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

Update for Symfony 6.x and drop support for older versions #156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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;
}
}