Completed
Pull Request — master (#384)
by Kristof
08:53
created

SchemaConfigurator::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
c 0
b 0
f 0
rs 9.408
cc 1
nc 1
nop 1
1
<?php
2
3
namespace CultuurNet\UDB3\MyOrganizers\ReadModel\Doctrine;
4
5
use CultuurNet\UDB3\Doctrine\DBAL\SchemaConfiguratorInterface;
6
use Doctrine\DBAL\Schema\AbstractSchemaManager;
7
use ValueObjects\StringLiteral\StringLiteral;
8
9
class SchemaConfigurator implements SchemaConfiguratorInterface
10
{
11
    /**
12
     * @var StringLiteral
13
     */
14
    protected $tableName;
15
16
    /**
17
     * @param StringLiteral $tableName
18
     */
19
    public function __construct(StringLiteral $tableName)
20
    {
21
        $this->tableName = $tableName;
22
    }
23
24
    /**
25
     * @inheritdoc
26
     */
27
    public function configure(AbstractSchemaManager $schemaManager)
28
    {
29
        $schema = $schemaManager->createSchema();
30
        $table = $schema->createTable($this->tableName->toNative());
31
32
        $table->addColumn(
33
            'id',
34
            'guid',
35
            array('length' => 36, 'notnull' => true)
36
        );
37
        $table->addColumn(
38
            'uid',
39
            'guid',
40
            array('length' => 36, 'notnull' => true)
41
        );
42
        $table->addColumn(
43
            'created',
44
            'string',
45
            array('length' => 32, 'notnull' => true)
46
        );
47
        $table->addColumn(
48
            'updated',
49
            'string',
50
            array('length' => 32, 'notnull' => true)
51
        );
52
53
        $table->setPrimaryKey(['id']);
54
55
        $table->addIndex(['uid']);
56
57
        $schemaManager->createTable($table);
58
    }
59
}
60