aboutsummaryrefslogtreecommitdiffhomepage
path: root/app
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2017-12-12 11:10:21 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2017-12-12 11:17:16 +0100
commit43e1711eb66a55e954bcffa2f37fd30c1b3b1fae (patch)
tree276c2a67749533631644233dc7111788aa431218 /app
parentf209798368de66b4acd8b892fe71018ebb30c2da (diff)
downloadwallabag-43e1711eb66a55e954bcffa2f37fd30c1b3b1fae.tar.gz
wallabag-43e1711eb66a55e954bcffa2f37fd30c1b3b1fae.tar.zst
wallabag-43e1711eb66a55e954bcffa2f37fd30c1b3b1fae.zip
Change the way to check for initial migration
Diffstat (limited to 'app')
-rw-r--r--app/DoctrineMigrations/Version20160401000000.php29
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
5use Doctrine\DBAL\Migrations\AbstractMigration; 5use Doctrine\DBAL\Migrations\AbstractMigration;
6use Doctrine\DBAL\Schema\Schema; 6use Doctrine\DBAL\Schema\Schema;
7use Doctrine\DBAL\Schema\SchemaException;
8use Symfony\Component\DependencyInjection\ContainerAwareInterface;
9use Symfony\Component\DependencyInjection\ContainerInterface;
7 10
8/** 11/**
9 * Initial database structure. 12 * Initial database structure.
10 */ 13 */
11class Version20160401000000 extends AbstractMigration 14class 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
160ALTER TABLE wallabag_oauth2_auth_codes ADD CONSTRAINT FK_EE52E3FA19EB6921 FOREIGN KEY (client_id) REFERENCES wallabag_oauth2_clients (id) NOT DEFERRABLE INITIALLY IMMEDIATE; 176ALTER TABLE wallabag_oauth2_auth_codes ADD CONSTRAINT FK_EE52E3FA19EB6921 FOREIGN KEY (client_id) REFERENCES wallabag_oauth2_clients (id) NOT DEFERRABLE INITIALLY IMMEDIATE;
161ALTER TABLE wallabag_oauth2_auth_codes ADD CONSTRAINT FK_EE52E3FAA76ED395 FOREIGN KEY (user_id) REFERENCES "wallabag_user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE; 177ALTER TABLE wallabag_oauth2_auth_codes ADD CONSTRAINT FK_EE52E3FAA76ED395 FOREIGN KEY (user_id) REFERENCES "wallabag_user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE;
162ALTER TABLE wallabag_annotation ADD CONSTRAINT FK_A7AED006A76ED395 FOREIGN KEY (user_id) REFERENCES "wallabag_user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE; 178ALTER TABLE wallabag_annotation ADD CONSTRAINT FK_A7AED006A76ED395 FOREIGN KEY (user_id) REFERENCES "wallabag_user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE;
163ALTER TABLE wallabag_annotation ADD CONSTRAINT FK_A7AED006BA364942 FOREIGN KEY (entry_id) REFERENCES "wallabag_entry" (id) NOT DEFERRABLE INITIALLY IMMEDIATE; 179ALTER TABLE wallabag_annotation ADD CONSTRAINT FK_A7AED006BA364942 FOREIGN KEY (entry_id) REFERENCES "wallabag_entry" (id) NOT DEFERRABLE INITIALLY IMMEDIATE;
164SQL 180SQL
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}