Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sources/common/dbdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func ProcessDbDump(conv *internal.Conv, r *internal.Reader, dbDump DbDump, ddlVe
ExpressionVerificationAccessor: exprVerifier,
DdlV: ddlVerifier,
}
schemaToSpanner.SchemaToSpannerDDL(conv, dbDump.GetToDdl())
schemaToSpanner.SchemaToSpannerDDL(conv, dbDump.GetToDdl(), internal.AdditionalSchemaAttributes{})
conv.AddPrimaryKeys()
}
return nil
Expand Down
6 changes: 1 addition & 5 deletions sources/common/infoschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,11 @@ func (ps *ProcessSchemaImpl) ProcessSchema(conv *internal.Conv, infoSchema InfoS
}
uo.initPrimaryKeyOrder(conv)
uo.initIndexOrder(conv)
s.SchemaToSpannerDDL(conv, infoSchema.GetToDdl())
s.SchemaToSpannerDDL(conv, infoSchema.GetToDdl(), attributes)
if tableCount != len(conv.SpSchema) {
fmt.Printf("Failed to load all the source tables, source table count: %v, processed tables:%v. Please retry connecting to the source database to load tables.\n", tableCount, len(conv.SpSchema))
return fmt.Errorf("failed to load all the source tables, source table count: %v, processed tables:%v. Please retry connecting to the source database to load tables.", tableCount, len(conv.SpSchema))
}
conv.AddPrimaryKeys()
if attributes.IsSharded {
conv.AddShardIdColumn()
}
fmt.Println("loaded schema")
return nil
}
Expand Down
9 changes: 7 additions & 2 deletions sources/common/toddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type ToDdl interface {
}

