Skip to content

Commit

Permalink
Convert schema-qualified CREATE TABLE statements (#557)
Browse files Browse the repository at this point in the history
Ensure that schema qualified `CREATE TABLE` statements are correctly
converted to a `migrations.OpCreateTable` operation.
  • Loading branch information
andrew-farries authored Dec 19, 2024
1 parent c64edc6 commit e1ba0af
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/sql2pgroll/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func convertCreateStmt(stmt *pgq.CreateStmt) (migrations.Operations, error) {

return migrations.Operations{
&migrations.OpCreateTable{
Name: stmt.Relation.GetRelname(),
Name: getQualifiedRelationName(stmt.GetRelation()),
Columns: columns,
},
}, nil
Expand Down
4 changes: 4 additions & 0 deletions pkg/sql2pgroll/create_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func TestConvertCreateTableStatements(t *testing.T) {
sql: "CREATE TABLE foo(a int)",
expectedOp: expect.CreateTableOp1,
},
{
sql: "CREATE TABLE schema.foo(a int)",
expectedOp: expect.CreateTableOp17,
},
{
sql: "CREATE TABLE foo(a int NULL)",
expectedOp: expect.CreateTableOp1,
Expand Down
11 changes: 11 additions & 0 deletions pkg/sql2pgroll/expect/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,14 @@ var CreateTableOp16 = &migrations.OpCreateTable{
},
},
}

var CreateTableOp17 = &migrations.OpCreateTable{
Name: "schema.foo",
Columns: []migrations.Column{
{
Name: "a",
Type: "int",
Nullable: true,
},
},
}

0 comments on commit e1ba0af

Please sign in to comment.