3 namespace Application\Migrations
;
5 use Doctrine\DBAL\Migrations\AbstractMigration
;
6 use Doctrine\DBAL\Schema\Schema
;
7 use Symfony\Component\DependencyInjection\ContainerAwareInterface
;
8 use Symfony\Component\DependencyInjection\ContainerInterface
;
11 * Add site credential table to store username & password for some website (behind authentication or paywall)
13 class Version20170501115751
extends AbstractMigration
implements ContainerAwareInterface
16 * @var ContainerInterface
20 public function setContainer(ContainerInterface
$container = null)
22 $this->container
= $container;
25 private function getTable($tableName)
27 return $this->container
->getParameter('database_table_prefix').$tableName;
31 * @param Schema $schema
33 public function up(Schema
$schema)
35 $this->skipIf($schema->hasTable($this->getTable('site_credential')), 'It seems that you already played this migration.');
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', 'text');
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');
48 if ('postgresql' === $this->connection
->getDatabasePlatform()->getName()) {
49 $schema->dropSequence('site_credential_id_seq');
50 $schema->createSequence('site_credential_id_seq');
55 * @param Schema $schema
57 public function down(Schema
$schema)
59 $schema->dropTable($this->getTable('site_credential'));