type SchemaToSpannerInterface interface {
SchemaToSpannerDDL(conv *internal.Conv, toddl ToDdl) error
SchemaToSpannerDDL(conv *internal.Conv, toddl ToDdl, attributes internal.AdditionalSchemaAttributes) error
SchemaToSpannerDDLHelper(conv *internal.Conv, toddl ToDdl, srcTable schema.Table, isRestore bool) error
SchemaToSpannerSequenceHelper(conv *internal.Conv, srcSequence ddl.Sequence) error
}
Expand All @@ -75,7 +75,7 @@ var ErrorTypeMapping = map[string]internal.SchemaIssue{
// SchemaToSpannerDDL performs schema conversion from the source DB schema to
// Spanner. It uses the source schema in conv.SrcSchema, and writes
// the Spanner schema to conv.SpSchema.
func (ss *SchemaToSpannerImpl) SchemaToSpannerDDL(conv *internal.Conv, toddl ToDdl) error {
func (ss *SchemaToSpannerImpl) SchemaToSpannerDDL(conv *internal.Conv, toddl ToDdl, attributes internal.AdditionalSchemaAttributes) error {
srcSequences := conv.SrcSequences
for _, srcSequence := range srcSequences {
ss.SchemaToSpannerSequenceHelper(conv, srcSequence)
Expand All @@ -86,6 +86,11 @@ func (ss *SchemaToSpannerImpl) SchemaToSpannerDDL(conv *internal.Conv, toddl ToD
ss.SchemaToSpannerDDLHelper(conv, toddl, srcTable, false)
}

conv.AddPrimaryKeys()
if attributes.IsSharded {
conv.AddShardIdColumn()
}

if (conv.Source == constants.MYSQL || conv.Source == constants.MYSQLDUMP) && conv.SpProjectId != "" && conv.SpInstanceId != "" {
// Process and verify Check constraints for MySQL and MySQLDump flow only
err := ss.VerifyExpressions(conv)
Expand Down
4 changes: 2 additions & 2 deletions sources/dynamodb/toddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestToSpannerType(t *testing.T) {
ExpressionVerificationAccessor: mockAccessor,
DdlV: &expressions_api.MockDDLVerifier{},
}
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}))
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}, internal.AdditionalSchemaAttributes{}))
actual := conv.SpSchema[name]
dropComments(&actual) // Don't test comment.
expected := ddl.CreateTable{
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestToSpannerPostgreSQLDialectType(t *testing.T) {
ExpressionVerificationAccessor: mockAccessor,
DdlV: &expressions_api.MockDDLVerifier{},
}
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}))
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}, internal.AdditionalSchemaAttributes{}))
actual := conv.SpSchema["t1"]
dropComments(&actual) // Don't test comment.
expected := ddl.CreateTable{
Expand Down
4 changes: 2 additions & 2 deletions sources/mysql/toddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func TestToSpannerType(t *testing.T) {
ExpressionVerificationAccessor: mockAccessor,
DdlV: &expressions_api.MockDDLVerifier{},
}
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}))
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}, internal.AdditionalSchemaAttributes{}))
actual := conv.SpSchema[tableId]
dropComments(&actual) // Don't test comment.
expected := ddl.CreateTable{
Expand Down Expand Up @@ -296,7 +296,7 @@ func TestToSpannerPostgreSQLDialectType(t *testing.T) {
ExpressionVerificationAccessor: mockAccessor,
DdlV: &expressions_api.MockDDLVerifier{},
}
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}))
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}, internal.AdditionalSchemaAttributes{}))
actual := conv.SpSchema[tableId]
dropComments(&actual) // Don't test comment.
expected := ddl.CreateTable{
Expand Down
4 changes: 2 additions & 2 deletions sources/oracle/toddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func TestToSpannerType(t *testing.T) {
ExpressionVerificationAccessor: mockAccessor,
DdlV: &expressions_api.MockDDLVerifier{},
}
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}))
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}, internal.AdditionalSchemaAttributes{}))
actual := conv.SpSchema[tableId]
dropComments(&actual) // Don't test comment.
expected := ddl.CreateTable{
Expand Down Expand Up @@ -285,7 +285,7 @@ func TestToSpannerPostgreSQLDialectType(t *testing.T) {
ExpressionVerificationAccessor: mockAccessor,
DdlV: &expressions_api.MockDDLVerifier{},
}
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}))
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}, internal.AdditionalSchemaAttributes{}))
actual := conv.SpSchema[tableId]
dropComments(&actual) // Don't test comment.
expected := ddl.CreateTable{
Expand Down
4 changes: 2 additions & 2 deletions sources/postgres/toddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func TestToSpannerType(t *testing.T) {
DdlV: &expressions_api.MockDDLVerifier{},
ExpressionVerificationAccessor: mockAccessor,
}
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}))
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}, internal.AdditionalSchemaAttributes{}))
actual := conv.SpSchema[tableId]
dropComments(&actual) // Don't test comment.
expected := ddl.CreateTable{
Expand Down Expand Up @@ -282,7 +282,7 @@ func TestToExperimentalSpannerType(t *testing.T) {
ExpressionVerificationAccessor: mockAccessor,
DdlV: &expressions_api.MockDDLVerifier{},
}
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}))
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}, internal.AdditionalSchemaAttributes{}))
actual := conv.SpSchema[tableId]
dropComments(&actual) // Don't test comment.
expected := ddl.CreateTable{
Expand Down
4 changes: 2 additions & 2 deletions sources/sqlserver/toddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestToSpannerType(t *testing.T) {
ExpressionVerificationAccessor: mockAccessor,
DdlV: &expressions_api.MockDDLVerifier{},
}
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}))
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}, internal.AdditionalSchemaAttributes{}))
actual := conv.SpSchema[tableId]
dropComments(&actual) // Don't test comment.
expected := ddl.CreateTable{
Expand Down Expand Up @@ -302,7 +302,7 @@ func TestToSpannerPostgreSQLDialectType(t *testing.T) {
ExpressionVerificationAccessor: mockAccessor,
DdlV: &expressions_api.MockDDLVerifier{},
}
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}))
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}, internal.AdditionalSchemaAttributes{}))
actual := conv.SpSchema[tableId]
dropComments(&actual) // Don't test comment.
expected := ddl.CreateTable{
Expand Down
2 changes: 1 addition & 1 deletion testing/postgres/golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestGoldens(t *testing.T) {
t.Fatalf("error when processing dump %s: %s", tc.Input, err)
}

err = schemaToSpanner.SchemaToSpannerDDL(conv, postgres.ToDdlImpl{})
err = schemaToSpanner.SchemaToSpannerDDL(conv, postgres.ToDdlImpl{}, internal.AdditionalSchemaAttributes{})
if err != nil {
t.Fatalf("error when converting schema to spanner ddl %s: %s", tc.Input, err)
}
Expand Down
Loading