From 4eb7b418dba6d1c76407f876b3c9687f65cc1329 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Fri, 27 Apr 2018 17:58:09 +0300 Subject: [PATCH] #44 Database migration for new schema. --- .../Version20180427143940.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 app/DoctrineMigrations/Version20180427143940.php diff --git a/app/DoctrineMigrations/Version20180427143940.php b/app/DoctrineMigrations/Version20180427143940.php new file mode 100644 index 0000000..795184e --- /dev/null +++ b/app/DoctrineMigrations/Version20180427143940.php @@ -0,0 +1,47 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('ALTER TABLE posts.posts ADD is_subscribed BOOLEAN DEFAULT FALSE NOT NULL'); + // Removing parent_id constraint and index + $this->addSql('ALTER TABLE posts.comments DROP CONSTRAINT fk_62899975727aca70'); + $this->addSql('DROP INDEX posts.idx_62899975727aca70'); + $this->addSql('ALTER TABLE posts.comments DROP parent_id'); + + $this->addSql('ALTER TABLE posts.comments ADD to_number INT'); + $this->addSql('ALTER TABLE posts.comments ALTER number TYPE INT'); + $this->addSql('ALTER TABLE posts.comments ALTER number DROP DEFAULT'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_6289997596901F54 ON posts.comments (number)'); + } + + public function down(Schema $schema) + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('ALTER TABLE posts.posts DROP is_subscribed'); + $this->addSql('DROP INDEX posts.UNIQ_6289997596901F54'); + $this->addSql('ALTER TABLE posts.comments ADD parent_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE posts.comments DROP to_number'); + $this->addSql('ALTER TABLE posts.comments ALTER number TYPE SMALLINT'); + $this->addSql('ALTER TABLE posts.comments ALTER number DROP DEFAULT'); + $this->addSql('ALTER TABLE posts.comments ADD CONSTRAINT fk_62899975727aca70 FOREIGN KEY (parent_id) REFERENCES posts.comments (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX idx_62899975727aca70 ON posts.comments (parent_id)'); + } +}