From f32fa4eac6a4f33927d1c856546ff2a77739f30c Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Wed, 18 Jun 2025 09:48:13 -0600 Subject: [PATCH 1/8] Rework sqlite fk pragma handling Signed-off-by: Matthew Peveler --- src/Phinx/Db/Adapter/AdapterInterface.php | 16 +++ src/Phinx/Db/Adapter/PdoAdapter.php | 16 +++ src/Phinx/Db/Adapter/SQLiteAdapter.php | 124 ++++++++++--------- src/Phinx/Db/Plan/Plan.php | 6 + tests/Phinx/Db/Adapter/SQLiteAdapterTest.php | 1 + 5 files changed, 103 insertions(+), 60 deletions(-) diff --git a/src/Phinx/Db/Adapter/AdapterInterface.php b/src/Phinx/Db/Adapter/AdapterInterface.php index ecce738af..f93a82162 100644 --- a/src/Phinx/Db/Adapter/AdapterInterface.php +++ b/src/Phinx/Db/Adapter/AdapterInterface.php @@ -275,6 +275,13 @@ public function rollbackTransaction(): void; */ public function execute(string $sql, array $params = []): int; + /** + * Function to be called before executing any migration actions. + * + * @return array + */ + public function preExecuteActions(): array; + /** * Executes a list of migration actions for the given table * @@ -284,6 +291,15 @@ public function execute(string $sql, array $params = []): int; */ public function executeActions(Table $table, array $actions): void; + /** + * Function to be called after executing any migration actions. + * + * @param array $tableNames List of table names that were affected by the actions + * @param array $preOptions Options that were set before executing the actions + * @return void + */ + public function postExecuteActions(array $tableNames, array $preOptions): void; + /** * Returns a new Query object * diff --git a/src/Phinx/Db/Adapter/PdoAdapter.php b/src/Phinx/Db/Adapter/PdoAdapter.php index 46e6b0870..980e245f7 100644 --- a/src/Phinx/Db/Adapter/PdoAdapter.php +++ b/src/Phinx/Db/Adapter/PdoAdapter.php @@ -1001,6 +1001,14 @@ public function changeComment(Table $table, $newComment): void */ abstract protected function getChangeCommentInstructions(Table $table, ?string $newComment): AlterInstructions; + /** + * {@inheritDoc} + */ + public function preExecuteActions(): array + { + return []; + } + /** * {@inheritDoc} * @@ -1126,4 +1134,12 @@ public function executeActions(Table $table, array $actions): void $this->executeAlterSteps($table->getName(), $instructions); } + + /** + * {@inheritDoc} + */ + public function postExecuteActions(array $tableNames, array $preOptions): void + { + + } } diff --git a/src/Phinx/Db/Adapter/SQLiteAdapter.php b/src/Phinx/Db/Adapter/SQLiteAdapter.php index 1c7c76561..75463fccb 100644 --- a/src/Phinx/Db/Adapter/SQLiteAdapter.php +++ b/src/Phinx/Db/Adapter/SQLiteAdapter.php @@ -1034,57 +1034,52 @@ protected function recreateIndicesAndTriggers(AlterInstructions $instructions): * the given table, and of those tables whose constraints are * targeting it. * - * @param \Phinx\Db\Util\AlterInstructions $instructions The instructions to process - * @param string $tableName The name of the table for which to check constraints. + * @param string|array $tableName The name of the table for which to check constraints. * @return \Phinx\Db\Util\AlterInstructions */ - protected function validateForeignKeys(AlterInstructions $instructions, string $tableName): AlterInstructions + protected function validateForeignKeys(string|array $tableNames): void { - $instructions->addPostStep(function ($state) use ($tableName) { - $tablesToCheck = [ - $tableName, - ]; - - $otherTables = $this - ->query( - "SELECT name FROM sqlite_master WHERE type = 'table' AND name != ?", - [$tableName], - ) - ->fetchAll(); - - foreach ($otherTables as $otherTable) { - $foreignKeyList = $this->getTableInfo($otherTable['name'], 'foreign_key_list'); - foreach ($foreignKeyList as $foreignKey) { - if (strcasecmp($foreignKey['table'], $tableName) === 0) { - $tablesToCheck[] = $otherTable['name']; - break; - } - } - } - - $tablesToCheck = array_unique(array_map('strtolower', $tablesToCheck)); + if (!is_array($tableNames)) { + $tableNames = [$tableNames]; + } - foreach ($tablesToCheck as $tableToCheck) { - $schema = $this->getSchemaName($tableToCheck, true)['schema']; + $tablesToCheck = $tableNames; - $stmt = $this->query( - sprintf('PRAGMA %sforeign_key_check(%s)', $schema, $this->quoteTableName($tableToCheck)), - ); - $row = $stmt->fetch(); - $stmt->closeCursor(); + $otherTables = $this + ->query( + "SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT IN (" . implode(',',array_fill(0, count($tableNames), '?')) . ')', + $tableNames + ) + ->fetchAll(); - if (is_array($row)) { - throw new RuntimeException(sprintf( - 'Integrity constraint violation: FOREIGN KEY constraint on `%s` failed.', - $tableToCheck, - )); + foreach ($otherTables as $otherTable) { + $foreignKeyList = $this->getTableInfo($otherTable['name'], 'foreign_key_list'); + foreach ($foreignKeyList as $foreignKey) { + if (in_array(strtolower($foreignKey['table']), $tableNames)) { + $tablesToCheck[] = $otherTable['name']; + break; } } + } - return $state; - }); + $tablesToCheck = array_unique(array_map('strtolower', $tablesToCheck)); - return $instructions; + foreach ($tablesToCheck as $tableToCheck) { + $schema = $this->getSchemaName($tableToCheck, true)['schema']; + + $stmt = $this->query( + sprintf('PRAGMA %sforeign_key_check(%s)', $schema, $this->quoteTableName($tableToCheck)), + ); + $row = $stmt->fetch(); + $stmt->closeCursor(); + + if (is_array($row)) { + throw new RuntimeException(sprintf( + 'Integrity constraint violation: FOREIGN KEY constraint on `%s` failed.', + $tableToCheck, + )); + } + } } /** @@ -1239,7 +1234,6 @@ protected function endAlterByCopyTable( string $tableName, ?string $renamedOrRemovedColumnName = null, ?string $newColumnName = null, - bool $validateForeignKeys = true, ): AlterInstructions { $instructions = $this->bufferIndicesAndTriggers($instructions, $tableName); @@ -1251,26 +1245,9 @@ protected function endAlterByCopyTable( } } - $foreignKeysEnabled = (bool)$this->fetchRow('PRAGMA foreign_keys')['foreign_keys']; - - if ($foreignKeysEnabled) { - $instructions->addPostStep('PRAGMA foreign_keys = OFF'); - } - $instructions = $this->copyAndDropTmpTable($instructions, $tableName); $instructions = $this->recreateIndicesAndTriggers($instructions); - if ($foreignKeysEnabled) { - $instructions->addPostStep('PRAGMA foreign_keys = ON'); - } - - if ( - $foreignKeysEnabled && - $validateForeignKeys - ) { - $instructions = $this->validateForeignKeys($instructions, $tableName); - } - return $instructions; } @@ -1661,7 +1638,7 @@ protected function getDropPrimaryKeyInstructions(Table $table, string $column): return $newState + $state; }); - return $this->endAlterByCopyTable($instructions, $tableName, null, null, false); + return $this->endAlterByCopyTable($instructions, $tableName, null, null); } /** @@ -2013,4 +1990,31 @@ public function getDecoratedConnection(): Connection return $this->decoratedConnection = $this->buildConnection(SqliteDriver::class, $options); } + + /** + * {@inheritDoc} + */ + public function preExecuteActions(): array + { + $foreignKeysEnabled = (bool)$this->fetchRow('PRAGMA foreign_keys')['foreign_keys']; + + if ($foreignKeysEnabled) { + $this->execute('PRAGMA foreign_keys = OFF'); + } + + return [ + 'foreignKeysEnabled' => $foreignKeysEnabled, + ]; + } + + /** + * {@inheritDoc} + */ + public function postExecuteActions(array $tableNames, array $preOptions): void + { + if ($preOptions['foreignKeysEnabled']) { + $this->execute('PRAGMA foreign_keys = ON'); + $this->validateForeignKeys($tableNames); + } + } } diff --git a/src/Phinx/Db/Plan/Plan.php b/src/Phinx/Db/Plan/Plan.php index d95221428..2820fb754 100644 --- a/src/Phinx/Db/Plan/Plan.php +++ b/src/Phinx/Db/Plan/Plan.php @@ -143,15 +143,21 @@ protected function inverseUpdatesSequence(): array */ public function execute(AdapterInterface $executor): void { + $preOptions = $executor->preExecuteActions(); + foreach ($this->tableCreates as $newTable) { $executor->createTable($newTable->getTable(), $newTable->getColumns(), $newTable->getIndexes()); } + $tables = []; foreach ($this->updatesSequence() as $updates) { foreach ($updates as $update) { + $tables[] = $update->getTable()->getName(); $executor->executeActions($update->getTable(), $update->getActions()); } } + + $executor->postExecuteActions(array_unique($tables), $preOptions); } /** diff --git a/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php b/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php index 622583a8e..1dc2e4743 100644 --- a/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php +++ b/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php @@ -2387,6 +2387,7 @@ public function testAlterTableDoesViolateForeignKeyConstraintOnTargetTableChange */ public function testAlterTableDoesViolateForeignKeyConstraintOnSourceTableChange() { + /** @var \Phinx\Db\Adapter\AdapterInterface&\PHPUnit\Framework\MockObject\MockObject */ $adapter = $this ->getMockBuilder(SQLiteAdapter::class) ->setConstructorArgs([SQLITE_DB_CONFIG, new ArrayInput([]), new NullOutput()]) From 2422dd2baf1aba0999af961d21f2bfa92c5884c4 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Wed, 18 Jun 2025 12:58:05 -0600 Subject: [PATCH 2/8] add pre/post execute to adapterwrapper Signed-off-by: Matthew Peveler --- src/Phinx/Db/Adapter/AdapterWrapper.php | 16 ++++++++++++++++ src/Phinx/Db/Plan/Plan.php | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/src/Phinx/Db/Adapter/AdapterWrapper.php b/src/Phinx/Db/Adapter/AdapterWrapper.php index 09ee619dc..cf59e43e2 100644 --- a/src/Phinx/Db/Adapter/AdapterWrapper.php +++ b/src/Phinx/Db/Adapter/AdapterWrapper.php @@ -474,6 +474,14 @@ public function getConnection(): PDO return $this->getAdapter()->getConnection(); } + /** + * {@inheritDoc} + */ + public function preExecuteActions(): array + { + return $this->getAdapter()->preExecuteActions(); + } + /** * @inheritDoc */ @@ -482,6 +490,14 @@ public function executeActions(Table $table, array $actions): void $this->getAdapter()->executeActions($table, $actions); } + /** + * {@inheritDoc} + */ + public function postExecuteActions(array $tableNames, array $preOptions): void + { + $this->getAdapter()->postExecuteActions($tableNames, $preOptions); + } + /** * @inheritDoc */ diff --git a/src/Phinx/Db/Plan/Plan.php b/src/Phinx/Db/Plan/Plan.php index 2820fb754..cade7767c 100644 --- a/src/Phinx/Db/Plan/Plan.php +++ b/src/Phinx/Db/Plan/Plan.php @@ -168,12 +168,18 @@ public function execute(AdapterInterface $executor): void */ public function executeInverse(AdapterInterface $executor): void { + $preOptions = $executor->preExecuteActions(); + $tables = []; + foreach ($this->inverseUpdatesSequence() as $updates) { foreach ($updates as $update) { + $tables[] = $update->getTable()->getName(); $executor->executeActions($update->getTable(), $update->getActions()); } } + $executor->postExecuteActions(array_unique($tables), $preOptions); + foreach ($this->tableCreates as $newTable) { $executor->createTable($newTable->getTable(), $newTable->getColumns(), $newTable->getIndexes()); } From 8fd78bd9279033442475fe90197aa98b12dc9be3 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Wed, 18 Jun 2025 14:28:43 -0600 Subject: [PATCH 3/8] fix phpdoc srings Signed-off-by: Matthew Peveler --- src/Phinx/Db/Adapter/SQLiteAdapter.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Phinx/Db/Adapter/SQLiteAdapter.php b/src/Phinx/Db/Adapter/SQLiteAdapter.php index 75463fccb..1f9883ec1 100644 --- a/src/Phinx/Db/Adapter/SQLiteAdapter.php +++ b/src/Phinx/Db/Adapter/SQLiteAdapter.php @@ -1035,7 +1035,7 @@ protected function recreateIndicesAndTriggers(AlterInstructions $instructions): * targeting it. * * @param string|array $tableName The name of the table for which to check constraints. - * @return \Phinx\Db\Util\AlterInstructions + * @return void */ protected function validateForeignKeys(string|array $tableNames): void { @@ -1225,8 +1225,6 @@ protected function beginAlterByCopyTable(string $tableName): AlterInstructions * @param ?string $renamedOrRemovedColumnName The name of the renamed or removed column when part of a column * rename/drop operation. * @param ?string $newColumnName The new column name when part of a column rename operation. - * @param bool $validateForeignKeys Whether to validate foreign keys after the copy and drop operations. Note that - * enabling this option only has an effect when the `foreign_keys` PRAGMA is set to `ON`! * @return \Phinx\Db\Util\AlterInstructions */ protected function endAlterByCopyTable( From dbac510a1540ad6a5b8e21dcbf9b0b25e9a49932 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Wed, 18 Jun 2025 16:08:13 -0600 Subject: [PATCH 4/8] fix failing test Signed-off-by: Matthew Peveler --- src/Phinx/Db/Adapter/AdapterInterface.php | 3 ++- src/Phinx/Db/Adapter/PdoAdapter.php | 2 +- src/Phinx/Db/Adapter/SQLiteAdapter.php | 17 +++++++++++++++-- src/Phinx/Db/Plan/Plan.php | 11 ++++++----- tests/Phinx/Db/Adapter/SQLiteAdapterTest.php | 13 +++++++++---- 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/Phinx/Db/Adapter/AdapterInterface.php b/src/Phinx/Db/Adapter/AdapterInterface.php index f93a82162..1060aa455 100644 --- a/src/Phinx/Db/Adapter/AdapterInterface.php +++ b/src/Phinx/Db/Adapter/AdapterInterface.php @@ -278,9 +278,10 @@ public function execute(string $sql, array $params = []): int; /** * Function to be called before executing any migration actions. * + * @param \Phinx\Db\Plan\AlterTable[][] $updateSequences List of update sequences to be executed * @return array */ - public function preExecuteActions(): array; + public function preExecuteActions(array $updateSequences): array; /** * Executes a list of migration actions for the given table diff --git a/src/Phinx/Db/Adapter/PdoAdapter.php b/src/Phinx/Db/Adapter/PdoAdapter.php index 980e245f7..51ba5c08d 100644 --- a/src/Phinx/Db/Adapter/PdoAdapter.php +++ b/src/Phinx/Db/Adapter/PdoAdapter.php @@ -1004,7 +1004,7 @@ abstract protected function getChangeCommentInstructions(Table $table, ?string $ /** * {@inheritDoc} */ - public function preExecuteActions(): array + public function preExecuteActions(array $updateSequences): array { return []; } diff --git a/src/Phinx/Db/Adapter/SQLiteAdapter.php b/src/Phinx/Db/Adapter/SQLiteAdapter.php index 1f9883ec1..e3e69a0ab 100644 --- a/src/Phinx/Db/Adapter/SQLiteAdapter.php +++ b/src/Phinx/Db/Adapter/SQLiteAdapter.php @@ -14,6 +14,7 @@ use InvalidArgumentException; use PDO; use PDOException; +use Phinx\Db\Action\AddForeignKey; use Phinx\Db\Table\Column; use Phinx\Db\Table\ForeignKey; use Phinx\Db\Table\Index; @@ -1648,7 +1649,6 @@ protected function getAddForeignKeyInstructions(Table $table, ForeignKey $foreig $tableName = $table->getName(); $instructions->addPostStep(function ($state) use ($foreignKey, $tableName) { - $this->execute('pragma foreign_keys = ON'); $sql = substr($state['createSQL'], 0, -1) . ',' . $this->getForeignKeySqlDefinition($foreignKey) . '); '; //Delete indexes from original table and recreate them in temporary table @@ -1992,10 +1992,23 @@ public function getDecoratedConnection(): Connection /** * {@inheritDoc} */ - public function preExecuteActions(): array + public function preExecuteActions(array $updateSequences): array { $foreignKeysEnabled = (bool)$this->fetchRow('PRAGMA foreign_keys')['foreign_keys']; + if (!$foreignKeysEnabled) { + foreach ($updateSequences as $updates) { + foreach ($updates as $update) { + foreach ($update->getActions() as $action) { + if ($action instanceof AddForeignKey) { + $foreignKeysEnabled = true; + break 3; + } + } + } + } + } + if ($foreignKeysEnabled) { $this->execute('PRAGMA foreign_keys = OFF'); } diff --git a/src/Phinx/Db/Plan/Plan.php b/src/Phinx/Db/Plan/Plan.php index cade7767c..c0c9ac231 100644 --- a/src/Phinx/Db/Plan/Plan.php +++ b/src/Phinx/Db/Plan/Plan.php @@ -143,14 +143,15 @@ protected function inverseUpdatesSequence(): array */ public function execute(AdapterInterface $executor): void { - $preOptions = $executor->preExecuteActions(); + $updatesSequence = $this->updatesSequence(); + $preOptions = $executor->preExecuteActions($updatesSequence); foreach ($this->tableCreates as $newTable) { $executor->createTable($newTable->getTable(), $newTable->getColumns(), $newTable->getIndexes()); } $tables = []; - foreach ($this->updatesSequence() as $updates) { + foreach ($updatesSequence as $updates) { foreach ($updates as $update) { $tables[] = $update->getTable()->getName(); $executor->executeActions($update->getTable(), $update->getActions()); @@ -168,7 +169,7 @@ public function execute(AdapterInterface $executor): void */ public function executeInverse(AdapterInterface $executor): void { - $preOptions = $executor->preExecuteActions(); + $preOptions = $executor->preExecuteActions($this->inverseUpdatesSequence()); $tables = []; foreach ($this->inverseUpdatesSequence() as $updates) { @@ -178,11 +179,11 @@ public function executeInverse(AdapterInterface $executor): void } } - $executor->postExecuteActions(array_unique($tables), $preOptions); - foreach ($this->tableCreates as $newTable) { $executor->createTable($newTable->getTable(), $newTable->getColumns(), $newTable->getIndexes()); } + + $executor->postExecuteActions(array_unique($tables), $preOptions); } /** diff --git a/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php b/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php index 1dc2e4743..49e2f1afd 100644 --- a/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php +++ b/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php @@ -2397,14 +2397,19 @@ public function testAlterTableDoesViolateForeignKeyConstraintOnSourceTableChange $adapterReflection = new ReflectionObject($adapter); $queryReflection = $adapterReflection->getParentClass()->getMethod('query'); + $count = 0; $adapter ->expects($this->atLeastOnce()) ->method('query') - ->willReturnCallback(function (string $sql, array $params = []) use ($adapter, $queryReflection) { + ->willReturnCallback(function (string $sql, array $params = []) use ($adapter, &$count, $queryReflection) { if ($sql === 'PRAGMA foreign_key_check(`comments`)') { - $adapter->execute('PRAGMA foreign_keys = OFF'); - $adapter->execute('DELETE FROM articles'); - $adapter->execute('PRAGMA foreign_keys = ON'); + $count++; + + if ($count > 1) { + $adapter->execute('PRAGMA foreign_keys = OFF'); + $adapter->execute('DELETE FROM articles'); + $adapter->execute('PRAGMA foreign_keys = ON'); + } } return $queryReflection->invoke($adapter, $sql, $params); From f8dd33b0ec60722b8e2803d489ed4287fd5e3b15 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Wed, 18 Jun 2025 16:13:10 -0600 Subject: [PATCH 5/8] update function Signed-off-by: Matthew Peveler --- src/Phinx/Db/Adapter/AdapterWrapper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Phinx/Db/Adapter/AdapterWrapper.php b/src/Phinx/Db/Adapter/AdapterWrapper.php index cf59e43e2..dbdfe1fcb 100644 --- a/src/Phinx/Db/Adapter/AdapterWrapper.php +++ b/src/Phinx/Db/Adapter/AdapterWrapper.php @@ -477,9 +477,9 @@ public function getConnection(): PDO /** * {@inheritDoc} */ - public function preExecuteActions(): array + public function preExecuteActions(array $updateSequences): array { - return $this->getAdapter()->preExecuteActions(); + return $this->getAdapter()->preExecuteActions($updateSequences); } /** From 5c4630632be4bf1933108d3a9085b73281586637 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Wed, 18 Jun 2025 16:22:16 -0600 Subject: [PATCH 6/8] fix phpdoc param Signed-off-by: Matthew Peveler --- src/Phinx/Db/Adapter/SQLiteAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Phinx/Db/Adapter/SQLiteAdapter.php b/src/Phinx/Db/Adapter/SQLiteAdapter.php index e3e69a0ab..fc9b10235 100644 --- a/src/Phinx/Db/Adapter/SQLiteAdapter.php +++ b/src/Phinx/Db/Adapter/SQLiteAdapter.php @@ -1035,7 +1035,7 @@ protected function recreateIndicesAndTriggers(AlterInstructions $instructions): * the given table, and of those tables whose constraints are * targeting it. * - * @param string|array $tableName The name of the table for which to check constraints. + * @param string|array $tableNames The name of the table for which to check constraints. * @return void */ protected function validateForeignKeys(string|array $tableNames): void From 98722aab73d38efb00bdb158fdcdd50caddf89db Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Wed, 18 Jun 2025 16:29:10 -0600 Subject: [PATCH 7/8] fix phpcs Signed-off-by: Matthew Peveler --- src/Phinx/Db/Adapter/PdoAdapter.php | 1 - src/Phinx/Db/Adapter/SQLiteAdapter.php | 4 ++-- tests/Phinx/Db/Adapter/SQLiteAdapterTest.php | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Phinx/Db/Adapter/PdoAdapter.php b/src/Phinx/Db/Adapter/PdoAdapter.php index 51ba5c08d..3f57e87be 100644 --- a/src/Phinx/Db/Adapter/PdoAdapter.php +++ b/src/Phinx/Db/Adapter/PdoAdapter.php @@ -1140,6 +1140,5 @@ public function executeActions(Table $table, array $actions): void */ public function postExecuteActions(array $tableNames, array $preOptions): void { - } } diff --git a/src/Phinx/Db/Adapter/SQLiteAdapter.php b/src/Phinx/Db/Adapter/SQLiteAdapter.php index fc9b10235..e4f9b3a02 100644 --- a/src/Phinx/Db/Adapter/SQLiteAdapter.php +++ b/src/Phinx/Db/Adapter/SQLiteAdapter.php @@ -1048,8 +1048,8 @@ protected function validateForeignKeys(string|array $tableNames): void $otherTables = $this ->query( - "SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT IN (" . implode(',',array_fill(0, count($tableNames), '?')) . ')', - $tableNames + "SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT IN (" . implode(',', array_fill(0, count($tableNames), '?')) . ')', + $tableNames, ) ->fetchAll(); diff --git a/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php b/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php index 49e2f1afd..1c2bd74f3 100644 --- a/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php +++ b/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php @@ -2387,7 +2387,7 @@ public function testAlterTableDoesViolateForeignKeyConstraintOnTargetTableChange */ public function testAlterTableDoesViolateForeignKeyConstraintOnSourceTableChange() { - /** @var \Phinx\Db\Adapter\AdapterInterface&\PHPUnit\Framework\MockObject\MockObject */ + /** @var \Phinx\Db\Adapter\AdapterInterface&\PHPUnit\Framework\MockObject\MockObject $adapter */ $adapter = $this ->getMockBuilder(SQLiteAdapter::class) ->setConstructorArgs([SQLITE_DB_CONFIG, new ArrayInput([]), new NullOutput()]) From bf8b45b74b99c34383e0be4416817e0e95863da8 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Wed, 18 Jun 2025 16:32:19 -0600 Subject: [PATCH 8/8] move function stubs in AbstractAdapter Signed-off-by: Matthew Peveler --- src/Phinx/Db/Adapter/AbstractAdapter.php | 15 +++++++++++++++ src/Phinx/Db/Adapter/PdoAdapter.php | 15 --------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Phinx/Db/Adapter/AbstractAdapter.php b/src/Phinx/Db/Adapter/AbstractAdapter.php index abc223ddb..7391d12d1 100644 --- a/src/Phinx/Db/Adapter/AbstractAdapter.php +++ b/src/Phinx/Db/Adapter/AbstractAdapter.php @@ -410,4 +410,19 @@ protected function hasCreatedTable(string $tableName): bool return in_array($tableName, $this->createdTables, true); } + + /** + * {@inheritDoc} + */ + public function preExecuteActions(array $updateSequences): array + { + return []; + } + + /** + * {@inheritDoc} + */ + public function postExecuteActions(array $tableNames, array $preOptions): void + { + } } diff --git a/src/Phinx/Db/Adapter/PdoAdapter.php b/src/Phinx/Db/Adapter/PdoAdapter.php index 3f57e87be..46e6b0870 100644 --- a/src/Phinx/Db/Adapter/PdoAdapter.php +++ b/src/Phinx/Db/Adapter/PdoAdapter.php @@ -1001,14 +1001,6 @@ public function changeComment(Table $table, $newComment): void */ abstract protected function getChangeCommentInstructions(Table $table, ?string $newComment): AlterInstructions; - /** - * {@inheritDoc} - */ - public function preExecuteActions(array $updateSequences): array - { - return []; - } - /** * {@inheritDoc} * @@ -1134,11 +1126,4 @@ public function executeActions(Table $table, array $actions): void $this->executeAlterSteps($table->getName(), $instructions); } - - /** - * {@inheritDoc} - */ - public function postExecuteActions(array $tableNames, array $preOptions): void - { - } }