aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/DoctrineMigrations
diff options
context:
space:
mode:
Diffstat (limited to 'app/DoctrineMigrations')
-rw-r--r--app/DoctrineMigrations/Version20170623092923.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/app/DoctrineMigrations/Version20170623092923.php b/app/DoctrineMigrations/Version20170623092923.php
new file mode 100644
index 00000000..5c6eafa7
--- /dev/null
+++ b/app/DoctrineMigrations/Version20170623092923.php
@@ -0,0 +1,63 @@
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 Notifications table
12 */
13class Version20170623092923 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('notification')), 'It seems that you already played this migration.');
36
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');
49
50 if ('postgresql' === $this->connection->getDatabasePlatform()->getName()) {
51 $schema->dropSequence('notification_id_seq');
52 $schema->createSequence('notification_id_seq');
53 }
54 }
55
56 /**
57 * @param Schema $schema
58 */
59 public function down(Schema $schema)
60 {
61 $schema->dropTable($this->getTable('notification'));
62 }
63}