From bf6c0346d8d35a719dd1bff1cb4d573d422f99ff Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 31 May 2017 09:31:18 +0200 Subject: WIP Signed-off-by: Thomas Citharel --- app/DoctrineMigrations/Version20170328185535.php | 99 ++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 app/DoctrineMigrations/Version20170328185535.php (limited to 'app/DoctrineMigrations/Version20170328185535.php') diff --git a/app/DoctrineMigrations/Version20170328185535.php b/app/DoctrineMigrations/Version20170328185535.php new file mode 100644 index 00000000..f0afb7b9 --- /dev/null +++ b/app/DoctrineMigrations/Version20170328185535.php @@ -0,0 +1,99 @@ +container = $container; + } + + private function getTable($tableName) + { + return $this->container->getParameter('database_table_prefix').$tableName; + } + + /** + * @param Schema $schema + */ + public function up(Schema $schema) + { + try { + $schema->getTable($this->getTable('change')); + } catch (SchemaException $e) { + // The Change table doesn't exist, we need to create it + if (10 == $e->getCode()) { + if ($this->connection->getDatabasePlatform()->getName() == 'sqlite') { + $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)'); + + return true; + } + + $changeTable = $schema->createTable($this->getTable('change')); + $changeTable->addColumn( + 'id', + 'integer', + ['autoincrement' => true] + ); + $changeTable->addColumn( + 'type', + 'integer', + ['notnull' => false] + ); + $changeTable->addColumn( + 'created_at', + 'datetime', + ['notnull' => false] + ); + $changeTable->addColumn( + 'entry_id', + 'integer', + ['notnull' => false] + ); + + $changeTable->setPrimaryKey(['id']); + + $changeTable->addForeignKeyConstraint( + $this->getTable('entry'), + ['entry_id'], + ['id'], + ['onDelete' => 'CASCADE'], + 'IDX_change_entry' + ); + + return true; + } + } + + throw new SkipMigrationException('It seems that you already played this migration.'); + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + try { + $changeTable = $schema->getTable($this->getTable('change')); + $schema->dropTable($changeTable->getName()); + } catch (SchemaException $e) { + throw new SkipMigrationException('It seems that you already played this migration.'); + } + } +} -- cgit v1.2.3