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 Notifications table
13 class Version20170623092923
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('notification')), 'It seems that you already played this migration.');
37 $table = $schema->createTable($this->getTable('notification'));
38 $table->addColumn('id', 'integer', ['autoincrement' => true]);
39 $table->addColumn('user_id', 'integer');
40 $table->addColumn('timestamp', 'datetime');
41 $table->addColumn('title', 'text');
42 $table->addColumn('description', 'text');
43 $table->addColumn('read', 'boolean');
44 $table->addColumn('actions', 'text');
45 $table->addColumn('parameter', 'text');
46 $table->addIndex(['user_id'], 'idx_user');
47 $table->setPrimaryKey(['id']);
48 $table->addForeignKeyConstraint($this->getTable('user'), ['user_id'], ['id'], [], 'fk_user_notification');
50 if ('postgresql' === $this->connection
->getDatabasePlatform()->getName()) {
51 $schema->dropSequence('notification_id_seq');
52 $schema->createSequence('notification_id_seq');
57 * @param Schema $schema
59 public function down(Schema
$schema)
61 $schema->dropTable($this->getTable('notification'));