]>
Commit | Line | Data |
---|---|---|
f92fcb53 JB |
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 | /** | |
f808b016 | 11 | * Add site credential table to store username & password for some website (behind authentication or paywall). |
f92fcb53 | 12 | */ |
fd7fde95 | 13 | class Version20170501115751 extends AbstractMigration implements ContainerAwareInterface |
f92fcb53 JB |
14 | { |
15 | /** | |
16 | * @var ContainerInterface | |
17 | */ | |
18 | private $container; | |
19 | ||
20 | public function setContainer(ContainerInterface $container = null) | |
21 | { | |
22 | $this->container = $container; | |
23 | } | |
24 | ||
f92fcb53 JB |
25 | /** |
26 | * @param Schema $schema | |
27 | */ | |
28 | public function up(Schema $schema) | |
29 | { | |
30 | $this->skipIf($schema->hasTable($this->getTable('site_credential')), 'It seems that you already played this migration.'); | |
31 | ||
32 | $table = $schema->createTable($this->getTable('site_credential')); | |
33 | $table->addColumn('id', 'integer', ['autoincrement' => true]); | |
34 | $table->addColumn('user_id', 'integer'); | |
35 | $table->addColumn('host', 'string', ['length' => 255]); | |
bead8b42 | 36 | $table->addColumn('username', 'text'); |
906424c1 | 37 | $table->addColumn('password', 'text'); |
f92fcb53 JB |
38 | $table->addColumn('createdAt', 'datetime'); |
39 | $table->addIndex(['user_id'], 'idx_user'); | |
40 | $table->setPrimaryKey(['id']); | |
41 | $table->addForeignKeyConstraint($this->getTable('user'), ['user_id'], ['id'], [], 'fk_user'); | |
fd7fde95 JB |
42 | |
43 | if ('postgresql' === $this->connection->getDatabasePlatform()->getName()) { | |
44 | $schema->dropSequence('site_credential_id_seq'); | |
45 | $schema->createSequence('site_credential_id_seq'); | |
46 | } | |
f92fcb53 JB |
47 | } |
48 | ||
49 | /** | |
50 | * @param Schema $schema | |
51 | */ | |
52 | public function down(Schema $schema) | |
53 | { | |
54 | $schema->dropTable($this->getTable('site_credential')); | |
55 | } | |
f808b016 JB |
56 | |
57 | private function getTable($tableName) | |
58 | { | |
59 | return $this->container->getParameter('database_table_prefix') . $tableName; | |
60 | } | |
f92fcb53 | 61 | } |