Skip to content

Commit

Permalink
Update for Symfony 6.x and drop support for older versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ruben-haegeman committed May 19, 2022
1 parent 3e214c5 commit 3c9a9e4
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 6 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
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:
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
}],
"require": {
"php": ">=7.1",
"symfony/console": "^2.0||^3.0||^4.0||^5.0",
"symfony/config": "^2.0||^3.0||^4.0||^5.0"
"symfony/console": "^5.0||^6.0",
"symfony/config": "^5.0||^6.0"
},
"require-dev": {
"phpunit/phpunit": "^7.5||^8.5||^9.2",
"phpunit/phpunit": "^9.2",
"mockery/mockery": "*@dev"
},
"suggest": {
Expand Down
94 changes: 94 additions & 0 deletions src/Phpmig/Adapter/Doctrine/DBAL3.php
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;
}
}

0 comments on commit 3c9a9e4

Please sign in to comment.