@@ -16,10 +16,13 @@ fn schema_filter_migration_adding_external_table(api: TestApi) {
1616
1717 let filter = SchemaFilter {
1818 external_tables : vec ! [ "ExternalTable" . to_string( ) ] ,
19+ external_enums : vec ! [ ] ,
1920 } ;
2021 api. create_migration_with_filter ( "custom" , & schema, & dir, filter, "" )
2122 . send_sync ( )
2223 . assert_migration_directories_count ( 0 ) ;
24+ // Table is external => migrations should not touch it => created no migration => external table should not be there
25+ api. assert_schema ( ) . assert_has_no_table ( "ExternalTable" ) ;
2326}
2427
2528#[ test_connector]
@@ -32,20 +35,21 @@ fn schema_filter_migration_removing_external_table(mut api: TestApi) {
3235 }
3336 "# ,
3437 ) ;
35-
36- let dir = api. create_migrations_directory ( ) ;
37-
3838 // No filter applied here to actually create the external tables first
39- api. create_migration ( "create" , & schema_1, & dir ) . send_sync ( ) ;
39+ api. schema_push ( schema_1) . send ( ) ;
4040
41+ let dir = api. create_migrations_directory ( ) ;
4142 let schema_2 = api. datamodel_with_provider ( "" ) ;
4243
4344 let filter = SchemaFilter {
4445 external_tables : vec ! [ "ExternalTable" . to_string( ) ] ,
46+ external_enums : vec ! [ ] ,
4547 } ;
4648 api. create_migration_with_filter ( "remove" , & schema_2, & dir, filter, "" )
4749 . send_sync ( )
48- . assert_migration_directories_count ( 1 ) ;
50+ . assert_migration_directories_count ( 0 ) ;
51+ // Table is external => migrations should not touch it => created no migration => external table should still be there
52+ api. assert_schema ( ) . assert_has_table ( "ExternalTable" ) ;
4953}
5054
5155#[ test_connector]
@@ -58,20 +62,17 @@ fn schema_filter_migration_removing_external_table_with_contents(mut api: TestAp
5862 }
5963 "# ,
6064 ) ;
61-
62- let dir = api. create_migrations_directory ( ) ;
63-
6465 // No filter applied here to actually create the external tables first
65- api. create_migration ( "create" , & schema_1, & dir) . send_sync ( ) ;
66- api. apply_migrations ( & dir) . send_sync ( ) ;
67-
66+ api. schema_push ( schema_1) . send ( ) ;
6867 api. insert ( "Cat" ) . value ( "id" , 1 ) . value ( "name" , "Felix" ) . result_raw ( ) ;
6968 api. insert ( "Cat" ) . value ( "id" , 2 ) . value ( "name" , "Norbert" ) . result_raw ( ) ;
7069
70+ let dir = api. create_migrations_directory ( ) ;
7171 let schema_2 = api. datamodel_with_provider ( "" ) ;
7272
7373 let filter = SchemaFilter {
7474 external_tables : vec ! [ "Cat" . to_string( ) ] ,
75+ external_enums : vec ! [ ] ,
7576 } ;
7677 api. evaluate_data_loss_with_filter ( & dir, schema_2. clone ( ) , filter)
7778 . send ( )
@@ -87,12 +88,10 @@ fn schema_filter_migration_modifying_external_table(mut api: TestApi) {
8788 }
8889 "# ,
8990 ) ;
90-
91- let dir = api. create_migrations_directory ( ) ;
92-
9391 // No filter applied here to actually create the external tables first
94- api. create_migration ( "create" , & schema_1, & dir ) . send_sync ( ) ;
92+ api. schema_push ( schema_1) . send ( ) ;
9593
94+ let dir = api. create_migrations_directory ( ) ;
9695 let schema_2 = api. datamodel_with_provider (
9796 r#"
9897 model ExternalTable {
@@ -104,10 +103,69 @@ fn schema_filter_migration_modifying_external_table(mut api: TestApi) {
104103
105104 let filter = SchemaFilter {
106105 external_tables : vec ! [ "ExternalTable" . to_string( ) ] ,
106+ external_enums : vec ! [ ] ,
107107 } ;
108108 api. create_migration_with_filter ( "modify" , & schema_2, & dir, filter, "" )
109109 . send_sync ( )
110- . assert_migration_directories_count ( 1 ) ;
110+ . assert_migration_directories_count ( 0 ) ;
111+ // Table is external => migrations should not touch it => created no migration => external table should still be in the old state
112+ api. assert_schema ( ) . assert_table ( "ExternalTable" , |table_assertions| {
113+ table_assertions. assert_column_count ( 1 )
114+ } ) ;
115+ }
116+
117+ #[ test_connector( tags( Postgres ) , exclude( CockroachDb ) ) ]
118+ fn schema_filter_migration_adding_external_enum ( api : TestApi ) {
119+ let schema = api. datamodel_with_provider (
120+ r#"
121+ enum ExternalEnum {
122+ ONE
123+ TWO
124+ }
125+ "# ,
126+ ) ;
127+
128+ let dir = api. create_migrations_directory ( ) ;
129+
130+ let filter = SchemaFilter {
131+ external_tables : vec ! [ ] ,
132+ external_enums : vec ! [ "ExternalEnum" . to_string( ) ] ,
133+ } ;
134+ api. create_migration_with_filter ( "custom" , & schema, & dir, filter, "" )
135+ . send_sync ( )
136+ . assert_migration_directories_count ( 0 ) ;
137+ // Enum is external => migrations should not touch it => created no migration => external enum should not be there
138+ api. assert_schema ( ) . assert_has_no_enum ( "ExternalEnum" ) ;
139+ }
140+
141+ #[ test_connector( tags( Postgres ) , exclude( CockroachDb ) ) ]
142+ fn schema_filter_migration_removing_external_enum ( mut api : TestApi ) {
143+ let schema_1 = api. datamodel_with_provider (
144+ r#"
145+ enum ExternalEnum {
146+ ONE
147+ TWO
148+ }
149+ "# ,
150+ ) ;
151+ // Create the external enum in the database
152+ api. schema_push ( schema_1) . send ( ) ;
153+
154+ let dir = api. create_migrations_directory ( ) ;
155+
156+ let schema_2 = api. datamodel_with_provider ( "" ) ;
157+
158+ let filter = SchemaFilter {
159+ external_tables : vec ! [ ] ,
160+ external_enums : vec ! [ "ExternalEnum" . to_string( ) ] ,
161+ } ;
162+ api. create_migration_with_filter ( "remove" , & schema_2, & dir, filter, "" )
163+ . send_sync ( )
164+ . assert_migration_directories_count ( 0 ) ;
165+ // Enum is external => migrations should not touch it => created no migration => external enum should still be there
166+ api. assert_schema ( ) . assert_enum ( "ExternalEnum" , |enum_assertions| {
167+ enum_assertions. assert_values ( & [ "ONE" , "TWO" ] )
168+ } ) ;
111169}
112170
113171#[ test_connector( exclude( CockroachDb , Vitess ) ) ]
@@ -152,6 +210,7 @@ fn schema_filter_migration_adding_external_tables_incl_relations(api: TestApi) {
152210
153211 let filter = SchemaFilter {
154212 external_tables : vec ! [ "ExternalTableA" . to_string( ) , "ExternalTableB" . to_string( ) ] ,
213+ external_enums : vec ! [ ] ,
155214 } ;
156215 api. create_migration_with_filter ( "custom" , & schema, & dir, filter, "" )
157216 . send_sync ( )
@@ -283,6 +342,7 @@ fn schema_filter_migration_removing_external_tables_incl_relations(mut api: Test
283342
284343 let filter = SchemaFilter {
285344 external_tables : vec ! [ "ExternalTableA" . to_string( ) , "ExternalTableB" . to_string( ) ] ,
345+ external_enums : vec ! [ ] ,
286346 } ;
287347 api. create_migration_with_filter ( "remove" , & schema_2, & dir, filter, "" )
288348 . send_sync ( )
@@ -436,6 +496,7 @@ fn schema_filter_migration_modifying_external_tables_incl_relations(mut api: Tes
436496
437497 let filter = SchemaFilter {
438498 external_tables : vec ! [ "ExternalTableA" . to_string( ) , "ExternalTableB" . to_string( ) ] ,
499+ external_enums : vec ! [ ] ,
439500 } ;
440501 api. create_migration_with_filter ( "modify" , & schema_2, & dir, filter, "" )
441502 . send_sync ( )
@@ -542,6 +603,7 @@ fn schema_filter_leveraging_init_script(api: TestApi) {
542603
543604 let filter = SchemaFilter {
544605 external_tables : vec ! [ "external" . to_string( ) ] ,
606+ external_enums : vec ! [ ] ,
545607 } ;
546608 api. create_migration_with_filter ( "custom" , & schema, & dir, filter, init_script)
547609 . send_sync ( )
@@ -652,6 +714,7 @@ fn schema_filter_migration_multi_schema_requires_namespaced_table_names(api: Tes
652714
653715 let filter = SchemaFilter {
654716 external_tables : vec ! [ "two.ExternalTable" . to_string( ) ] ,
717+ external_enums : vec ! [ ] ,
655718 } ;
656719 api. create_migration_with_filter ( "custom" , & schema, & dir, filter, "" )
657720 . send_sync ( )
@@ -731,6 +794,7 @@ fn schema_filter_migration_multi_schema_without_namespaced_table_names(api: Test
731794
732795 let filter = SchemaFilter {
733796 external_tables : vec ! [ "ExternalTable" . to_string( ) ] ,
797+ external_enums : vec ! [ ] ,
734798 } ;
735799 let err = api
736800 . create_migration_with_filter ( "custom" , & schema, & dir, filter, "" )
@@ -763,6 +827,7 @@ fn schema_filter_migration_with_namespaced_table_names_and_no_explicit_schemas_l
763827
764828 let filter = SchemaFilter {
765829 external_tables : vec ! [ "public.ExternalTable" . to_string( ) ] ,
830+ external_enums : vec ! [ ] ,
766831 } ;
767832 let err = api
768833 . create_migration_with_filter ( "custom" , & schema, & dir, filter, "" )
@@ -785,6 +850,7 @@ fn schema_filter_migration_dev_diagnostic_drift_detection(api: TestApi) {
785850
786851 let filter = SchemaFilter {
787852 external_tables : vec ! [ "external_table" . to_string( ) ] ,
853+ external_enums : vec ! [ ] ,
788854 } ;
789855 // Table exists in DB and is missing in the schema but is marked as external => not a drift.
790856 api. dev_diagnostic_with_filter ( & dir, filter)
0 commit comments