3 namespace Application\Migrations
;
5 use Doctrine\DBAL\Migrations\AbstractMigration
;
6 use Doctrine\DBAL\Schema\Schema
;
7 use Doctrine\DBAL\Schema\SchemaException
;
8 use Symfony\Component\DependencyInjection\ContainerAwareInterface
;
9 use Symfony\Component\DependencyInjection\ContainerInterface
;
10 use Doctrine\DBAL\Migrations\SkipMigrationException
;
13 * Creates the Change table.
15 class Version20170328185535
extends AbstractMigration
implements ContainerAwareInterface
18 * @var ContainerInterface
22 public function setContainer(ContainerInterface
$container = null)
24 $this->container
= $container;
27 private function getTable($tableName)
29 return $this->container
->getParameter('database_table_prefix').$tableName;
33 * @param Schema $schema
35 public function up(Schema
$schema)
38 $schema->getTable($this->getTable('change'));
39 } catch (SchemaException
$e) {
40 // The Change table doesn't exist, we need to create it
41 if (10 == $e->getCode()) {
42 if ($this->connection
->getDatabasePlatform()->getName() == 'sqlite') {
43 $this->addSql('CREATE TABLE '.$this->getTable('change').' (id INTEGER NOT NULL, entry_id INTEGER DEFAULT NULL, type INTEGER NOT NULL, created_at DATETIME NOT NULL, PRIMARY KEY(id), CONSTRAINT FK_133B9D0FBA364942 FOREIGN KEY (entry_id) REFERENCES '.$this->getTable('entry').' (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
48 $changeTable = $schema->createTable($this->getTable('change'));
49 $changeTable->addColumn(
52 ['autoincrement' => true]
54 $changeTable->addColumn(
59 $changeTable->addColumn(
64 $changeTable->addColumn(
70 $changeTable->setPrimaryKey(['id']);
72 $changeTable->addForeignKeyConstraint(
73 $this->getTable('entry'),
76 ['onDelete' => 'CASCADE'],
84 throw new SkipMigrationException('It seems that you already played this migration.');
88 * @param Schema $schema
90 public function down(Schema
$schema)
93 $changeTable = $schema->getTable($this->getTable('change'));
94 $schema->dropTable($changeTable->getName());
95 } catch (SchemaException
$e) {
96 throw new SkipMigrationException('It seems that you already played this migration.');