aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/DoctrineMigrations/Version20170501115751.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2017-05-02 08:38:22 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2017-06-20 16:03:20 +0200
commitfd7fde95159828960784a438c4b4da147e20ab18 (patch)
tree5b113a3eca7a3d194eee9b45a3017f62c7659c00 /app/DoctrineMigrations/Version20170501115751.php
parentb8427f22f06cab58383ec3080f09715c712c65ef (diff)
downloadwallabag-fd7fde95159828960784a438c4b4da147e20ab18.tar.gz
wallabag-fd7fde95159828960784a438c4b4da147e20ab18.tar.zst
wallabag-fd7fde95159828960784a438c4b4da147e20ab18.zip
Force sequence creation for postgresql
Diffstat (limited to 'app/DoctrineMigrations/Version20170501115751.php')
-rw-r--r--app/DoctrineMigrations/Version20170501115751.php61
1 files changed, 61 insertions, 0 deletions
diff --git a/app/DoctrineMigrations/Version20170501115751.php b/app/DoctrineMigrations/Version20170501115751.php
new file mode 100644
index 00000000..846a87b5
--- /dev/null
+++ b/app/DoctrineMigrations/Version20170501115751.php
@@ -0,0 +1,61 @@
1<?php
2
3namespace Application\Migrations;
4
5use Doctrine\DBAL\Migrations\AbstractMigration;
6use Doctrine\DBAL\Schema\Schema;
7use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8use Symfony\Component\DependencyInjection\ContainerInterface;
9
10/**
11 * Add site credential table to store username & password for some website (behind authentication or paywall)
12 */
13class Version20170501115751 extends AbstractMigration implements ContainerAwareInterface
14{
15 /**
16 * @var ContainerInterface
17 */
18 private $container;
19
20 public function setContainer(ContainerInterface $container = null)
21 {
22 $this->container = $container;
23 }
24
25 private function getTable($tableName)
26 {
27 return $this->container->getParameter('database_table_prefix').$tableName;
28 }
29
30 /**
31 * @param Schema $schema
32 */
33 public function up(Schema $schema)
34 {
35 $this->skipIf($schema->hasTable($this->getTable('site_credential')), 'It seems that you already played this migration.');
36
37 $table = $schema->createTable($this->getTable('site_credential'));
38 $table->addColumn('id', 'integer', ['autoincrement' => true]);
39 $table->addColumn('user_id', 'integer');
40 $table->addColumn('host', 'string', ['length' => 255]);
41 $table->addColumn('username', 'string', ['length' => 255]);
42 $table->addColumn('password', 'string', ['length' => 255]);
43 $table->addColumn('createdAt', 'datetime');
44 $table->addIndex(['user_id'], 'idx_user');
45 $table->setPrimaryKey(['id']);
46 $table->addForeignKeyConstraint($this->getTable('user'), ['user_id'], ['id'], [], 'fk_user');
47
48 if ('postgresql' === $this->connection->getDatabasePlatform()->getName()) {
49 $schema->dropSequence('site_credential_id_seq');
50 $schema->createSequence('site_credential_id_seq');
51 }
52 }
53
54 /**
55 * @param Schema $schema
56 */
57 public function down(Schema $schema)
58 {
59 $schema->dropTable($this->getTable('site_credential'));
60 }
61}