Created
September 15, 2016 09:36
-
-
Save alOneh/62f155d1b5b97f7db29df2fe92361bbf to your computer and use it in GitHub Desktop.
Migration 0 exemple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Application\Migrations; | |
use Doctrine\DBAL\Migrations\AbstractMigration; | |
use Doctrine\DBAL\Schema\Schema; | |
class Version00000000000000 extends AbstractMigration | |
{ | |
public function up(Schema $schema) | |
{ | |
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | |
$sql = <<<SQL | |
CREATE TABLE my_table ( | |
id NUMBER(10) NOT NULL, | |
... | |
); | |
SQL; | |
foreach (explode(';', $sql) as $stmt) { | |
$stmt = trim($stmt); | |
if (!empty($stmt)) { | |
$this->addSql($stmt); | |
} | |
} | |
} | |
public function down(Schema $schema) | |
{ | |
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | |
$schemaName = $schema->getName(); | |
$sql = <<<SQL | |
SET FOREIGN_KEY_CHECKS = 0; | |
SET @tables = NULL; | |
SELECT GROUP_CONCAT(table_schema, '.', table_name) INTO @tables | |
FROM information_schema.tables | |
WHERE table_schema = '$schemaName'; | |
SET @tables = CONCAT('DROP TABLE ', @tables); | |
PREPARE stmt FROM @tables; | |
EXECUTE stmt; | |
DEALLOCATE PREPARE stmt; | |
SET FOREIGN_KEY_CHECKS = 1; | |
SQL; | |
$this->addSql($sql); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to generate the
up()
mysql ?Then copy/paste the dump into the
<<<SQL...SQL
block