setForeignKeyChecks(false); } /** * @param Schema $schema */ public function postUp(Schema $schema) { parent::postUp($schema); $this->setForeignKeyChecks(true); } /** * @param Schema $schema */ public function preDown(Schema $schema) { parent::preDown($schema); $this->setForeignKeyChecks(false); } /** * @param Schema $schema */ public function postDown(Schema $schema) { parent::postDown($schema); $this->setForeignKeyChecks(true); } public function up(Schema $schema) { $this->abortIf( $this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'." ); $this->addSql("ALTER TABLE super_puper DROP hyper_id"); } public function down(Schema $schema) { $this->abortIf( $this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'." ); $this->addSql("ALTER TABLE super_puper ADD hyper_id INT UNSIGNED NOT NULL"); } /** * @param boolean $enabled */ protected function setForeignKeyChecks($enabled) { $connection = $this->connection; $platform = $connection->getDatabasePlatform(); if ($platform instanceof MySqlPlatform) { $connection->exec(sprintf('SET foreign_key_checks = %s;', (int)$enabled)); } } }