diff options
author | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2016-10-24 11:57:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-24 11:57:51 +0200 |
commit | 9313ea9d440e3f93a6bb2d8c0fb6717364cd27f5 (patch) | |
tree | 659842576e853a536c67e7c74139a73853b6caf2 /app/DoctrineMigrations/Version20161001072726.php | |
parent | a1c18418288a9521c980c96fd5defffc757a81c6 (diff) | |
parent | f623516e107c8146f87d815f033cecb5d812466a (diff) | |
download | wallabag-9313ea9d440e3f93a6bb2d8c0fb6717364cd27f5.tar.gz wallabag-9313ea9d440e3f93a6bb2d8c0fb6717364cd27f5.tar.zst wallabag-9313ea9d440e3f93a6bb2d8c0fb6717364cd27f5.zip |
Merge pull request #2401 from wallabag/reset-account
Reset account
Diffstat (limited to 'app/DoctrineMigrations/Version20161001072726.php')
-rw-r--r-- | app/DoctrineMigrations/Version20161001072726.php | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/app/DoctrineMigrations/Version20161001072726.php b/app/DoctrineMigrations/Version20161001072726.php new file mode 100644 index 00000000..237db932 --- /dev/null +++ b/app/DoctrineMigrations/Version20161001072726.php | |||
@@ -0,0 +1,63 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Application\Migrations; | ||
4 | |||
5 | use Doctrine\DBAL\Migrations\AbstractMigration; | ||
6 | use Doctrine\DBAL\Schema\Schema; | ||
7 | use Symfony\Component\DependencyInjection\ContainerAwareInterface; | ||
8 | use Symfony\Component\DependencyInjection\ContainerInterface; | ||
9 | |||
10 | class Version20161001072726 extends AbstractMigration implements ContainerAwareInterface | ||
11 | { | ||
12 | /** | ||
13 | * @var ContainerInterface | ||
14 | */ | ||
15 | private $container; | ||
16 | |||
17 | public function setContainer(ContainerInterface $container = null) | ||
18 | { | ||
19 | $this->container = $container; | ||
20 | } | ||
21 | |||
22 | private function getTable($tableName) | ||
23 | { | ||
24 | return $this->container->getParameter('database_table_prefix') . $tableName; | ||
25 | } | ||
26 | |||
27 | /** | ||
28 | * @param Schema $schema | ||
29 | */ | ||
30 | public function up(Schema $schema) | ||
31 | { | ||
32 | $this->skipIf($this->connection->getDatabasePlatform()->getName() == 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.'); | ||
33 | |||
34 | // remove all FK from entry_tag | ||
35 | $query = $this->connection->query("SELECT CONSTRAINT_NAME FROM information_schema.key_column_usage WHERE TABLE_NAME = '".$this->getTable('entry_tag')."' AND CONSTRAINT_NAME LIKE 'FK_%' AND TABLE_SCHEMA = '".$this->connection->getDatabase()."'"); | ||
36 | $query->execute(); | ||
37 | |||
38 | foreach ($query->fetchAll() as $fk) { | ||
39 | $this->addSql('ALTER TABLE '.$this->getTable('entry_tag').' DROP FOREIGN KEY '.$fk['CONSTRAINT_NAME']); | ||
40 | } | ||
41 | |||
42 | $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'); | ||
43 | $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'); | ||
44 | |||
45 | // remove entry FK from annotation | ||
46 | $query = $this->connection->query("SELECT CONSTRAINT_NAME FROM information_schema.key_column_usage WHERE TABLE_NAME = '".$this->getTable('annotation')."' AND CONSTRAINT_NAME LIKE 'FK_%' and COLUMN_NAME = 'entry_id' AND TABLE_SCHEMA = '".$this->connection->getDatabase()."'"); | ||
47 | $query->execute(); | ||
48 | |||
49 | foreach ($query->fetchAll() as $fk) { | ||
50 | $this->addSql('ALTER TABLE '.$this->getTable('annotation').' DROP FOREIGN KEY '.$fk['CONSTRAINT_NAME']); | ||
51 | } | ||
52 | |||
53 | $this->addSql('ALTER TABLE '.$this->getTable('annotation').' ADD CONSTRAINT FK_annotation_entry FOREIGN KEY (entry_id) REFERENCES '.$this->getTable('entry').' (id) ON DELETE CASCADE'); | ||
54 | } | ||
55 | |||
56 | /** | ||
57 | * @param Schema $schema | ||
58 | */ | ||
59 | public function down(Schema $schema) | ||
60 | { | ||
61 | throw new SkipMigrationException('Too complex ...'); | ||
62 | } | ||
63 | } | ||