diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2017-07-01 09:52:38 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2017-07-01 09:52:38 +0200 |
commit | f808b01692a835673f328d7221ba8c212caa9b61 (patch) | |
tree | 0c3b1fc5b1ddbd7af72227303503177689e1d403 /app/DoctrineMigrations/Version20161001072726.php | |
parent | 822c877949aff8ae57677671115f8f4fc69588d5 (diff) | |
download | wallabag-f808b01692a835673f328d7221ba8c212caa9b61.tar.gz wallabag-f808b01692a835673f328d7221ba8c212caa9b61.tar.zst wallabag-f808b01692a835673f328d7221ba8c212caa9b61.zip |
Add a real configuration for CS-Fixer
Diffstat (limited to 'app/DoctrineMigrations/Version20161001072726.php')
-rw-r--r-- | app/DoctrineMigrations/Version20161001072726.php | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/app/DoctrineMigrations/Version20161001072726.php b/app/DoctrineMigrations/Version20161001072726.php index ad761541..4babe172 100644 --- a/app/DoctrineMigrations/Version20161001072726.php +++ b/app/DoctrineMigrations/Version20161001072726.php | |||
@@ -3,10 +3,10 @@ | |||
3 | namespace Application\Migrations; | 3 | namespace Application\Migrations; |
4 | 4 | ||
5 | use Doctrine\DBAL\Migrations\AbstractMigration; | 5 | use Doctrine\DBAL\Migrations\AbstractMigration; |
6 | use Doctrine\DBAL\Migrations\SkipMigrationException; | ||
6 | use Doctrine\DBAL\Schema\Schema; | 7 | use Doctrine\DBAL\Schema\Schema; |
7 | use Symfony\Component\DependencyInjection\ContainerAwareInterface; | 8 | use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
8 | use Symfony\Component\DependencyInjection\ContainerInterface; | 9 | use Symfony\Component\DependencyInjection\ContainerInterface; |
9 | use Doctrine\DBAL\Migrations\SkipMigrationException; | ||
10 | 10 | ||
11 | /** | 11 | /** |
12 | * Added pocket_consumer_key field on wallabag_config. | 12 | * Added pocket_consumer_key field on wallabag_config. |
@@ -23,17 +23,12 @@ class Version20161001072726 extends AbstractMigration implements ContainerAwareI | |||
23 | $this->container = $container; | 23 | $this->container = $container; |
24 | } | 24 | } |
25 | 25 | ||
26 | private function getTable($tableName) | ||
27 | { | ||
28 | return $this->container->getParameter('database_table_prefix').$tableName; | ||
29 | } | ||
30 | |||
31 | /** | 26 | /** |
32 | * @param Schema $schema | 27 | * @param Schema $schema |
33 | */ | 28 | */ |
34 | public function up(Schema $schema) | 29 | public function up(Schema $schema) |
35 | { | 30 | { |
36 | $this->skipIf($this->connection->getDatabasePlatform()->getName() == 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.'); | 31 | $this->skipIf($this->connection->getDatabasePlatform()->getName() === 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.'); |
37 | 32 | ||
38 | // remove all FK from entry_tag | 33 | // remove all FK from entry_tag |
39 | switch ($this->connection->getDatabasePlatform()->getName()) { | 34 | switch ($this->connection->getDatabasePlatform()->getName()) { |
@@ -41,16 +36,15 @@ class Version20161001072726 extends AbstractMigration implements ContainerAwareI | |||
41 | $query = $this->connection->query(" | 36 | $query = $this->connection->query(" |
42 | SELECT CONSTRAINT_NAME | 37 | SELECT CONSTRAINT_NAME |
43 | FROM information_schema.key_column_usage | 38 | FROM information_schema.key_column_usage |
44 | WHERE TABLE_NAME = '".$this->getTable('entry_tag')."' AND CONSTRAINT_NAME LIKE 'FK_%' | 39 | WHERE TABLE_NAME = '" . $this->getTable('entry_tag') . "' AND CONSTRAINT_NAME LIKE 'FK_%' |
45 | AND TABLE_SCHEMA = '".$this->connection->getDatabase()."'" | 40 | AND TABLE_SCHEMA = '" . $this->connection->getDatabase() . "'" |
46 | ); | 41 | ); |
47 | $query->execute(); | 42 | $query->execute(); |
48 | 43 | ||
49 | foreach ($query->fetchAll() as $fk) { | 44 | foreach ($query->fetchAll() as $fk) { |
50 | $this->addSql('ALTER TABLE '.$this->getTable('entry_tag').' DROP FOREIGN KEY '.$fk['CONSTRAINT_NAME']); | 45 | $this->addSql('ALTER TABLE ' . $this->getTable('entry_tag') . ' DROP FOREIGN KEY ' . $fk['CONSTRAINT_NAME']); |
51 | } | 46 | } |
52 | break; | 47 | break; |
53 | |||
54 | case 'postgresql': | 48 | case 'postgresql': |
55 | // http://dba.stackexchange.com/questions/36979/retrieving-all-pk-and-fk | 49 | // http://dba.stackexchange.com/questions/36979/retrieving-all-pk-and-fk |
56 | $query = $this->connection->query(" | 50 | $query = $this->connection->query(" |
@@ -60,19 +54,19 @@ class Version20161001072726 extends AbstractMigration implements ContainerAwareI | |||
60 | FROM pg_constraint c | 54 | FROM pg_constraint c |
61 | JOIN pg_namespace n ON n.oid = c.connamespace | 55 | JOIN pg_namespace n ON n.oid = c.connamespace |
62 | WHERE contype = 'f' | 56 | WHERE contype = 'f' |
63 | AND conrelid::regclass::text = '".$this->getTable('entry_tag')."' | 57 | AND conrelid::regclass::text = '" . $this->getTable('entry_tag') . "' |
64 | AND n.nspname = 'public';" | 58 | AND n.nspname = 'public';" |
65 | ); | 59 | ); |
66 | $query->execute(); | 60 | $query->execute(); |
67 | 61 | ||
68 | foreach ($query->fetchAll() as $fk) { | 62 | foreach ($query->fetchAll() as $fk) { |
69 | $this->addSql('ALTER TABLE '.$this->getTable('entry_tag').' DROP CONSTRAINT '.$fk['conname']); | 63 | $this->addSql('ALTER TABLE ' . $this->getTable('entry_tag') . ' DROP CONSTRAINT ' . $fk['conname']); |
70 | } | 64 | } |
71 | break; | 65 | break; |
72 | } | 66 | } |
73 | 67 | ||
74 | $this->addSql('ALTER TABLE '.$this->getTable('entry_tag').' ADD CONSTRAINT FK_entry_tag_entry FOREIGN KEY (entry_id) REFERENCES '.$this->getTable('entry').' (id) ON DELETE CASCADE'); | 68 | $this->addSql('ALTER TABLE ' . $this->getTable('entry_tag') . ' ADD CONSTRAINT FK_entry_tag_entry FOREIGN KEY (entry_id) REFERENCES ' . $this->getTable('entry') . ' (id) ON DELETE CASCADE'); |
75 | $this->addSql('ALTER TABLE '.$this->getTable('entry_tag').' ADD CONSTRAINT FK_entry_tag_tag FOREIGN KEY (tag_id) REFERENCES '.$this->getTable('tag').' (id) ON DELETE CASCADE'); | 69 | $this->addSql('ALTER TABLE ' . $this->getTable('entry_tag') . ' ADD CONSTRAINT FK_entry_tag_tag FOREIGN KEY (tag_id) REFERENCES ' . $this->getTable('tag') . ' (id) ON DELETE CASCADE'); |
76 | 70 | ||
77 | // remove entry FK from annotation | 71 | // remove entry FK from annotation |
78 | 72 | ||
@@ -81,18 +75,17 @@ class Version20161001072726 extends AbstractMigration implements ContainerAwareI | |||
81 | $query = $this->connection->query(" | 75 | $query = $this->connection->query(" |
82 | SELECT CONSTRAINT_NAME | 76 | SELECT CONSTRAINT_NAME |
83 | FROM information_schema.key_column_usage | 77 | FROM information_schema.key_column_usage |
84 | WHERE TABLE_NAME = '".$this->getTable('annotation')."' | 78 | WHERE TABLE_NAME = '" . $this->getTable('annotation') . "' |
85 | AND CONSTRAINT_NAME LIKE 'FK_%' | 79 | AND CONSTRAINT_NAME LIKE 'FK_%' |
86 | AND COLUMN_NAME = 'entry_id' | 80 | AND COLUMN_NAME = 'entry_id' |
87 | AND TABLE_SCHEMA = '".$this->connection->getDatabase()."'" | 81 | AND TABLE_SCHEMA = '" . $this->connection->getDatabase() . "'" |
88 | ); | 82 | ); |
89 | $query->execute(); | 83 | $query->execute(); |
90 | 84 | ||
91 | foreach ($query->fetchAll() as $fk) { | 85 | foreach ($query->fetchAll() as $fk) { |
92 | $this->addSql('ALTER TABLE '.$this->getTable('annotation').' DROP FOREIGN KEY '.$fk['CONSTRAINT_NAME']); | 86 | $this->addSql('ALTER TABLE ' . $this->getTable('annotation') . ' DROP FOREIGN KEY ' . $fk['CONSTRAINT_NAME']); |
93 | } | 87 | } |
94 | break; | 88 | break; |
95 | |||
96 | case 'postgresql': | 89 | case 'postgresql': |
97 | // http://dba.stackexchange.com/questions/36979/retrieving-all-pk-and-fk | 90 | // http://dba.stackexchange.com/questions/36979/retrieving-all-pk-and-fk |
98 | $query = $this->connection->query(" | 91 | $query = $this->connection->query(" |
@@ -102,19 +95,19 @@ class Version20161001072726 extends AbstractMigration implements ContainerAwareI | |||
102 | FROM pg_constraint c | 95 | FROM pg_constraint c |
103 | JOIN pg_namespace n ON n.oid = c.connamespace | 96 | JOIN pg_namespace n ON n.oid = c.connamespace |
104 | WHERE contype = 'f' | 97 | WHERE contype = 'f' |
105 | AND conrelid::regclass::text = '".$this->getTable('annotation')."' | 98 | AND conrelid::regclass::text = '" . $this->getTable('annotation') . "' |
106 | AND n.nspname = 'public' | 99 | AND n.nspname = 'public' |
107 | AND pg_get_constraintdef(c.oid) LIKE '%entry_id%';" | 100 | AND pg_get_constraintdef(c.oid) LIKE '%entry_id%';" |
108 | ); | 101 | ); |
109 | $query->execute(); | 102 | $query->execute(); |
110 | 103 | ||
111 | foreach ($query->fetchAll() as $fk) { | 104 | foreach ($query->fetchAll() as $fk) { |
112 | $this->addSql('ALTER TABLE '.$this->getTable('annotation').' DROP CONSTRAINT '.$fk['conname']); | 105 | $this->addSql('ALTER TABLE ' . $this->getTable('annotation') . ' DROP CONSTRAINT ' . $fk['conname']); |
113 | } | 106 | } |
114 | break; | 107 | break; |
115 | } | 108 | } |
116 | 109 | ||
117 | $this->addSql('ALTER TABLE '.$this->getTable('annotation').' ADD CONSTRAINT FK_annotation_entry FOREIGN KEY (entry_id) REFERENCES '.$this->getTable('entry').' (id) ON DELETE CASCADE'); | 110 | $this->addSql('ALTER TABLE ' . $this->getTable('annotation') . ' ADD CONSTRAINT FK_annotation_entry FOREIGN KEY (entry_id) REFERENCES ' . $this->getTable('entry') . ' (id) ON DELETE CASCADE'); |
118 | } | 111 | } |
119 | 112 | ||
120 | /** | 113 | /** |
@@ -124,4 +117,9 @@ class Version20161001072726 extends AbstractMigration implements ContainerAwareI | |||
124 | { | 117 | { |
125 | throw new SkipMigrationException('Too complex ...'); | 118 | throw new SkipMigrationException('Too complex ...'); |
126 | } | 119 | } |
120 | |||
121 | private function getTable($tableName) | ||
122 | { | ||
123 | return $this->container->getParameter('database_table_prefix') . $tableName; | ||
124 | } | ||
127 | } | 125 | } |