Updated to doctrine migrations 2

This commit is contained in:
Alejandro Celaya 2019-03-09 18:45:58 +01:00
parent 6314315db7
commit f46de4d3e1
5 changed files with 22 additions and 29 deletions

View file

@ -20,7 +20,7 @@
"cakephp/chronos": "^1.2", "cakephp/chronos": "^1.2",
"cocur/slugify": "^3.0", "cocur/slugify": "^3.0",
"doctrine/cache": "^1.6", "doctrine/cache": "^1.6",
"doctrine/migrations": "^1.4", "doctrine/migrations": "^2.0",
"doctrine/orm": "^2.5", "doctrine/orm": "^2.5",
"endroid/qr-code": "^1.7", "endroid/qr-code": "^1.7",
"firebase/php-jwt": "^4.0", "firebase/php-jwt": "^4.0",

View file

@ -3,21 +3,24 @@ declare(strict_types=1);
namespace ShlinkMigrations; namespace ShlinkMigrations;
use Doctrine\DBAL\Migrations\AbstractMigration; use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\Migrations\AbstractMigration;
/** /**
* Auto-generated Migration: Please modify to your needs! * Auto-generated Migration: Please modify to your needs!
*/ */
class Version20160819142757 extends AbstractMigration class Version20160819142757 extends AbstractMigration
{ {
const MYSQL = 'mysql'; private const MYSQL = 'mysql';
const SQLITE = 'sqlite'; private const SQLITE = 'sqlite';
/** /**
* @param Schema $schema * @throws DBALException
* @throws SchemaException
*/ */
public function up(Schema $schema) public function up(Schema $schema): void
{ {
$db = $this->connection->getDatabasePlatform()->getName(); $db = $this->connection->getDatabasePlatform()->getName();
$table = $schema->getTable('short_urls'); $table = $schema->getTable('short_urls');
@ -31,9 +34,9 @@ class Version20160819142757 extends AbstractMigration
} }
/** /**
* @param Schema $schema * @throws DBALException
*/ */
public function down(Schema $schema) public function down(Schema $schema): void
{ {
$db = $this->connection->getDatabasePlatform()->getName(); $db = $this->connection->getDatabasePlatform()->getName();
} }

View file

@ -3,19 +3,16 @@ declare(strict_types=1);
namespace ShlinkMigrations; namespace ShlinkMigrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\Migrations\AbstractMigration;
/** /**
* Auto-generated Migration: Please modify to your needs! * Auto-generated Migration: Please modify to your needs!
*/ */
class Version20160820191203 extends AbstractMigration class Version20160820191203 extends AbstractMigration
{ {
/** public function up(Schema $schema): void
* @param Schema $schema
*/
public function up(Schema $schema)
{ {
// Check if the tables already exist // Check if the tables already exist
$tables = $schema->getTables(); $tables = $schema->getTables();
@ -29,7 +26,7 @@ class Version20160820191203 extends AbstractMigration
$this->createShortUrlsInTagsTable($schema); $this->createShortUrlsInTagsTable($schema);
} }
protected function createTagsTable(Schema $schema) private function createTagsTable(Schema $schema): void
{ {
$table = $schema->createTable('tags'); $table = $schema->createTable('tags');
$table->addColumn('id', Type::BIGINT, [ $table->addColumn('id', Type::BIGINT, [
@ -46,7 +43,7 @@ class Version20160820191203 extends AbstractMigration
$table->setPrimaryKey(['id']); $table->setPrimaryKey(['id']);
} }
protected function createShortUrlsInTagsTable(Schema $schema) private function createShortUrlsInTagsTable(Schema $schema): void
{ {
$table = $schema->createTable('short_urls_in_tags'); $table = $schema->createTable('short_urls_in_tags');
$table->addColumn('short_url_id', Type::BIGINT, [ $table->addColumn('short_url_id', Type::BIGINT, [
@ -70,10 +67,7 @@ class Version20160820191203 extends AbstractMigration
$table->setPrimaryKey(['short_url_id', 'tag_id']); $table->setPrimaryKey(['short_url_id', 'tag_id']);
} }
/** public function down(Schema $schema): void
* @param Schema $schema
*/
public function down(Schema $schema)
{ {
$schema->dropTable('short_urls_in_tags'); $schema->dropTable('short_urls_in_tags');
$schema->dropTable('tags'); $schema->dropTable('tags');

View file

@ -3,10 +3,10 @@ declare(strict_types=1);
namespace ShlinkMigrations; namespace ShlinkMigrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaException; use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\Migrations\AbstractMigration;
/** /**
* Auto-generated Migration: Please modify to your needs! * Auto-generated Migration: Please modify to your needs!
@ -14,10 +14,9 @@ use Doctrine\DBAL\Types\Type;
class Version20171021093246 extends AbstractMigration class Version20171021093246 extends AbstractMigration
{ {
/** /**
* @param Schema $schema
* @throws SchemaException * @throws SchemaException
*/ */
public function up(Schema $schema) public function up(Schema $schema): void
{ {
$shortUrls = $schema->getTable('short_urls'); $shortUrls = $schema->getTable('short_urls');
if ($shortUrls->hasColumn('valid_since')) { if ($shortUrls->hasColumn('valid_since')) {
@ -33,10 +32,9 @@ class Version20171021093246 extends AbstractMigration
} }
/** /**
* @param Schema $schema
* @throws SchemaException * @throws SchemaException
*/ */
public function down(Schema $schema) public function down(Schema $schema): void
{ {
$shortUrls = $schema->getTable('short_urls'); $shortUrls = $schema->getTable('short_urls');
if (! $shortUrls->hasColumn('valid_since')) { if (! $shortUrls->hasColumn('valid_since')) {

View file

@ -3,10 +3,10 @@ declare(strict_types=1);
namespace ShlinkMigrations; namespace ShlinkMigrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaException; use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\Migrations\AbstractMigration;
/** /**
* Auto-generated Migration: Please modify to your needs! * Auto-generated Migration: Please modify to your needs!
@ -14,10 +14,9 @@ use Doctrine\DBAL\Types\Type;
class Version20171022064541 extends AbstractMigration class Version20171022064541 extends AbstractMigration
{ {
/** /**
* @param Schema $schema
* @throws SchemaException * @throws SchemaException
*/ */
public function up(Schema $schema) public function up(Schema $schema): void
{ {
$shortUrls = $schema->getTable('short_urls'); $shortUrls = $schema->getTable('short_urls');
if ($shortUrls->hasColumn('max_visits')) { if ($shortUrls->hasColumn('max_visits')) {
@ -31,10 +30,9 @@ class Version20171022064541 extends AbstractMigration
} }
/** /**
* @param Schema $schema
* @throws SchemaException * @throws SchemaException
*/ */
public function down(Schema $schema) public function down(Schema $schema): void
{ {
$shortUrls = $schema->getTable('short_urls'); $shortUrls = $schema->getTable('short_urls');
if (! $shortUrls->hasColumn('max_visits')) { if (! $shortUrls->hasColumn('max_visits')) {