|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Migration; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
|
|
|
|
|
6
|
|
|
use Doctrine\Migrations\AbstractMigration; |
|
|
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Migrations\Version; |
|
|
|
|
|
|
8
|
|
|
use Ds\Component\Acl\Migration\Version0_15_0 as Acl; |
|
|
|
|
|
|
9
|
|
|
use Ds\Component\Config\Migration\Version0_15_0 as Config; |
|
|
|
|
|
|
10
|
|
|
use Ds\Component\Container\Attribute; |
|
|
|
|
|
|
11
|
|
|
use Ds\Component\Database\Util\Objects; |
|
|
|
|
|
|
12
|
|
|
use Ds\Component\Database\Util\Parameters; |
|
|
|
|
|
|
13
|
|
|
use Ds\Component\Metadata\Migration\Version0_15_0 as Metadata; |
|
|
|
|
|
|
14
|
|
|
use Ds\Component\Parameter\Migration\Version0_15_0 as Parameter; |
|
|
|
|
|
|
15
|
|
|
use Ds\Component\Tenant\Migration\Version0_15_0 as Tenant; |
|
|
|
|
|
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class Version0_15_0 |
|
20
|
|
|
*/ |
|
21
|
|
|
final class Version0_15_0 extends AbstractMigration implements ContainerAwareInterface |
|
22
|
|
|
{ |
|
23
|
|
|
use Attribute\Container; |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @cont string |
|
27
|
|
|
*/ |
|
28
|
|
|
const DIRECTORY = '/srv/api/config/migrations'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var \Ds\Component\Acl\Migration\Version0_15_0 |
|
32
|
|
|
*/ |
|
33
|
|
|
private $acl; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var \Ds\Component\Config\Migration\Version0_15_0 |
|
37
|
|
|
*/ |
|
38
|
|
|
private $config; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var \Ds\Component\Metadata\Migration\Version0_15_0 |
|
42
|
|
|
*/ |
|
43
|
|
|
private $metadata; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var \Ds\Component\Parameter\Migration\Version0_15_0 |
|
47
|
|
|
*/ |
|
48
|
|
|
private $parameter; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var \Ds\Component\Tenant\Migration\Version0_15_0 |
|
52
|
|
|
*/ |
|
53
|
|
|
private $tenant; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Constructor |
|
57
|
|
|
* |
|
58
|
|
|
* @param \Doctrine\DBAL\Migrations\Version $version |
|
59
|
|
|
*/ |
|
60
|
|
|
public function __construct(Version $version) |
|
61
|
|
|
{ |
|
62
|
|
|
parent::__construct($version); |
|
63
|
|
|
$this->acl = new Acl($version); |
|
64
|
|
|
$this->config = new Config($version); |
|
65
|
|
|
$this->metadata = new Metadata($version); |
|
66
|
|
|
$this->parameter = new Parameter($version); |
|
67
|
|
|
$this->tenant = new Tenant($version); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Up migration |
|
72
|
|
|
* |
|
73
|
|
|
* @param \Doctrine\DBAL\Schema\Schema $schema |
|
74
|
|
|
*/ |
|
75
|
|
|
public function up(Schema $schema) |
|
76
|
|
|
{ |
|
77
|
|
|
$parameters = Parameters::parseFile(static::DIRECTORY.'/parameters.yaml'); |
|
78
|
|
|
$this->acl->up($schema, Objects::parseFile(static::DIRECTORY.'/0_15_0/acl.yaml', $parameters)); |
|
79
|
|
|
$this->config->setContainer($this->container)->up($schema, Objects::parseFile(static::DIRECTORY.'/0_15_0/config.yaml', $parameters)); |
|
80
|
|
|
$this->metadata->up($schema, Objects::parseFile(static::DIRECTORY.'/0_15_0/metadata.yaml', $parameters)); |
|
81
|
|
|
$this->parameter->setContainer($this->container)->up($schema, Objects::parseFile(static::DIRECTORY.'/0_15_0/system/parameter.yaml', $parameters)); |
|
82
|
|
|
$this->tenant->up($schema, Objects::parseFile(static::DIRECTORY.'/0_15_0/system/tenant.yaml', $parameters)); |
|
83
|
|
|
|
|
84
|
|
|
$users = Objects::parseFile(static::DIRECTORY.'/0_15_0/user.yaml', $parameters); |
|
85
|
|
|
|
|
86
|
|
|
$sequences['app_registration_id_seq'] = 1; |
|
|
|
|
|
|
87
|
|
|
$sequences['app_user_id_seq'] = 1 + count($users); |
|
88
|
|
|
|
|
89
|
|
|
switch ($this->platform->getName()) { |
|
90
|
|
|
case 'postgresql': |
|
91
|
|
|
$this->addSql('CREATE SEQUENCE app_registration_id_seq INCREMENT BY 1 MINVALUE 1 START '.$sequences['app_registration_id_seq']); |
|
92
|
|
|
$this->addSql('CREATE SEQUENCE app_user_id_seq INCREMENT BY 1 MINVALUE 1 START '.$sequences['app_user_id_seq']); |
|
93
|
|
|
$this->addSql('CREATE TABLE app_registration (id INT NOT NULL, user_id INT DEFAULT NULL, uuid UUID NOT NULL, "owner" VARCHAR(255) DEFAULT NULL, owner_uuid UUID DEFAULT NULL, username VARCHAR(255) NOT NULL, identity VARCHAR(255) DEFAULT NULL, data JSON NOT NULL, version INT DEFAULT 1 NOT NULL, tenant UUID NOT NULL, deleted_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))'); |
|
94
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_A026BD26D17F50A6 ON app_registration (uuid)'); |
|
95
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_A026BD26A76ED395 ON app_registration (user_id)'); |
|
96
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_A026BD26F85E06774E59C462 ON app_registration (username, tenant)'); |
|
97
|
|
|
$this->addSql('COMMENT ON COLUMN app_registration.data IS \'(DC2Type:json_array)\''); |
|
98
|
|
|
$this->addSql('CREATE TABLE app_user (id INT NOT NULL, username VARCHAR(180) NOT NULL, email VARCHAR(180) NOT NULL, enabled BOOLEAN NOT NULL, salt VARCHAR(255) DEFAULT NULL, password VARCHAR(255) NOT NULL, last_login TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, confirmation_token VARCHAR(180) DEFAULT NULL, password_requested_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, roles TEXT NOT NULL, uuid UUID NOT NULL, "owner" VARCHAR(255) DEFAULT NULL, owner_uuid UUID DEFAULT NULL, identity VARCHAR(255) DEFAULT NULL, identity_uuid UUID DEFAULT NULL, version INT DEFAULT 1 NOT NULL, tenant UUID NOT NULL, username_canonical VARCHAR(180) NOT NULL, email_canonical VARCHAR(180) NOT NULL, deleted_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))'); |
|
99
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_88BDF3E9C05FB297 ON app_user (confirmation_token)'); |
|
100
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_88BDF3E9D17F50A6 ON app_user (uuid)'); |
|
101
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_88BDF3E9F85E06774E59C462 ON app_user (username, tenant)'); |
|
102
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_88BDF3E992FC23A84E59C462 ON app_user (username_canonical, tenant)'); |
|
103
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_88BDF3E9E7927C744E59C462 ON app_user (email, tenant)'); |
|
104
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_88BDF3E9A0D96FBF4E59C462 ON app_user (email_canonical, tenant)'); |
|
105
|
|
|
$this->addSql('COMMENT ON COLUMN app_user.roles IS \'(DC2Type:array)\''); |
|
106
|
|
|
$this->addSql('ALTER TABLE app_registration ADD CONSTRAINT FK_A026BD26A76ED395 FOREIGN KEY (user_id) REFERENCES app_user (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
107
|
|
|
|
|
108
|
|
|
$i = 0; |
|
109
|
|
|
|
|
110
|
|
|
foreach ($users as $user) { |
|
111
|
|
|
$this->addSql(sprintf( |
|
112
|
|
|
'INSERT INTO app_user (id, username, username_canonical, email, email_canonical, enabled, salt, password, last_login, confirmation_token, password_requested_at, roles, uuid, owner, owner_uuid, identity, identity_uuid, version, tenant, created_at, updated_at, deleted_at) VALUES (%d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s, %s);', |
|
113
|
|
|
++$i, |
|
114
|
|
|
$this->connection->quote($user->username), |
|
115
|
|
|
$this->connection->quote($user->username), |
|
116
|
|
|
$this->connection->quote($user->username), |
|
117
|
|
|
$this->connection->quote($user->username), |
|
118
|
|
|
$user->enabled ? 'true' : 'false', |
|
119
|
|
|
'NULL', |
|
120
|
|
|
$this->connection->quote(password_hash($user->password, PASSWORD_BCRYPT)), |
|
121
|
|
|
'NULL', |
|
122
|
|
|
'NULL', |
|
123
|
|
|
'NULL', |
|
124
|
|
|
$this->connection->quote(serialize($user->roles)), |
|
125
|
|
|
$this->connection->quote($user->uuid), |
|
126
|
|
|
$this->connection->quote($user->owner), |
|
127
|
|
|
$this->connection->quote($user->owner_uuid), |
|
128
|
|
|
$this->connection->quote($user->identity), |
|
129
|
|
|
null === $user->identity_uuid ? 'NULL' : $this->connection->quote($user->identity_uuid), |
|
130
|
|
|
$user->version, |
|
131
|
|
|
$this->connection->quote($user->tenant), |
|
132
|
|
|
'now()', |
|
133
|
|
|
'now()', |
|
134
|
|
|
'NULL' |
|
135
|
|
|
)); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
break; |
|
139
|
|
|
|
|
140
|
|
|
default: |
|
141
|
|
|
$this->abortIf(true,'Migration cannot be executed on "'.$this->platform->getName().'".'); |
|
142
|
|
|
break; |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Down migration |
|
148
|
|
|
* |
|
149
|
|
|
* @param \Doctrine\DBAL\Schema\Schema $schema |
|
150
|
|
|
*/ |
|
151
|
|
|
public function down(Schema $schema) |
|
152
|
|
|
{ |
|
153
|
|
|
$this->acl->down($schema); |
|
154
|
|
|
$this->config->setContainer($this->container)->down($schema); |
|
155
|
|
|
$this->metadata->down($schema); |
|
156
|
|
|
$this->parameter->setContainer($this->container)->down($schema); |
|
157
|
|
|
$this->tenant->down($schema); |
|
158
|
|
|
|
|
159
|
|
|
switch ($this->platform->getName()) { |
|
160
|
|
|
case 'postgresql': |
|
161
|
|
|
$this->addSql('ALTER TABLE app_registration DROP CONSTRAINT FK_A026BD26A76ED395'); |
|
162
|
|
|
$this->addSql('DROP SEQUENCE app_registration_id_seq CASCADE'); |
|
163
|
|
|
$this->addSql('DROP SEQUENCE app_user_id_seq CASCADE'); |
|
164
|
|
|
$this->addSql('DROP TABLE app_registration'); |
|
165
|
|
|
$this->addSql('DROP TABLE app_user'); |
|
166
|
|
|
break; |
|
167
|
|
|
|
|
168
|
|
|
default: |
|
169
|
|
|
$this->abortIf(true,'Migration cannot be executed on "'.$this->platform->getName().'".'); |
|
170
|
|
|
break; |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths