Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate shared code into PdoAdapter #801

Merged
merged 4 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 0 additions & 76 deletions src/Db/Adapter/MysqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand Down
86 changes: 76 additions & 10 deletions src/Db/Adapter/PdoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -186,16 +262,6 @@ public function getDecoratedConnection(): Connection
return $this->getConnection();
}

/**
* @inheritDoc
*/
abstract public function connect(): void;

/**
* @inheritDoc
*/
abstract public function disconnect(): void;

/**
* @inheritDoc
*/
Expand Down
76 changes: 0 additions & 76 deletions src/Db/Adapter/PostgresAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand All @@ -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
*/
Expand Down
Loading
Loading