Skip to content

Commit 9a37ea8

Browse files
Multi-operation migration support for create_table operations (#596)
Ensure that `create_table` operations can be used as part of multi-operation migrations: Add a validation testcase: * create a table `foo` in one migration, rename it to `bar` and attempt to create a table `bar` in a second migration Other tests and changes to the `create_table` operation were merged in earlier parts of #239, so nothing else needs to be done here. Part of #239
1 parent cb0c1e2 commit 9a37ea8

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

pkg/migrations/op_create_table_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,3 +788,54 @@ func TestCreateTableColumnDefaultTransformation(t *testing.T) {
788788
},
789789
}, roll.WithSQLTransformer(sqlTransformer))
790790
}
791+
792+
func TestCreateTableValidationInMultiOperationMigrations(t *testing.T) {
793+
t.Parallel()
794+
795+
ExecuteTests(t, TestCases{
796+
{
797+
name: "create table with a name matching a name used in a previous operation",
798+
migrations: []migrations.Migration{
799+
{
800+
Name: "01_create_table",
801+
Operations: migrations.Operations{
802+
&migrations.OpCreateTable{
803+
Name: "items",
804+
Columns: []migrations.Column{
805+
{
806+
Name: "id",
807+
Type: "serial",
808+
Pk: true,
809+
},
810+
{
811+
Name: "name",
812+
Type: "varchar(255)",
813+
},
814+
},
815+
},
816+
},
817+
},
818+
{
819+
Name: "02_multi_operation",
820+
Operations: migrations.Operations{
821+
&migrations.OpRenameTable{
822+
From: "items",
823+
To: "products",
824+
},
825+
&migrations.OpCreateTable{
826+
Name: "products",
827+
Columns: []migrations.Column{
828+
{
829+
Name: "id",
830+
Type: "serial",
831+
Pk: true,
832+
},
833+
},
834+
},
835+
},
836+
},
837+
},
838+
wantStartErr: migrations.TableAlreadyExistsError{Name: "products"},
839+
},
840+
})
841+
}

0 commit comments

Comments
 (0)