diff --git a/app/classes/Framadate/Migrations/Version20180525110000.php b/app/classes/Framadate/Migrations/Version20180525110000.php new file mode 100644 index 0000000..b2d1e46 --- /dev/null +++ b/app/classes/Framadate/Migrations/Version20180525110000.php @@ -0,0 +1,100 @@ +getTable(Utils::table('poll')); + $poll->addColumn('collect_users_mail_integer', 'smallint', ['default' => 0]); + } + + /** + * @param Schema $schema + */ + public function postUp(Schema $schema) + { + $this->addSql('UPDATE ' . Utils::table('poll') . ' SET collect_users_mail_integer = collect_users_mail'); + $this->addSql('ALTER TABLE ' . Utils::table('poll') . ' DROP COLUMN collect_users_mail'); + if ($this->connection->getDatabasePlatform()->getName() === 'mysql') { + $this->addSql( + 'ALTER TABLE ' . Utils::table('poll') . ' CHANGE collect_users_mail_integer collect_users_mail SMALLINT' + ); + } else { + $this->addSql( + 'ALTER TABLE ' . Utils::table('poll') . ' RENAME COLUMN collect_users_mail_integer to collect_users_mail' + ); + } + } + + /** + * @param Schema $schema + * @throws \Doctrine\DBAL\Schema\SchemaException + */ + public function down(Schema $schema) + { + $poll = $schema->getTable(Utils::table('poll')); + $poll->addColumn('collect_users_mail_boolean', 'boolean', ['default' => false]); + } + + /** + * @param Schema $schema + */ + public function postDown(Schema $schema) + { + $this->addSql('UPDATE ' . Utils::table('poll') . ' SET collect_users_mail_boolean = collect_users_mail > 0'); + $this->addSql('ALTER TABLE ' . Utils::table('poll') . ' DROP COLUMN collect_users_mail'); + + if ($this->connection->getDatabasePlatform()->getName() === 'mysql') { + $this->addSql( + 'ALTER TABLE ' . Utils::table('poll') . ' CHANGE collect_users_mail_boolean collect_users_mail SMALLINT' + ); + } else { + $this->addSql( + 'ALTER TABLE ' . Utils::table('poll') . ' RENAME COLUMN collect_users_mail_boolean to collect_users_mail' + ); + } + } +}