1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Migrations; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Migrations\AbstractMigration; |
6
|
|
|
use Doctrine\DBAL\Schema\Schema; |
7
|
|
|
use Ramsey\Uuid\Uuid; |
8
|
|
|
use Symfony\Component\Yaml\Yaml; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Version1_0_0 |
12
|
|
|
*/ |
13
|
|
|
class Version1_0_0 extends AbstractMigration |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Up |
17
|
|
|
* |
18
|
|
|
* @param \Doctrine\DBAL\Schema\Schema $schema |
19
|
|
|
*/ |
20
|
|
|
public function up(Schema $schema) |
21
|
|
|
{ |
22
|
|
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); |
23
|
|
|
|
24
|
|
|
// Entity schema |
25
|
|
|
$this->addSql('CREATE SEQUENCE ds_config_id_seq INCREMENT BY 1 MINVALUE 1 START 22'); |
26
|
|
|
$this->addSql('CREATE SEQUENCE ds_parameter_id_seq INCREMENT BY 1 MINVALUE 1 START 2'); |
27
|
|
|
$this->addSql('CREATE SEQUENCE ds_access_id_seq INCREMENT BY 1 MINVALUE 1 START 3'); |
28
|
|
|
$this->addSql('CREATE SEQUENCE ds_access_permission_id_seq INCREMENT BY 1 MINVALUE 1 START 7'); |
29
|
|
|
$this->addSql('CREATE SEQUENCE ds_tenant_id_seq INCREMENT BY 1 MINVALUE 1 START 2'); |
30
|
|
|
$this->addSql('CREATE SEQUENCE app_registration_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); |
31
|
|
|
$this->addSql('CREATE SEQUENCE app_user_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); |
32
|
|
|
$this->addSql('CREATE TABLE ds_config (id INT NOT NULL, uuid UUID NOT NULL, "owner" VARCHAR(255) DEFAULT NULL, owner_uuid UUID DEFAULT NULL, "key" VARCHAR(255) NOT NULL, value JSON DEFAULT NULL, enabled BOOLEAN NOT NULL, version INT DEFAULT 1 NOT NULL, tenant UUID NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))'); |
33
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_758C45F4D17F50A6 ON ds_config (uuid)'); |
34
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_758C45F48A90ABA94E59C462 ON ds_config (key, tenant)'); |
35
|
|
|
$this->addSql('CREATE TABLE ds_parameter (id INT NOT NULL, "key" VARCHAR(255) NOT NULL, value JSON DEFAULT NULL, enabled BOOLEAN NOT NULL, PRIMARY KEY(id))'); |
36
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_B3C0FD91F48571EB ON ds_parameter ("key")'); |
37
|
|
|
$this->addSql('CREATE TABLE ds_access (id INT NOT NULL, uuid UUID NOT NULL, "owner" VARCHAR(255) DEFAULT NULL, owner_uuid UUID DEFAULT NULL, assignee VARCHAR(255) DEFAULT NULL, assignee_uuid UUID DEFAULT NULL, version INT DEFAULT 1 NOT NULL, tenant UUID NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))'); |
38
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_A76F41DCD17F50A6 ON ds_access (uuid)'); |
39
|
|
|
$this->addSql('CREATE TABLE ds_access_permission (id INT NOT NULL, access_id INT DEFAULT NULL, scope VARCHAR(255) DEFAULT NULL, entity VARCHAR(255) DEFAULT NULL, entity_uuid UUID DEFAULT NULL, "key" VARCHAR(255) NOT NULL, attributes JSON NOT NULL, tenant UUID NOT NULL, PRIMARY KEY(id))'); |
40
|
|
|
$this->addSql('CREATE INDEX IDX_D46DD4D04FEA67CF ON ds_access_permission (access_id)'); |
41
|
|
|
$this->addSql('CREATE TABLE ds_tenant (id INT NOT NULL, uuid UUID NOT NULL, data JSON NOT NULL, version INT DEFAULT 1 NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))'); |
42
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_EF5FAEEAD17F50A6 ON ds_tenant (uuid)'); |
43
|
|
|
$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, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, deleted_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))'); |
44
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_A026BD26D17F50A6 ON app_registration (uuid)'); |
45
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_A026BD26A76ED395 ON app_registration (user_id)'); |
46
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_A026BD26F85E06774E59C462 ON app_registration (username, tenant)'); |
47
|
|
|
$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, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, deleted_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))'); |
48
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_88BDF3E9C05FB297 ON app_user (confirmation_token)'); |
49
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_88BDF3E9D17F50A6 ON app_user (uuid)'); |
50
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_88BDF3E9F85E06774E59C462 ON app_user (username, tenant)'); |
51
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_88BDF3E992FC23A84E59C462 ON app_user (username_canonical, tenant)'); |
52
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_88BDF3E9E7927C744E59C462 ON app_user (email, tenant)'); |
53
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_88BDF3E9A0D96FBF4E59C462 ON app_user (email_canonical, tenant)'); |
54
|
|
|
$this->addSql('COMMENT ON COLUMN app_user.roles IS \'(DC2Type:array)\''); |
55
|
|
|
$this->addSql('ALTER TABLE ds_access_permission ADD CONSTRAINT FK_D46DD4D04FEA67CF FOREIGN KEY (access_id) REFERENCES ds_access (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); |
56
|
|
|
$this->addSql('ALTER TABLE app_registration ADD CONSTRAINT FK_A026BD26A76ED395 FOREIGN KEY (user_id) REFERENCES app_user (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); |
57
|
|
|
|
58
|
|
|
// Custom schema |
59
|
|
|
$this->addSql('CREATE TABLE ds_session (id VARCHAR(128) NOT NULL PRIMARY KEY, data BYTEA NOT NULL, time INTEGER NOT NULL, lifetime INTEGER NOT NULL)'); |
60
|
|
|
|
61
|
|
|
// Data |
62
|
|
|
$yml = file_get_contents('/srv/api-platform/src/AppBundle/Resources/migrations/1_0_0.yml'); |
63
|
|
|
$data = Yaml::parse($yml); |
64
|
|
|
|
65
|
|
|
$this->addSql(' |
66
|
|
|
INSERT INTO |
67
|
|
|
ds_parameter (id, key, value, enabled) |
68
|
|
|
VALUES |
69
|
|
|
(1, \'ds_tenant.tenant.default\', \'"'.$data['tenant']['uuid'].'"\', true); |
70
|
|
|
'); |
71
|
|
|
|
72
|
|
|
$this->addSql(' |
73
|
|
|
INSERT INTO |
74
|
|
|
ds_tenant (id, uuid, data, created_at, updated_at) |
75
|
|
|
VALUES |
76
|
|
|
(1, \''.$data['tenant']['uuid'].'\', \'{}\', now(), now()); |
77
|
|
|
'); |
78
|
|
|
|
79
|
|
|
$this->addSql(' |
80
|
|
|
INSERT INTO |
81
|
|
|
ds_config (id, uuid, owner, owner_uuid, key, value, enabled, version, tenant, created_at, updated_at) |
82
|
|
|
VALUES |
83
|
|
|
(1, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'app.spa.admin\', \'"'.$data['config']['app.spa.admin']['value'].'"\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
84
|
|
|
(2, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'app.spa.portal\', \'"'.$data['config']['app.spa.admin']['value'].'"\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
85
|
|
|
(3, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'app.registration.individual.owner.type\', \'"BusinessUnit"\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
86
|
|
|
(4, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'app.registration.individual.owner.uuid\', \'"'.$data['business_unit']['administration']['uuid'].'"\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
87
|
|
|
(5, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'app.registration.individual.roles\', \'[]\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
88
|
|
|
(6, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'app.registration.individual.enabled\', \'true\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
89
|
|
|
(7, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'app.registration.organization.owner.type\', \'"BusinessUnit"\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
90
|
|
|
(8, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'app.registration.organization.owner.uuid\', \'"'.$data['business_unit']['administration']['uuid'].'"\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
91
|
|
|
(9, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'app.registration.organization.roles\', \'[]\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
92
|
|
|
(10, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'app.registration.organization.enabled\', \'true\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
93
|
|
|
(11, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'app.resetting.email.subject\', \'"app.resetting.email.subject"\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
94
|
|
|
(12, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'app.resetting.email.body.plain\', \'"app.resetting.email.body.plain"\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
95
|
|
|
(13, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'app.resetting.email.body.html\', \'"app.resetting.email.body.html"\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
96
|
|
|
(14, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'ds_api.user.username\', \'"[email protected]"\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
97
|
|
|
(15, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'ds_api.user.password\', \'"'.$data['user']['system']['password'].'"\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
98
|
|
|
(16, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'ds_api.user.uuid\', \'"'.$data['user']['system']['uuid'].'"\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
99
|
|
|
(17, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'ds_api.user.roles\', \'[]\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
100
|
|
|
(18, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'ds_api.user.identity.roles\', \'[]\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
101
|
|
|
(19, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'ds_api.user.identity.type\', \'"System"\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
102
|
|
|
(20, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'ds_api.user.identity.uuid\', \'"'.$data['identity']['system']['uuid'].'"\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
103
|
|
|
(21, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'ds_api.user.tenant\', \'"'.$data['tenant']['uuid'].'"\', true, 1, \''.$data['tenant']['uuid'].'\', now(), now()); |
104
|
|
|
'); |
105
|
|
|
|
106
|
|
|
$this->addSql(' |
107
|
|
|
INSERT INTO |
108
|
|
|
ds_access (id, uuid, owner, owner_uuid, assignee, assignee_uuid, version, tenant, created_at, updated_at) |
109
|
|
|
VALUES |
110
|
|
|
(1, \''.Uuid::uuid4()->toString().'\', \'System\', \''.$data['identity']['system']['uuid'].'\', \'System\', \''.$data['identity']['system']['uuid'].'\', 1, \''.$data['tenant']['uuid'].'\', now(), now()), |
111
|
|
|
(2, \''.Uuid::uuid4()->toString().'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'Staff\', \''.$data['identity']['admin']['uuid'].'\', 1, \''.$data['tenant']['uuid'].'\', now(), now()); |
112
|
|
|
'); |
113
|
|
|
|
114
|
|
|
$this->addSql(' |
115
|
|
|
INSERT INTO |
116
|
|
|
ds_access_permission (id, access_id, scope, entity, entity_uuid, key, attributes, tenant) |
117
|
|
|
VALUES |
118
|
|
|
(1, 1, \'generic\', NULL, NULL, \'entity\', \'["BROWSE","READ","EDIT","ADD","DELETE"]\', \''.$data['tenant']['uuid'].'\'), |
119
|
|
|
(2, 1, \'generic\', NULL, NULL, \'property\', \'["BROWSE","READ","EDIT"]\', \''.$data['tenant']['uuid'].'\'), |
120
|
|
|
(3, 1, \'generic\', NULL, NULL, \'generic\', \'["BROWSE","READ","EDIT","ADD","DELETE","EXECUTE"]\', \''.$data['tenant']['uuid'].'\'), |
121
|
|
|
(4, 2, \'generic\', NULL, NULL, \'entity\', \'["BROWSE","READ","EDIT","ADD","DELETE"]\', \''.$data['tenant']['uuid'].'\'), |
122
|
|
|
(5, 2, \'generic\', NULL, NULL, \'property\', \'["BROWSE","READ","EDIT"]\', \''.$data['tenant']['uuid'].'\'), |
123
|
|
|
(6, 2, \'generic\', NULL, NULL, \'generic\', \'["BROWSE","READ","EDIT","ADD","DELETE","EXECUTE"]\', \''.$data['tenant']['uuid'].'\'); |
124
|
|
|
'); |
125
|
|
|
|
126
|
|
|
$this->addSql(' |
127
|
|
|
INSERT INTO |
128
|
|
|
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) |
129
|
|
|
VALUES |
130
|
|
|
(1, \'[email protected]\', \'[email protected]\', \'[email protected]\', \'[email protected]\', true, NULL, \''.password_hash($data['user']['system']['password'], PASSWORD_BCRYPT).'\', NULL, NULL, NULL, \'a:1:{i:0;s:0:"";}\', \''.$data['user']['system']['uuid'].'\', \'System\', \''.$data['identity']['system']['uuid'].'\', \'System\', \''.$data['identity']['system']['uuid'].'\', 1, \''.$data['tenant']['uuid'].'\', now(), now(), NULL), |
131
|
|
|
(2, \'[email protected]\', \'[email protected]\', \'[email protected]\', \'[email protected]\', true, NULL, \''.password_hash($data['user']['anonymous']['password'], PASSWORD_BCRYPT).'\', NULL, NULL, NULL, \'a:1:{i:0;s:0:"";}\', \''.$data['user']['anonymous']['uuid'].'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'Anonymous\', NULL, 1, \''.$data['tenant']['uuid'].'\', now(), now(), NULL), |
132
|
|
|
(3, \'[email protected]\', \'[email protected]\', \'[email protected]\', \'[email protected]\', true, NULL, \''.password_hash($data['user']['admin']['password'], PASSWORD_BCRYPT).'\', NULL, NULL, NULL, \'a:1:{i:0;s:0:"";}\', \''.$data['user']['admin']['uuid'].'\', \'BusinessUnit\', \''.$data['business_unit']['administration']['uuid'].'\', \'Staff\', \''.$data['identity']['admin']['uuid'].'\', 1, \''.$data['tenant']['uuid'].'\', now(), now(), NULL); |
133
|
|
|
'); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Down |
138
|
|
|
* |
139
|
|
|
* @param \Doctrine\DBAL\Schema\Schema $schema |
140
|
|
|
*/ |
141
|
|
|
public function down(Schema $schema) |
142
|
|
|
{ |
143
|
|
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); |
144
|
|
|
|
145
|
|
|
// Entity schema |
146
|
|
|
$this->addSql('ALTER TABLE ds_access_permission DROP CONSTRAINT FK_D46DD4D04FEA67CF'); |
147
|
|
|
$this->addSql('ALTER TABLE app_registration DROP CONSTRAINT FK_A026BD26A76ED395'); |
148
|
|
|
$this->addSql('DROP SEQUENCE ds_config_id_seq CASCADE'); |
149
|
|
|
$this->addSql('DROP SEQUENCE ds_parameter_id_seq CASCADE'); |
150
|
|
|
$this->addSql('DROP SEQUENCE ds_access_id_seq CASCADE'); |
151
|
|
|
$this->addSql('DROP SEQUENCE ds_access_permission_id_seq CASCADE'); |
152
|
|
|
$this->addSql('DROP SEQUENCE ds_tenant_id_seq CASCADE'); |
153
|
|
|
$this->addSql('DROP SEQUENCE app_registration_id_seq CASCADE'); |
154
|
|
|
$this->addSql('DROP SEQUENCE app_user_id_seq CASCADE'); |
155
|
|
|
$this->addSql('DROP TABLE ds_config'); |
156
|
|
|
$this->addSql('DROP TABLE ds_parameter'); |
157
|
|
|
$this->addSql('DROP TABLE ds_access'); |
158
|
|
|
$this->addSql('DROP TABLE ds_access_permission'); |
159
|
|
|
$this->addSql('DROP TABLE ds_tenant'); |
160
|
|
|
$this->addSql('DROP TABLE app_registration'); |
161
|
|
|
$this->addSql('DROP TABLE app_user'); |
162
|
|
|
|
163
|
|
|
// Custom schema |
164
|
|
|
$this->addSql('DROP TABLE ds_session'); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|