aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/DoctrineMigrations/Version20160410190541.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/DoctrineMigrations/Version20160410190541.php')
-rw-r--r--app/DoctrineMigrations/Version20160410190541.php33
1 files changed, 23 insertions, 10 deletions
diff --git a/app/DoctrineMigrations/Version20160410190541.php b/app/DoctrineMigrations/Version20160410190541.php
index f034b0e4..6294d842 100644
--- a/app/DoctrineMigrations/Version20160410190541.php
+++ b/app/DoctrineMigrations/Version20160410190541.php
@@ -7,6 +7,9 @@ use Doctrine\DBAL\Schema\Schema;
7use Symfony\Component\DependencyInjection\ContainerAwareInterface; 7use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8use Symfony\Component\DependencyInjection\ContainerInterface; 8use Symfony\Component\DependencyInjection\ContainerInterface;
9 9
10/**
11 * Added foreign keys for account resetting
12 */
10class Version20160410190541 extends AbstractMigration implements ContainerAwareInterface 13class Version20160410190541 extends AbstractMigration implements ContainerAwareInterface
11{ 14{
12 /** 15 /**
@@ -21,7 +24,7 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI
21 24
22 private function getTable($tableName) 25 private function getTable($tableName)
23 { 26 {
24 return $this->container->getParameter('database_table_prefix') . $tableName; 27 return $this->container->getParameter('database_table_prefix').$tableName;
25 } 28 }
26 29
27 /** 30 /**
@@ -29,13 +32,23 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI
29 */ 32 */
30 public function up(Schema $schema) 33 public function up(Schema $schema)
31 { 34 {
32 if ($this->connection->getDatabasePlatform()->getName() == 'postgresql') { 35 $entryTable = $schema->getTable($this->getTable('entry'));
33 $this->addSql('ALTER TABLE "'.$this->getTable('entry').'" ADD uuid UUID DEFAULT NULL'); 36
34 } else { 37 $this->skipIf($entryTable->hasColumn('uid') || $entryTable->hasColumn('uuid'), 'It seems that you already played this migration.');
35 $this->addSql('ALTER TABLE "'.$this->getTable('entry').'" ADD uuid LONGTEXT DEFAULT NULL'); 38
36 } 39 $entryTable->addColumn('uid', 'string', [
40 'notnull' => false,
41 'length' => 23,
42 ]);
37 43
38 $this->addSql("INSERT INTO \"".$this->getTable('craue_config_setting')."\" (name, value, section) VALUES ('share_public', '1', 'entry')"); 44 $sharePublic = $this->container
45 ->get('doctrine.orm.default_entity_manager')
46 ->getConnection()
47 ->fetchArray('SELECT * FROM '.$this->getTable('craue_config_setting')." WHERE name = 'share_public'");
48
49 if (false === $sharePublic) {
50 $this->addSql('INSERT INTO '.$this->getTable('craue_config_setting')." (name, value, section) VALUES ('share_public', '1', 'entry')");
51 }
39 } 52 }
40 53
41 /** 54 /**
@@ -43,9 +56,9 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI
43 */ 56 */
44 public function down(Schema $schema) 57 public function down(Schema $schema)
45 { 58 {
46 $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'sqlite', 'This down migration can\'t be executed on SQLite databases, because SQLite don\'t support DROP COLUMN.'); 59 $entryTable = $schema->getTable($this->getTable('entry'));
60 $entryTable->dropColumn('uid');
47 61
48 $this->addSql('ALTER TABLE "'.$this->getTable('entry').'" DROP uuid'); 62 $this->addSql('DELETE FROM '.$this->getTable('craue_config_setting')." WHERE name = 'share_public'");
49 $this->addSql("DELETE FROM \"".$this->getTable('craue_config_setting')."\" WHERE name = 'share_public'");
50 } 63 }
51} 64}