Skip to content

Commit 415523f

Browse files
committed
Simplify reset command to drop all tables
Instead of preserving tracking tables and clearing their records, just drop everything and let migrations recreate the tables.
1 parent 465ff59 commit 415523f

File tree

1 file changed

+1
-73
lines changed

1 file changed

+1
-73
lines changed

src/Command/ResetCommand.php

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,6 @@ class ResetCommand extends Command
3636
*/
3737
use EventDispatcherTrait;
3838

39-
/**
40-
* Migration/seed tracking tables that should not be dropped.
41-
*
42-
* These tables are kept (structure preserved) but their contents
43-
* are cleared so migrations can run fresh.
44-
*
45-
* @var array<string>
46-
*/
47-
protected array $trackingTables = [
48-
'cake_migrations',
49-
'cake_seeds',
50-
'phinxlog',
51-
];
52-
5339
/**
5440
* The default name added to the application command list
5541
*
@@ -163,9 +149,6 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
163149
$io->out('');
164150
if (!$dryRun) {
165151
$this->dropTables($connection, $tablesToDrop, $io);
166-
/** @var string|null $plugin */
167-
$plugin = $args->getOption('plugin');
168-
$this->clearTrackingRecords($connection, $plugin, $io);
169152
} else {
170153
$io->info('DRY-RUN: Would drop ' . count($tablesToDrop) . ' table(s).');
171154
}
@@ -194,23 +177,8 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
194177
protected function getTablesToDrop(Connection $connection): array
195178
{
196179
$schema = $connection->getDriver()->schemaDialect();
197-
$tables = $schema->listTables();
198-
199-
// Filter out migration/seed tracking tables
200-
$tablesToDrop = [];
201-
foreach ($tables as $table) {
202-
// Skip migration/seed tracking tables (we clear their contents instead)
203-
if (in_array($table, $this->trackingTables, true)) {
204-
continue;
205-
}
206-
// Skip plugin phinxlog tables
207-
if (str_ends_with($table, '_phinxlog')) {
208-
continue;
209-
}
210-
$tablesToDrop[] = $table;
211-
}
212180

213-
return $tablesToDrop;
181+
return $schema->listTables();
214182
}
215183

216184
/**
@@ -317,46 +285,6 @@ protected function setForeignKeyChecks(Connection $connection, bool $enable): vo
317285
}
318286
}
319287

320-
/**
321-
* Clear migration and seed records from tracking tables.
322-
*
323-
* @param \Cake\Database\Connection $connection Database connection
324-
* @param string|null $plugin Plugin name
325-
* @param \Cake\Console\ConsoleIo $io Console IO
326-
* @return void
327-
*/
328-
protected function clearTrackingRecords(Connection $connection, ?string $plugin, ConsoleIo $io): void
329-
{
330-
$schema = $connection->getDriver()->schemaDialect();
331-
332-
// Clear unified migrations table if exists
333-
if ($schema->hasTable('cake_migrations')) {
334-
$query = $connection->deleteQuery()->delete('cake_migrations');
335-
if ($plugin !== null) {
336-
$query->where(['plugin' => $plugin]);
337-
}
338-
$query->execute();
339-
$io->verbose('Cleared migration records from cake_migrations');
340-
}
341-
342-
// Clear legacy phinxlog table if exists
343-
$legacyTable = $plugin ? strtolower($plugin) . '_phinxlog' : 'phinxlog';
344-
if ($schema->hasTable($legacyTable)) {
345-
$connection->deleteQuery()
346-
->delete($legacyTable)
347-
->execute();
348-
$io->verbose("Cleared migration records from {$legacyTable}");
349-
}
350-
351-
// Clear seed tracking table if exists
352-
if ($schema->hasTable('cake_seeds')) {
353-
$connection->deleteQuery()
354-
->delete('cake_seeds')
355-
->execute();
356-
$io->verbose('Cleared seed records from cake_seeds');
357-
}
358-
}
359-
360288
/**
361289
* Run migrations.
362290
*

0 commit comments

Comments
 (0)