diff --git a/src/Db/Adapter/MysqlAdapter.php b/src/Db/Adapter/MysqlAdapter.php index 29bbea08..21807131 100644 --- a/src/Db/Adapter/MysqlAdapter.php +++ b/src/Db/Adapter/MysqlAdapter.php @@ -11,7 +11,6 @@ use Cake\Core\Configure; use Cake\Database\Connection; use Cake\Database\Exception\QueryException; -use Cake\Database\Schema\SchemaDialect; use InvalidArgumentException; use Migrations\Db\AlterInstructions; use Migrations\Db\Literal; @@ -91,19 +90,6 @@ class MysqlAdapter extends PdoAdapter public const FIRST = 'FIRST'; - /** - * {@inheritDoc} - * - * @throws \RuntimeException - * @throws \InvalidArgumentException - * @return void - */ - public function connect(): void - { - $this->getConnection()->getDriver()->connect(); - $this->setConnection($this->getConnection()); - } - /** * @inheritDoc */ @@ -114,46 +100,6 @@ public function setConnection(Connection $connection): AdapterInterface return parent::setConnection($connection); } - /** - * @inheritDoc - */ - public function disconnect(): void - { - $this->getConnection()->getDriver()->disconnect(); - } - - /** - * @inheritDoc - */ - public function hasTransactions(): bool - { - return true; - } - - /** - * @inheritDoc - */ - public function beginTransaction(): void - { - $this->getConnection()->begin(); - } - - /** - * @inheritDoc - */ - public function commitTransaction(): void - { - $this->getConnection()->commit(); - } - - /** - * @inheritDoc - */ - public function rollbackTransaction(): void - { - $this->getConnection()->rollback(); - } - /** * @inheritDoc */ @@ -164,28 +110,6 @@ public function quoteTableName(string $tableName): string return $driver->quoteIdentifier($tableName); } - /** - * @inheritDoc - */ - public function quoteColumnName(string $columnName): string - { - $driver = $this->getConnection()->getDriver(); - - return $driver->quoteIdentifier($columnName); - } - - /** - * Get the schema dialect for this adapter. - * - * @return \Cake\Database\Schema\SchemaDialect - */ - protected function getSchemaDialect(): SchemaDialect - { - $driver = $this->getConnection()->getDriver(); - - return $driver->schemaDialect(); - } - /** * @inheritDoc */ diff --git a/src/Db/Adapter/PdoAdapter.php b/src/Db/Adapter/PdoAdapter.php index e5d0c068..227c1ce2 100644 --- a/src/Db/Adapter/PdoAdapter.php +++ b/src/Db/Adapter/PdoAdapter.php @@ -16,6 +16,7 @@ use Cake\Database\Query\InsertQuery; use Cake\Database\Query\SelectQuery; use Cake\Database\Query\UpdateQuery; +use Cake\Database\Schema\SchemaDialect; use InvalidArgumentException; use Migrations\Config\Config; use Migrations\Db\Action\AddColumn; @@ -55,6 +56,81 @@ abstract class PdoAdapter extends AbstractAdapter implements DirectActionInterfa */ protected ?Connection $connection = null; + /** + * Get the schema dialect for this adapter. + * + * @return \Cake\Database\Schema\SchemaDialect + */ + protected function getSchemaDialect(): SchemaDialect + { + $driver = $this->getConnection()->getDriver(); + + return $driver->schemaDialect(); + } + + /** + * {@inheritDoc} + * + * @throws \RuntimeException + * @throws \InvalidArgumentException + * @return void + */ + public function connect(): void + { + $this->getConnection()->getDriver()->connect(); + $this->setConnection($this->getConnection()); + } + + /** + * @inheritDoc + */ + public function disconnect(): void + { + $this->getConnection()->getDriver()->disconnect(); + } + + /** + * @inheritDoc + */ + public function beginTransaction(): void + { + $this->getConnection()->begin(); + } + + /** + * @inheritDoc + */ + public function commitTransaction(): void + { + $this->getConnection()->commit(); + } + + /** + * @inheritDoc + */ + public function rollbackTransaction(): void + { + $this->getConnection()->rollback(); + } + + /** + * @inheritDoc + */ + public function hasTransactions(): bool + { + return true; + } + + /** + * @inheritDoc + */ + public function quoteColumnName(string $columnName): string + { + $driver = $this->getConnection()->getDriver(); + + return $driver->quoteIdentifier($columnName); + } + /** * Writes a message to stdout if verbose output is on * @@ -186,16 +262,6 @@ public function getDecoratedConnection(): Connection return $this->getConnection(); } - /** - * @inheritDoc - */ - abstract public function connect(): void; - - /** - * @inheritDoc - */ - abstract public function disconnect(): void; - /** * @inheritDoc */ diff --git a/src/Db/Adapter/PostgresAdapter.php b/src/Db/Adapter/PostgresAdapter.php index 99a26d73..22454693 100644 --- a/src/Db/Adapter/PostgresAdapter.php +++ b/src/Db/Adapter/PostgresAdapter.php @@ -9,7 +9,6 @@ namespace Migrations\Db\Adapter; use Cake\Database\Connection; -use Cake\Database\Schema\SchemaDialect; use InvalidArgumentException; use Migrations\Db\AlterInstructions; use Migrations\Db\Literal; @@ -71,71 +70,6 @@ public function setConnection(Connection $connection): AdapterInterface return parent::setConnection($connection); } - /** - * {@inheritDoc} - * - * @throws \RuntimeException - * @throws \InvalidArgumentException - * @return void - */ - public function connect(): void - { - $this->getConnection()->getDriver()->connect(); - $this->setConnection($this->getConnection()); - } - - /** - * @inheritDoc - */ - public function disconnect(): void - { - $this->getConnection()->getDriver()->disconnect(); - } - - /** - * @inheritDoc - */ - public function hasTransactions(): bool - { - return true; - } - - /** - * @inheritDoc - */ - public function beginTransaction(): void - { - $this->getConnection()->begin(); - } - - /** - * @inheritDoc - */ - public function commitTransaction(): void - { - $this->getConnection()->commit(); - } - - /** - * @inheritDoc - */ - public function rollbackTransaction(): void - { - $this->getConnection()->rollback(); - } - - /** - * Get the schema dialect for this adapter. - * - * @return \Cake\Database\Schema\SchemaDialect - */ - protected function getSchemaDialect(): SchemaDialect - { - $driver = $this->getConnection()->getDriver(); - - return $driver->schemaDialect(); - } - /** * Quotes a schema name for use in a query. * @@ -157,16 +91,6 @@ public function quoteTableName(string $tableName): string return $this->quoteSchemaName($parts['schema']) . '.' . $this->quoteColumnName($parts['table']); } - /** - * @inheritDoc - */ - public function quoteColumnName(string $columnName): string - { - $driver = $this->getConnection()->getDriver(); - - return $driver->quoteIdentifier($columnName); - } - /** * @inheritDoc */ diff --git a/src/Db/Adapter/SqliteAdapter.php b/src/Db/Adapter/SqliteAdapter.php index e5f525f2..89b20205 100644 --- a/src/Db/Adapter/SqliteAdapter.php +++ b/src/Db/Adapter/SqliteAdapter.php @@ -9,7 +9,6 @@ namespace Migrations\Db\Adapter; use BadMethodCallException; -use Cake\Database\Schema\SchemaDialect; use InvalidArgumentException; use Migrations\Db\AlterInstructions; use Migrations\Db\Expression; @@ -134,19 +133,6 @@ public function databaseVersionAtLeast(string $ver): bool return version_compare($actual, $ver, '>='); } - /** - * {@inheritDoc} - * - * @throws \RuntimeException - * @throws \InvalidArgumentException - * @return void - */ - public function connect(): void - { - $this->getConnection()->getDriver()->connect(); - $this->setConnection($this->getConnection()); - } - /** * @inheritDoc */ @@ -166,46 +152,6 @@ public function setOptions(array $options): AdapterInterface return $this; } - /** - * @inheritDoc - */ - public function disconnect(): void - { - $this->getConnection()->getDriver()->disconnect(); - } - - /** - * @inheritDoc - */ - public function hasTransactions(): bool - { - return true; - } - - /** - * @inheritDoc - */ - public function beginTransaction(): void - { - $this->getConnection()->begin(); - } - - /** - * @inheritDoc - */ - public function commitTransaction(): void - { - $this->getConnection()->commit(); - } - - /** - * @inheritDoc - */ - public function rollbackTransaction(): void - { - $this->getConnection()->rollBack(); - } - /** * @inheritDoc */ @@ -216,28 +162,6 @@ public function quoteTableName($tableName): string return $driver->quoteIdentifier($tableName); } - /** - * @inheritDoc - */ - public function quoteColumnName($columnName): string - { - $driver = $this->getConnection()->getDriver(); - - return $driver->quoteIdentifier($columnName); - } - - /** - * Get the schema dialect for this adapter. - * - * @return \Cake\Database\Schema\SchemaDialect - */ - protected function getSchemaDialect(): SchemaDialect - { - $driver = $this->getConnection()->getDriver(); - - return $driver->schemaDialect(); - } - /** * Generates a regular expression to match identifiers that may or * may not be quoted with any of the supported quotes. @@ -830,7 +754,7 @@ protected function bufferIndicesAndTriggers(AlterInstructions $instructions, str "SELECT * FROM sqlite_master WHERE - (\"type\" = 'index' OR `type` = 'trigger') + (\"type\" = 'index' OR \"type\" = 'trigger') AND tbl_name = ? AND sql IS NOT NULL ", diff --git a/src/Db/Adapter/SqlserverAdapter.php b/src/Db/Adapter/SqlserverAdapter.php index e28fbb9b..d184d6ff 100644 --- a/src/Db/Adapter/SqlserverAdapter.php +++ b/src/Db/Adapter/SqlserverAdapter.php @@ -9,7 +9,6 @@ namespace Migrations\Db\Adapter; use BadMethodCallException; -use Cake\Database\Schema\SchemaDialect; use InvalidArgumentException; use Migrations\Db\AlterInstructions; use Migrations\Db\Literal; @@ -48,70 +47,6 @@ class SqlserverAdapter extends PdoAdapter self::PHINX_TYPE_DECIMAL => true, ]; - /** - * {@inheritDoc} - * - * @throws \InvalidArgumentException - * @return void - */ - public function connect(): void - { - $this->getConnection()->getDriver()->connect(); - $this->setConnection($this->getConnection()); - } - - /** - * @inheritDoc - */ - public function disconnect(): void - { - $this->getConnection()->getDriver()->disconnect(); - } - - /** - * @inheritDoc - */ - public function hasTransactions(): bool - { - return true; - } - - /** - * @inheritDoc - */ - public function beginTransaction(): void - { - $this->getConnection()->begin(); - } - - /** - * @inheritDoc - */ - public function commitTransaction(): void - { - $this->getConnection()->commit(); - } - - /** - * @inheritDoc - */ - public function rollbackTransaction(): void - { - $this->getConnection()->rollback(); - } - - /** - * Get the schema dialect for this adapter. - * - * @return \Cake\Database\Schema\SchemaDialect - */ - protected function getSchemaDialect(): SchemaDialect - { - $driver = $this->getConnection()->getDriver(); - - return $driver->schemaDialect(); - } - /** * Quotes a schema name for use in a query. * @@ -133,16 +68,6 @@ public function quoteTableName(string $tableName): string return $this->quoteSchemaName($parts['schema']) . '.' . $this->quoteColumnName($parts['table']); } - /** - * @inheritDoc - */ - public function quoteColumnName(string $columnName): string - { - $driver = $this->getConnection()->getDriver(); - - return $driver->quoteIdentifier($columnName); - } - /** * @inheritDoc */ @@ -211,7 +136,7 @@ public function createTable(Table $table, array $columns = [], array $indexes = if (is_string($primaryKey)) { // handle primary_key => 'id' $pkSql .= $this->quoteColumnName($primaryKey); } elseif (is_array($primaryKey)) { // handle primary_key => array('tag_id', 'resource_id') - $pkSql .= implode(',', array_map([$this, 'quoteColumnName'], $primaryKey)); + $pkSql .= implode(',', array_map($this->quoteColumnName(...), $primaryKey)); } $pkSql .= ')'; $sqlBuffer[] = $pkSql; @@ -265,7 +190,7 @@ protected function getChangePrimaryKeyInstructions(Table $table, $newColumns): A if (is_string($newColumns)) { // handle primary_key => 'id' $sql .= $this->quoteColumnName($newColumns); } elseif (is_array($newColumns)) { // handle primary_key => array('tag_id', 'resource_id') - $sql .= implode(',', array_map([$this, 'quoteColumnName'], $newColumns)); + $sql .= implode(',', array_map($this->quoteColumnName(...), $newColumns)); } $sql .= ')'; $instructions->addPostStep($sql);