@@ -51,6 +51,27 @@ def test_migrate_data_migration(migration_state_file, runner, log):
5151 assert "Migrations completed successfully." in result .output
5252
5353
54+ @freeze_time ("2025-04-06 13:10:30" )
55+ @pytest .mark .usefixtures ("data_migration_file" , "schema_migration_file" )
56+ def test_migrate_data_single_migration (migration_state_file , runner , log ):
57+ result = runner .invoke (app , ["migrate" , "--data" , "fake_data_file_name" ])
58+
59+ assert result .exit_code == 0 , result .output
60+ migration_state_data = json .loads (migration_state_file .read_text (encoding = "utf-8" ))
61+ assert migration_state_data == {
62+ "fake_data_file_name" : {
63+ "migration_id" : "fake_data_file_name" ,
64+ "order_id" : 20250406020202 ,
65+ "type" : "data" ,
66+ "started_at" : "2025-04-06T13:10:30+00:00" ,
67+ "applied_at" : "2025-04-06T13:10:30+00:00" ,
68+ }
69+ }
70+ assert "Running data migrations..." in result .output
71+ assert "Running migration: fake_data_file_name" in log .text
72+ assert "Migrations completed successfully." in result .output
73+
74+
5475@freeze_time ("2025-04-06 13:00:00" )
5576@pytest .mark .usefixtures ("applied_migration" )
5677def test_migrate_skip_migration_already_applied (migration_state_file , runner , log ):
@@ -90,6 +111,46 @@ def test_migrate_data_run_script_fail(migration_state_file, runner, log):
90111 assert "Migration fake_error_file_name failed: Fake Error" in result .output
91112
92113
114+ @pytest .mark .usefixtures ("data_migration_file" )
115+ def test_migrate_data_single_migration_not_found (runner ):
116+ result = runner .invoke (app , ["migrate" , "--data" , "not_existing_migration" ])
117+
118+ assert result .exit_code == 1 , result .output
119+ assert "Error running data command: Migration not_existing_migration not found" in result .output
120+
121+
122+ @pytest .mark .usefixtures ("data_migration_file" , "schema_migration_file" )
123+ def test_migrate_data_single_migration_wrong_type (runner ):
124+ result = runner .invoke (app , ["migrate" , "--data" , "fake_schema_file_name" ])
125+
126+ assert result .exit_code == 1 , result .output
127+ assert (
128+ "Error running data command: Migration fake_schema_file_name is not a data migration"
129+ in result .output
130+ )
131+
132+
133+ @freeze_time ("2025-04-06 13:10:30" )
134+ @pytest .mark .usefixtures ("data_migration_file" , "schema_migration_file" )
135+ def test_migrate_schema_single_migration (migration_state_file , runner , log ):
136+ result = runner .invoke (app , ["migrate" , "--schema" , "fake_schema_file_name" ])
137+
138+ assert result .exit_code == 0 , result .output
139+ migration_state_data = json .loads (migration_state_file .read_text (encoding = "utf-8" ))
140+ assert migration_state_data == {
141+ "fake_schema_file_name" : {
142+ "migration_id" : "fake_schema_file_name" ,
143+ "order_id" : 20260101010101 ,
144+ "type" : "schema" ,
145+ "started_at" : "2025-04-06T13:10:30+00:00" ,
146+ "applied_at" : "2025-04-06T13:10:30+00:00" ,
147+ }
148+ }
149+ assert "Running schema migrations..." in result .output
150+ assert "Running migration: fake_schema_file_name" in log .text
151+ assert "schema migrations applied successfully." in result .output
152+
153+
93154@freeze_time ("2025-04-06 10:11:24" )
94155@pytest .mark .usefixtures ("data_migration_file" )
95156def test_migrate_manual (migration_state_file , runner ):
0 commit comments