diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/DoctrineMigrations/Version20160401000000.php | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/app/DoctrineMigrations/Version20160401000000.php b/app/DoctrineMigrations/Version20160401000000.php index a8603abf..54bfb0f0 100644 --- a/app/DoctrineMigrations/Version20160401000000.php +++ b/app/DoctrineMigrations/Version20160401000000.php | |||
@@ -4,20 +4,36 @@ namespace Application\Migrations; | |||
4 | 4 | ||
5 | use Doctrine\DBAL\Migrations\AbstractMigration; | 5 | use Doctrine\DBAL\Migrations\AbstractMigration; |
6 | use Doctrine\DBAL\Schema\Schema; | 6 | use Doctrine\DBAL\Schema\Schema; |
7 | use Doctrine\DBAL\Schema\SchemaException; | ||
8 | use Symfony\Component\DependencyInjection\ContainerAwareInterface; | ||
9 | use Symfony\Component\DependencyInjection\ContainerInterface; | ||
7 | 10 | ||
8 | /** | 11 | /** |
9 | * Initial database structure. | 12 | * Initial database structure. |
10 | */ | 13 | */ |
11 | class Version20160401000000 extends AbstractMigration | 14 | class Version20160401000000 extends AbstractMigration implements ContainerAwareInterface |
12 | { | 15 | { |
13 | /** | 16 | /** |
17 | * @var ContainerInterface | ||
18 | */ | ||
19 | private $container; | ||
20 | |||
21 | public function setContainer(ContainerInterface $container = null) | ||
22 | { | ||
23 | $this->container = $container; | ||
24 | } | ||
25 | |||
26 | /** | ||
14 | * @param Schema $schema | 27 | * @param Schema $schema |
15 | */ | 28 | */ |
16 | public function up(Schema $schema) | 29 | public function up(Schema $schema) |
17 | { | 30 | { |
18 | if ($this->version->getConfiguration()->getNumberOfExecutedMigrations() > 0) { | 31 | try { |
19 | $this->version->markMigrated(); | 32 | $schema->getTable($this->getTable('entry')); |
33 | |||
20 | $this->skipIf(true, 'Database already initialized'); | 34 | $this->skipIf(true, 'Database already initialized'); |
35 | } catch (SchemaException $e) { | ||
36 | // it's ok, the table does not exist we can proceed to the initial migration | ||
21 | } | 37 | } |
22 | 38 | ||
23 | switch ($this->connection->getDatabasePlatform()->getName()) { | 39 | switch ($this->connection->getDatabasePlatform()->getName()) { |
@@ -160,7 +176,7 @@ ALTER TABLE wallabag_oauth2_refresh_tokens ADD CONSTRAINT FK_20C9FB24A76ED395 FO | |||
160 | ALTER TABLE wallabag_oauth2_auth_codes ADD CONSTRAINT FK_EE52E3FA19EB6921 FOREIGN KEY (client_id) REFERENCES wallabag_oauth2_clients (id) NOT DEFERRABLE INITIALLY IMMEDIATE; | 176 | ALTER TABLE wallabag_oauth2_auth_codes ADD CONSTRAINT FK_EE52E3FA19EB6921 FOREIGN KEY (client_id) REFERENCES wallabag_oauth2_clients (id) NOT DEFERRABLE INITIALLY IMMEDIATE; |
161 | ALTER TABLE wallabag_oauth2_auth_codes ADD CONSTRAINT FK_EE52E3FAA76ED395 FOREIGN KEY (user_id) REFERENCES "wallabag_user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE; | 177 | ALTER TABLE wallabag_oauth2_auth_codes ADD CONSTRAINT FK_EE52E3FAA76ED395 FOREIGN KEY (user_id) REFERENCES "wallabag_user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE; |
162 | ALTER TABLE wallabag_annotation ADD CONSTRAINT FK_A7AED006A76ED395 FOREIGN KEY (user_id) REFERENCES "wallabag_user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE; | 178 | ALTER TABLE wallabag_annotation ADD CONSTRAINT FK_A7AED006A76ED395 FOREIGN KEY (user_id) REFERENCES "wallabag_user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE; |
163 | ALTER TABLE wallabag_annotation ADD CONSTRAINT FK_A7AED006BA364942 FOREIGN KEY (entry_id) REFERENCES "wallabag_entry" (id) NOT DEFERRABLE INITIALLY IMMEDIATE; | 179 | ALTER TABLE wallabag_annotation ADD CONSTRAINT FK_A7AED006BA364942 FOREIGN KEY (entry_id) REFERENCES "wallabag_entry" (id) NOT DEFERRABLE INITIALLY IMMEDIATE; |
164 | SQL | 180 | SQL |
165 | ; | 181 | ; |
166 | foreach (explode("\n", $sql) as $query) { | 182 | foreach (explode("\n", $sql) as $query) { |
@@ -188,4 +204,9 @@ SQL | |||
188 | $this->addSql('DROP TABLE "wallabag_user"'); | 204 | $this->addSql('DROP TABLE "wallabag_user"'); |
189 | $this->addSql('DROP TABLE wallabag_annotation'); | 205 | $this->addSql('DROP TABLE wallabag_annotation'); |
190 | } | 206 | } |
207 | |||
208 | private function getTable($tableName) | ||
209 | { | ||
210 | return $this->container->getParameter('database_table_prefix') . $tableName; | ||
211 | } | ||
191 | } | 212 | } |