forked from davedevelopment/phpmig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update for Symfony 6.x and drop support for older versions
- Loading branch information
1 parent
3e214c5
commit 3c9a9e4
Showing
3 changed files
with
99 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
language: php | ||
|
||
php: | ||
- 7.1 | ||
- 7.2 | ||
- 7.3 | ||
- 7.4 | ||
- 8.0 | ||
- 8.1 | ||
|
||
branches: | ||
only: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
/** | ||
* @package Phpmig | ||
* @subpackage Phpmig\Adapter | ||
*/ | ||
namespace Phpmig\Adapter\Doctrine; | ||
|
||
use \Doctrine\DBAL\Connection, | ||
\Doctrine\DBAL\Schema\Schema, | ||
\Phpmig\Migration\Migration, | ||
\Phpmig\Adapter\AdapterInterface; | ||
|
||
/** | ||
* Phpmig adapter for doctrine dbal 3 connection | ||
*/ | ||
class DBAL3 implements AdapterInterface | ||
{ | ||
protected Connection $connection; | ||
protected string $tableName; | ||
|
||
public function __construct(Connection $connection, string $tableName) | ||
{ | ||
$this->connection = $connection; | ||
$this->tableName = $tableName; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function fetchAll() : array | ||
{ | ||
$tableName = $this->connection->quoteIdentifier($this->tableName); | ||
$sql = "SELECT version FROM $tableName ORDER BY version ASC"; | ||
$all = $this->connection->fetchAllAssociative($sql); | ||
|
||
return array_map(function($v) {return $v['version'];}, $all); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function up(Migration $migration) : self | ||
{ | ||
$this->connection->insert($this->tableName, array( | ||
'version' => $migration->getVersion(), | ||
)); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function down(Migration $migration) : self | ||
{ | ||
$this->connection->delete($this->tableName, array( | ||
'version' => $migration->getVersion(), | ||
)); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function hasSchema() : bool | ||
{ | ||
$sm = $this->connection->createSchemaManager(); | ||
$tables = $sm->listTables(); | ||
foreach($tables as $table) { | ||
if ($table->getName() == $this->tableName) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createSchema() : self | ||
{ | ||
$schema = new \Doctrine\DBAL\Schema\Schema(); | ||
$table = $schema->createTable($this->tableName); | ||
$table->addColumn("version", "string", array("length" => 255)); | ||
$queries = $schema->toSql($this->connection->getDatabasePlatform()); | ||
foreach($queries as $sql) { | ||
$this->connection->executeQuery($sql); | ||
} | ||
|
||
return $this; | ||
} | ||
} |