1313)
1414from piccolo .apps .migrations .commands .forwards import ForwardsMigrationManager
1515from piccolo .table import Table , create_table_class
16+ from piccolo .apps .migrations .tables import Migration
1617from piccolo .utils .sync import run_sync
1718
1819
@@ -21,13 +22,14 @@ def tearDown(self):
2122 create_table_class ("MyTable" ).alter ().drop_table (
2223 if_exists = True
2324 ).run_sync ()
25+ Migration .alter ().drop_table (if_exists = True ).run_sync ()
2426
2527 def run_migrations (self , app_config : AppConfig ):
2628 manager = ForwardsMigrationManager (app_name = app_config .app_name )
2729 run_sync (manager .create_migration_table ())
2830 run_sync (manager .run_migrations (app_config = app_config ))
2931
30- def _test_migrations (self , table_1 : t .Type [ Table ], table_2 : t .Type [Table ]):
32+ def _test_migrations (self , table_classes : t .List [ t .Type [Table ] ]):
3133 temp_directory_path = tempfile .gettempdir ()
3234 migrations_folder_path = os .path .join (
3335 temp_directory_path , "piccolo_migrations"
@@ -41,37 +43,28 @@ def _test_migrations(self, table_1: t.Type[Table], table_2: t.Type[Table]):
4143 app_config = AppConfig (
4244 app_name = "test_app" ,
4345 migrations_folder_path = migrations_folder_path ,
44- table_classes = [table_1 ],
46+ table_classes = [],
4547 )
4648
47- meta = run_sync (
48- _create_new_migration (app_config = app_config , auto = True )
49- )
50- self .assertTrue (os .path .exists (meta .migration_path ))
51- self .run_migrations (app_config = app_config )
52-
53- #######################################################################
54-
55- # It's kind of absurd sleeping for 1 microsecond, but it guarantees
56- # the migration IDs will be unique, and just in case computers and / or
57- # Python get insanely fast in the future :)
58- time .sleep (1e-6 )
49+ for table_class in table_classes :
50+ app_config .table_classes = [table_class ]
51+ meta = run_sync (
52+ _create_new_migration (app_config = app_config , auto = True )
53+ )
54+ self .assertTrue (os .path .exists (meta .migration_path ))
55+ self .run_migrations (app_config = app_config )
5956
60- #######################################################################
61-
62- app_config .table_classes = [table_2 ]
63- meta = run_sync (
64- _create_new_migration (app_config = app_config , auto = True )
65- )
66- self .assertTrue (os .path .exists (meta .migration_path ))
67- self .run_migrations (app_config = app_config )
57+ # It's kind of absurd sleeping for 1 microsecond, but it guarantees
58+ # the migration IDs will be unique, and just in case computers
59+ # and / or Python get insanely fast in the future :)
60+ time .sleep (1e-6 )
6861
69- # TODO - check the migrations ran correctly
62+ # TODO - check the migrations ran correctly
7063
7164 def test_add_column (self ):
7265 table_1 = create_table_class ("MyTable" )
7366 table_2 = create_table_class (
7467 "MyTable" , class_members = {"name" : Varchar ()}
7568 )
7669
77- self ._test_migrations (table_1 = table_1 , table_2 = table_2 )
70+ self ._test_migrations (table_classes = [ table_1 , table_2 ] )
0 commit comments