Skip to content

Commit 847bd05

Browse files
Add SQLite migration rollback coverage
1 parent 97cfbff commit 847bd05

1 file changed

Lines changed: 104 additions & 0 deletions

File tree

tests/Unit/migrations/MigrationsTest.php

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,46 @@ public function testDownMethodsDropTables(): void
128128
$this->assertFalse(Schema::hasTable('workflow_run_lineage_entries'));
129129
}
130130

131+
/**
132+
* @dataProvider sqliteRollbackCommandProvider
133+
*/
134+
public function testSqlitePackageMigrationsSupportRollbackCommands(string $command): void
135+
{
136+
$databasePath = tempnam(sys_get_temp_dir(), 'workflow-sqlite-migrations-');
137+
138+
$this->assertIsString($databasePath);
139+
140+
$connection = 'workflow_test_sqlite';
141+
config()->set("database.connections.{$connection}", [
142+
'driver' => 'sqlite',
143+
'database' => $databasePath,
144+
'prefix' => '',
145+
'foreign_key_constraints' => true,
146+
]);
147+
148+
try {
149+
$this->artisan('migrate:fresh', [
150+
'--database' => $connection,
151+
'--path' => dirname(__DIR__, 3) . '/src/migrations',
152+
'--realpath' => true,
153+
])->assertExitCode(0);
154+
155+
$this->assertSqliteWorkflowTablesExist($connection);
156+
157+
$this->artisan($command, [
158+
'--database' => $connection,
159+
'--path' => dirname(__DIR__, 3) . '/src/migrations',
160+
'--realpath' => true,
161+
])->assertExitCode(0);
162+
163+
$this->assertSqliteWorkflowTablesMissing($connection);
164+
} finally {
165+
if (is_file($databasePath)) {
166+
@unlink($databasePath);
167+
}
168+
}
169+
}
170+
131171
public function testTimerProjectionRowsDefaultToCurrentSchemaVersion(): void
132172
{
133173
/** @var WorkflowRunTimerEntry $entry */
@@ -182,4 +222,68 @@ private function stringColumnLength(string $table, string $column): int
182222

183223
$this->fail("Unable to determine {$table}.{$column} length for {$driver}.");
184224
}
225+
226+
/**
227+
* @return list<array{string}>
228+
*/
229+
public static function sqliteRollbackCommandProvider(): array
230+
{
231+
return [
232+
['migrate:rollback'],
233+
['migrate:reset'],
234+
];
235+
}
236+
237+
private function assertSqliteWorkflowTablesExist(string $connection): void
238+
{
239+
foreach (self::sqliteWorkflowTables() as $table) {
240+
$this->assertTrue(Schema::connection($connection)->hasTable($table), "Expected SQLite table [{$table}] to exist.");
241+
}
242+
}
243+
244+
private function assertSqliteWorkflowTablesMissing(string $connection): void
245+
{
246+
foreach (self::sqliteWorkflowTables() as $table) {
247+
$this->assertFalse(Schema::connection($connection)->hasTable($table), "Expected SQLite table [{$table}] to be dropped.");
248+
}
249+
}
250+
251+
/**
252+
* @return list<string>
253+
*/
254+
private static function sqliteWorkflowTables(): array
255+
{
256+
return [
257+
'workflows',
258+
'workflow_logs',
259+
'workflow_signals',
260+
'workflow_timers',
261+
'workflow_exceptions',
262+
'workflow_relationships',
263+
'workflow_instances',
264+
'workflow_runs',
265+
'workflow_run_timers',
266+
'workflow_tasks',
267+
'activity_executions',
268+
'workflow_failures',
269+
'workflow_run_summaries',
270+
'workflow_history_events',
271+
'workflow_commands',
272+
'workflow_links',
273+
'activity_attempts',
274+
'workflow_worker_compatibility_heartbeats',
275+
'workflow_updates',
276+
'workflow_signal_records',
277+
'workflow_run_waits',
278+
'workflow_run_timeline_entries',
279+
'workflow_run_lineage_entries',
280+
'workflow_run_timer_entries',
281+
'workflow_schedules',
282+
'workflow_messages',
283+
'workflow_memos',
284+
'workflow_search_attributes',
285+
'workflow_child_calls',
286+
'workflow_schedule_history_events',
287+
];
288+
}
185289
}

0 commit comments

Comments
 (0)