Added dropColumn for SQLite and some enhancements

This commit is contained in:
Nicolas Lœuillet 2016-11-26 15:40:42 +01:00
parent a4d55a9161
commit 84c6a48df4
6 changed files with 37 additions and 35 deletions

View file

@ -29,12 +29,18 @@ class Version20161024212538 extends AbstractMigration implements ContainerAwareI
*/ */
public function up(Schema $schema) public function up(Schema $schema)
{ {
$this->skipIf($this->connection->getDatabasePlatform()->getName() == 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.'); $clientsTable = $schema->getTable($this->getTable('oauth2_clients'));
$this->skipIf($schema->getTable($this->getTable('oauth2_clients'))->hasColumn('user_id'), 'It seems that you already played this migration.'); $this->skipIf($clientsTable->hasColumn('user_id'), 'It seems that you already played this migration.');
$this->addSql('ALTER TABLE '.$this->getTable('oauth2_clients').' ADD user_id INT(11) DEFAULT NULL'); $clientsTable->addColumn('user_id', 'integer');
$this->addSql('ALTER TABLE '.$this->getTable('oauth2_clients').' ADD CONSTRAINT FK_clients_user_clients FOREIGN KEY (user_id) REFERENCES '.$this->getTable('user').' (id) ON DELETE CASCADE');
$clientsTable->addForeignKeyConstraint(
$this->getTable('user'),
array('user_id'),
array('id'),
array('onDelete' => 'CASCADE')
);
} }
/** /**

View file

@ -37,8 +37,6 @@ class Version20161031132655 extends AbstractMigration implements ContainerAwareI
*/ */
public function down(Schema $schema) public function down(Schema $schema)
{ {
$this->skipIf($this->connection->getDatabasePlatform()->getName() == 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.');
$this->addSql('DELETE FROM "'.$this->getTable('craue_config_setting')."\" WHERE name = 'download_images_enabled';"); $this->addSql('DELETE FROM "'.$this->getTable('craue_config_setting')."\" WHERE name = 'download_images_enabled';");
} }
} }

View file

@ -29,18 +29,8 @@ class Version20161104073720 extends AbstractMigration implements ContainerAwareI
*/ */
public function up(Schema $schema) public function up(Schema $schema)
{ {
switch ($this->connection->getDatabasePlatform()->getName()) { $entryTable = $schema->getTable($this->getTable('entry'));
case 'sqlite': $entryTable->addIndex(['created_at']);
$this->addSql('CREATE INDEX `created_at` ON `'.$this->getTable('entry').'` (`created_at` DESC)');
break;
case 'mysql':
$this->addSql('ALTER TABLE '.$this->getTable('entry').' ADD INDEX created_at (created_at);');
break;
case 'postgresql':
$this->addSql('CREATE INDEX created_at ON '.$this->getTable('entry').' (created_at DESC)');
}
} }
/** /**

View file

@ -29,9 +29,13 @@ class Version20161106113822 extends AbstractMigration implements ContainerAwareI
*/ */
public function up(Schema $schema) public function up(Schema $schema)
{ {
$this->skipIf($schema->getTable($this->getTable('config'))->hasColumn('action_mark_as_read'), 'It seems that you already played this migration.'); $configTable = $schema->getTable($this->getTable('config'));
$this->addSql('ALTER TABLE '.$this->getTable('config').' ADD action_mark_as_read INT DEFAULT 0'); $this->skipIf($configTable->hasColumn('action_mark_as_read'), 'It seems that you already played this migration.');
$configTable->addColumn('action_mark_as_read', 'integer', [
'default' => 0,
]);
} }
/** /**
@ -39,8 +43,7 @@ class Version20161106113822 extends AbstractMigration implements ContainerAwareI
*/ */
public function down(Schema $schema) public function down(Schema $schema)
{ {
$this->skipIf($this->connection->getDatabasePlatform()->getName() != 'sqlite', 'This down migration can\'t be executed on SQLite databases, because SQLite don\'t support DROP COLUMN.'); $configTable = $schema->getTable($this->getTable('config'));
$userTable->dropColumn('action_mark_as_read');
$this->addSql('ALTER TABLE '.$this->getTable('config').' DROP action_mark_as_read');
} }
} }

View file

@ -32,9 +32,14 @@ class Version20161118134328 extends AbstractMigration implements ContainerAwareI
*/ */
public function up(Schema $schema) public function up(Schema $schema)
{ {
$this->skipIf($schema->getTable($this->getTable('entry'))->hasColumn('http_status'), 'It seems that you already played this migration.'); $entryTable = $schema->getTable($this->getTable('entry'));
$this->addSql('ALTER TABLE '.$this->getTable('entry').' ADD http_status VARCHAR(3) DEFAULT NULL'); $this->skipIf($entryTable->hasColumn('http_status'), 'It seems that you already played this migration.');
$entryTable->addColumn('http_status', 'string', [
'length' => 3,
'notnull' => false,
]);
} }
/** /**
@ -42,8 +47,7 @@ class Version20161118134328 extends AbstractMigration implements ContainerAwareI
*/ */
public function down(Schema $schema) public function down(Schema $schema)
{ {
$this->skipIf($this->connection->getDatabasePlatform()->getName() != 'sqlite', 'This down migration can\'t be executed on SQLite databases, because SQLite don\'t support DROP COLUMN.'); $userTable = $schema->getTable($this->getTable('entry'));
$userTable->dropColumn('http_status');
$this->addSql('ALTER TABLE '.$this->getTable('entry').' DROP http_status');
} }
} }

View file

@ -40,15 +40,15 @@ class Version20161122203647 extends AbstractMigration implements ContainerAwareI
*/ */
public function up(Schema $schema) public function up(Schema $schema)
{ {
$this->skipIf($this->connection->getDatabasePlatform()->getName() === 'sqlite', 'This up migration can\'t be executed on SQLite databases, because SQLite don\'t support DROP COLUMN.'); $userTable = $schema->getTable($this->getTable('user'));
$this->skipIf(false === $schema->getTable($this->getTable('user'))->hasColumn('expired'), 'It seems that you already played this migration.'); $this->skipIf(false === $userTable->hasColumn('expired'), 'It seems that you already played this migration.');
$this->addSql('ALTER TABLE '.$this->getTable('user').' DROP expired'); $userTable->dropColumn('expired');
$this->skipIf(false === $schema->getTable($this->getTable('user'))->hasColumn('credentials_expired'), 'It seems that you already played this migration.'); $this->skipIf(false === $userTable->hasColumn('credentials_expired'), 'It seems that you already played this migration.');
$this->addSql('ALTER TABLE '.$this->getTable('user').' DROP credentials_expired'); $userTable->dropColumn('credentials_expired');
} }
/** /**
@ -56,7 +56,8 @@ class Version20161122203647 extends AbstractMigration implements ContainerAwareI
*/ */
public function down(Schema $schema) public function down(Schema $schema)
{ {
$this->addSql('ALTER TABLE '.$this->getTable('user').' ADD expired tinyint(1) NULL DEFAULT 0'); $userTable = $schema->getTable($this->getTable('user'));
$this->addSql('ALTER TABLE '.$this->getTable('user').' ADD credentials_expired tinyint(1) NULL DEFAULT 0'); $userTable->addColumn('expired', 'smallint');
$userTable->addColumn('credentials_expired', 'smallint');
} }
} }