From: Nicolas LÅ“uillet Date: Tue, 12 Dec 2017 19:20:31 +0000 (+0100) Subject: Merge pull request #3487 from wallabag/initial-migration X-Git-Tag: 2.3.1~18 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=1f198256edd057abe110687e5049c0a904eb3c17;hp=f209798368de66b4acd8b892fe71018ebb30c2da;p=github%2Fwallabag%2Fwallabag.git Merge pull request #3487 from wallabag/initial-migration Change the way to check for initial migration --- diff --git a/app/DoctrineMigrations/Version20160401000000.php b/app/DoctrineMigrations/Version20160401000000.php index a8603abf..a88d2dc0 100644 --- a/app/DoctrineMigrations/Version20160401000000.php +++ b/app/DoctrineMigrations/Version20160401000000.php @@ -4,21 +4,30 @@ namespace Application\Migrations; use Doctrine\DBAL\Migrations\AbstractMigration; use Doctrine\DBAL\Schema\Schema; +use Symfony\Component\DependencyInjection\ContainerAwareInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Initial database structure. */ -class Version20160401000000 extends AbstractMigration +class Version20160401000000 extends AbstractMigration implements ContainerAwareInterface { + /** + * @var ContainerInterface + */ + private $container; + + public function setContainer(ContainerInterface $container = null) + { + $this->container = $container; + } + /** * @param Schema $schema */ public function up(Schema $schema) { - if ($this->version->getConfiguration()->getNumberOfExecutedMigrations() > 0) { - $this->version->markMigrated(); - $this->skipIf(true, 'Database already initialized'); - } + $this->skipIf($schema->hasTable($this->getTable('entry')), 'Database already initialized'); switch ($this->connection->getDatabasePlatform()->getName()) { case 'sqlite': @@ -160,7 +169,7 @@ ALTER TABLE wallabag_oauth2_refresh_tokens ADD CONSTRAINT FK_20C9FB24A76ED395 FO ALTER TABLE wallabag_oauth2_auth_codes ADD CONSTRAINT FK_EE52E3FA19EB6921 FOREIGN KEY (client_id) REFERENCES wallabag_oauth2_clients (id) NOT DEFERRABLE INITIALLY IMMEDIATE; ALTER TABLE wallabag_oauth2_auth_codes ADD CONSTRAINT FK_EE52E3FAA76ED395 FOREIGN KEY (user_id) REFERENCES "wallabag_user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE; ALTER TABLE wallabag_annotation ADD CONSTRAINT FK_A7AED006A76ED395 FOREIGN KEY (user_id) REFERENCES "wallabag_user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE; -ALTER TABLE wallabag_annotation ADD CONSTRAINT FK_A7AED006BA364942 FOREIGN KEY (entry_id) REFERENCES "wallabag_entry" (id) NOT DEFERRABLE INITIALLY IMMEDIATE; +ALTER TABLE wallabag_annotation ADD CONSTRAINT FK_A7AED006BA364942 FOREIGN KEY (entry_id) REFERENCES "wallabag_entry" (id) NOT DEFERRABLE INITIALLY IMMEDIATE; SQL ; foreach (explode("\n", $sql) as $query) { @@ -188,4 +197,9 @@ SQL $this->addSql('DROP TABLE "wallabag_user"'); $this->addSql('DROP TABLE wallabag_annotation'); } + + private function getTable($tableName) + { + return $this->container->getParameter('database_table_prefix') . $tableName; + } }