|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Migrations\Pgsql; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
8
|
|
|
use Doctrine\Migrations\AbstractMigration; |
|
9
|
|
|
|
|
10
|
|
|
final class Version20241205094349_Spacecraft_Split extends AbstractMigration |
|
11
|
|
|
{ |
|
12
|
|
|
public function getDescription(): string |
|
13
|
|
|
{ |
|
14
|
|
|
return 'Split ship entity into ships and stations with abstract spacecraft entity.'; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function up(Schema $schema): void |
|
18
|
|
|
{ |
|
19
|
|
|
// CREATE NEW TABLES |
|
20
|
|
|
$this->createSpacecraft(); |
|
21
|
|
|
$this->createShip(); |
|
22
|
|
|
$this->createStation(); |
|
23
|
|
|
$this->createTrumfield(); |
|
24
|
|
|
|
|
25
|
|
|
// MOVE DATA |
|
26
|
|
|
$this->fillSpacecraft(); |
|
27
|
|
|
$this->fillShip(); |
|
28
|
|
|
$this->fillStation(); |
|
29
|
|
|
$this->fillTrumfield(); |
|
30
|
|
|
$this->extendExistingData(); |
|
31
|
|
|
|
|
32
|
|
|
// ADD CONSTRAINTS |
|
33
|
|
|
$this->addConstraints(); |
|
34
|
|
|
|
|
35
|
|
|
// REFACTORING |
|
36
|
|
|
$this->addSql('ALTER TABLE stu_colonies_shipqueue DROP CONSTRAINT FK_BEDCCA2FC256317D'); |
|
37
|
|
|
$this->addSql('ALTER TABLE stu_colonies_shipqueue ADD CONSTRAINT FK_BEDCCA2FC256317D FOREIGN KEY (ship_id) REFERENCES stu_ship (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
38
|
|
|
$this->addSql('ALTER TABLE stu_colonies_shiprepair DROP CONSTRAINT FK_F14F182FC256317D'); |
|
39
|
|
|
$this->addSql('ALTER TABLE stu_colonies_shiprepair ADD CONSTRAINT FK_F14F182FC256317D FOREIGN KEY (ship_id) REFERENCES stu_ship (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
40
|
|
|
$this->addSql('ALTER TABLE stu_construction_progress DROP CONSTRAINT fk_57d2ad04c256317d'); |
|
41
|
|
|
$this->addSql('DROP INDEX uniq_57d2ad04c256317d'); |
|
42
|
|
|
$this->addSql('DROP INDEX construction_progress_ship_idx'); |
|
43
|
|
|
$this->addSql('ALTER TABLE stu_construction_progress RENAME COLUMN ship_id TO station_id'); |
|
44
|
|
|
$this->addSql('ALTER TABLE stu_construction_progress ADD CONSTRAINT FK_57D2AD0421BDB235 FOREIGN KEY (station_id) REFERENCES stu_station (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
45
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_57D2AD0421BDB235 ON stu_construction_progress (station_id)'); |
|
46
|
|
|
$this->addSql('ALTER TABLE stu_crew_assign DROP CONSTRAINT fk_2ca6e80ac907e695'); |
|
47
|
|
|
$this->addSql('DROP INDEX ship_crew_ship_idx'); |
|
48
|
|
|
$this->addSql('ALTER TABLE stu_crew_assign RENAME COLUMN ship_id TO spacecraft_id'); |
|
49
|
|
|
$this->addSql('ALTER TABLE stu_crew_assign ADD CONSTRAINT FK_4793ED241C6AF6FD FOREIGN KEY (spacecraft_id) REFERENCES stu_spacecraft (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
50
|
|
|
$this->addSql('CREATE INDEX ship_crew_spacecraft_idx ON stu_crew_assign (spacecraft_id)'); |
|
51
|
|
|
$this->addSql('ALTER TABLE stu_dockingrights DROP CONSTRAINT fk_e7d4b2ac907e695'); |
|
52
|
|
|
$this->addSql('DROP INDEX dockingrights_ship_idx'); |
|
53
|
|
|
$this->addSql('ALTER TABLE stu_dockingrights RENAME COLUMN ships_id TO station_id'); |
|
54
|
|
|
$this->addSql('ALTER TABLE stu_dockingrights ADD CONSTRAINT FK_E7D4B2A21BDB235 FOREIGN KEY (station_id) REFERENCES stu_station (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
55
|
|
|
$this->addSql('CREATE INDEX dockingrights_station_idx ON stu_dockingrights (station_id)'); |
|
56
|
|
|
$this->addSql('ALTER TABLE stu_fleets DROP CONSTRAINT FK_2042261BC907E695'); |
|
57
|
|
|
$this->addSql('ALTER TABLE stu_fleets ADD CONSTRAINT FK_2042261BC907E695 FOREIGN KEY (ships_id) REFERENCES stu_ship (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
58
|
|
|
$this->addSql('ALTER TABLE stu_mining_queue DROP CONSTRAINT FK_BBFEF8C4C256317D'); |
|
59
|
|
|
$this->addSql('ALTER TABLE stu_mining_queue ADD CONSTRAINT FK_BBFEF8C4C256317D FOREIGN KEY (ship_id) REFERENCES stu_ship (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
60
|
|
|
$this->addSql('ALTER TABLE stu_repair_task DROP CONSTRAINT FK_36DA3BAFC256317D'); |
|
61
|
|
|
$this->addSql('DROP INDEX idx_36da3bafc256317d'); |
|
62
|
|
|
$this->addSql('ALTER TABLE stu_repair_task RENAME COLUMN ship_id TO spacecraft_id'); |
|
63
|
|
|
$this->addSql('ALTER TABLE stu_repair_task ADD CONSTRAINT FK_36DA3BAFC256317D FOREIGN KEY (spacecraft_id) REFERENCES stu_spacecraft (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
64
|
|
|
$this->addSql('CREATE INDEX IDX_36DA3BAF1C6AF6FD ON stu_repair_task (spacecraft_id)'); |
|
65
|
|
|
$this->addSql('ALTER TABLE stu_rumps_categories DROP points'); |
|
66
|
|
|
$this->addSql('ALTER TABLE stu_ship_log DROP CONSTRAINT fk_74cef0eec256317d'); |
|
67
|
|
|
$this->addSql('DROP INDEX ship_log_ship_idx'); |
|
68
|
|
|
$this->addSql('ALTER TABLE stu_ship_log RENAME COLUMN ship_id TO spacecraft_id'); |
|
69
|
|
|
$this->addSql('ALTER TABLE stu_ship_log ADD CONSTRAINT FK_74CEF0EE1C6AF6FD FOREIGN KEY (spacecraft_id) REFERENCES stu_spacecraft (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
70
|
|
|
$this->addSql('CREATE INDEX IDX_74CEF0EE1C6AF6FD ON stu_ship_log (spacecraft_id)'); |
|
71
|
|
|
$this->addSql('ALTER TABLE stu_ship_system DROP CONSTRAINT fk_fc8bbeb7c907e695'); |
|
72
|
|
|
$this->addSql('DROP INDEX ship_system_ship_idx'); |
|
73
|
|
|
$this->addSql('ALTER TABLE stu_ship_system RENAME COLUMN ship_id TO spacecraft_id'); |
|
74
|
|
|
$this->addSql('ALTER TABLE stu_ship_system ADD CONSTRAINT FK_8E777AE91C6AF6FD FOREIGN KEY (spacecraft_id) REFERENCES stu_spacecraft (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
75
|
|
|
$this->addSql('CREATE INDEX IDX_8E777AE91C6AF6FD ON stu_ship_system (spacecraft_id)'); |
|
76
|
|
|
$this->addSql('ALTER INDEX ship_system_module_idx RENAME TO IDX_8E777AE9AFC2B591'); |
|
77
|
|
|
$this->addSql('ALTER TABLE stu_ship_takeover DROP CONSTRAINT fk_4b0b8a7c8b898915'); |
|
78
|
|
|
$this->addSql('ALTER TABLE stu_ship_takeover DROP CONSTRAINT fk_4b0b8a7c93e8816'); |
|
79
|
|
|
$this->addSql('DROP INDEX uniq_4b0b8a7c93e8816'); |
|
80
|
|
|
$this->addSql('DROP INDEX uniq_4b0b8a7c8b898915'); |
|
81
|
|
|
$this->addSql('DROP INDEX ship_takeover_target_idx'); |
|
82
|
|
|
$this->addSql('DROP INDEX ship_takeover_source_idx'); |
|
83
|
|
|
$this->addSql('ALTER TABLE stu_ship_takeover RENAME COLUMN source_ship_id TO source_spacecraft_id'); |
|
84
|
|
|
$this->addSql('ALTER TABLE stu_ship_takeover RENAME COLUMN target_ship_id TO target_spacecraft_id'); |
|
85
|
|
|
$this->addSql('ALTER TABLE stu_ship_takeover ADD CONSTRAINT FK_4B0B8A7CD906279F FOREIGN KEY (source_spacecraft_id) REFERENCES stu_spacecraft (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
86
|
|
|
$this->addSql('ALTER TABLE stu_ship_takeover ADD CONSTRAINT FK_4B0B8A7CE6C54C FOREIGN KEY (target_spacecraft_id) REFERENCES stu_spacecraft (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
87
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_4B0B8A7CD906279F ON stu_ship_takeover (source_spacecraft_id)'); |
|
88
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_4B0B8A7CE6C54C ON stu_ship_takeover (target_spacecraft_id)'); |
|
89
|
|
|
$this->addSql('CREATE INDEX ship_takeover_target_idx ON stu_ship_takeover (target_spacecraft_id)'); |
|
90
|
|
|
$this->addSql('CREATE INDEX ship_takeover_source_idx ON stu_ship_takeover (source_spacecraft_id)'); |
|
91
|
|
|
$this->addSql('ALTER TABLE stu_shipyard_shipqueue DROP CONSTRAINT fk_7c6ffb42c256317d'); |
|
92
|
|
|
$this->addSql('DROP INDEX idx_7c6ffb42c256317d'); |
|
93
|
|
|
$this->addSql('ALTER TABLE stu_shipyard_shipqueue RENAME COLUMN ship_id TO station_id'); |
|
94
|
|
|
$this->addSql('ALTER TABLE stu_shipyard_shipqueue ADD CONSTRAINT FK_7C6FFB4221BDB235 FOREIGN KEY (station_id) REFERENCES stu_station (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
95
|
|
|
$this->addSql('CREATE INDEX IDX_7C6FFB4221BDB235 ON stu_shipyard_shipqueue (station_id)'); |
|
96
|
|
|
$this->addSql('ALTER TABLE stu_spacecraft_emergency DROP CONSTRAINT FK_F0230813C256317D'); |
|
97
|
|
|
$this->addSql('DROP INDEX spacecraft_emergency_ship_idx'); |
|
98
|
|
|
$this->addSql('ALTER TABLE stu_spacecraft_emergency RENAME COLUMN ship_id TO spacecraft_id'); |
|
99
|
|
|
$this->addSql('ALTER TABLE stu_spacecraft_emergency ADD CONSTRAINT FK_F0230813C256317D FOREIGN KEY (spacecraft_id) REFERENCES stu_spacecraft (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
100
|
|
|
$this->addSql('CREATE INDEX IDX_F02308131C6AF6FD ON stu_spacecraft_emergency (spacecraft_id)'); |
|
101
|
|
|
$this->addSql('ALTER TABLE stu_station_shiprepair DROP CONSTRAINT FK_51875AF721BDB235'); |
|
102
|
|
|
$this->addSql('ALTER TABLE stu_station_shiprepair DROP CONSTRAINT FK_51875AF7C256317D'); |
|
103
|
|
|
$this->addSql('ALTER TABLE stu_station_shiprepair ADD CONSTRAINT FK_51875AF721BDB235 FOREIGN KEY (station_id) REFERENCES stu_station (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
104
|
|
|
$this->addSql('ALTER TABLE stu_station_shiprepair ADD CONSTRAINT FK_51875AF7C256317D FOREIGN KEY (ship_id) REFERENCES stu_ship (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
105
|
|
|
$this->addSql('ALTER TABLE stu_storage DROP CONSTRAINT FK_CC10346C256317D'); |
|
106
|
|
|
$this->addSql('DROP INDEX storage_ship_idx'); |
|
107
|
|
|
$this->addSql('ALTER TABLE stu_storage RENAME COLUMN ship_id TO spacecraft_id'); |
|
108
|
|
|
$this->addSql('ALTER TABLE stu_storage ADD trumfield_id INT DEFAULT NULL'); |
|
109
|
|
|
$this->addSql('ALTER TABLE stu_storage ADD CONSTRAINT FK_CC10346668E6720 FOREIGN KEY (trumfield_id) REFERENCES stu_trumfield (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
110
|
|
|
$this->addSql('ALTER TABLE stu_storage ADD CONSTRAINT FK_CC103461C6AF6FD FOREIGN KEY (spacecraft_id) REFERENCES stu_spacecraft (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
111
|
|
|
$this->addSql('CREATE INDEX IDX_CC10346668E6720 ON stu_storage (trumfield_id)'); |
|
112
|
|
|
$this->addSql('CREATE INDEX storage_spacecraft_idx ON stu_storage (spacecraft_id)'); |
|
113
|
|
|
$this->addSql('ALTER TABLE stu_tholian_web DROP CONSTRAINT FK_D032F9A0C256317D'); |
|
114
|
|
|
$this->addSql('ALTER TABLE stu_tholian_web ADD CONSTRAINT FK_D032F9A0C256317D FOREIGN KEY (ship_id) REFERENCES stu_ship (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
115
|
|
|
$this->addSql('ALTER TABLE stu_torpedo_storage DROP CONSTRAINT fk_82371911c256317d'); |
|
116
|
|
|
$this->addSql('DROP INDEX uniq_82371911c256317d'); |
|
117
|
|
|
$this->addSql('DROP INDEX torpedo_storage_ship_idx'); |
|
118
|
|
|
$this->addSql('ALTER TABLE stu_torpedo_storage RENAME COLUMN ship_id TO spacecraft_id'); |
|
119
|
|
|
$this->addSql('ALTER TABLE stu_torpedo_storage ADD CONSTRAINT FK_823719111C6AF6FD FOREIGN KEY (spacecraft_id) REFERENCES stu_spacecraft (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
120
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_823719111C6AF6FD ON stu_torpedo_storage (spacecraft_id)'); |
|
121
|
|
|
$this->addSql('CREATE INDEX torpedo_storage_spacecraft_idx ON stu_torpedo_storage (spacecraft_id)'); |
|
122
|
|
|
$this->addSql('ALTER TABLE stu_trade_posts DROP CONSTRAINT fk_13d25e73c256317d'); |
|
123
|
|
|
$this->addSql('DROP INDEX uniq_13d25e73c256317d'); |
|
124
|
|
|
$this->addSql('DROP INDEX trade_post_ship_idx'); |
|
125
|
|
|
$this->addSql('ALTER TABLE stu_trade_posts RENAME COLUMN ship_id TO station_id'); |
|
126
|
|
|
$this->addSql('ALTER TABLE stu_trade_posts ADD CONSTRAINT FK_13D25E7321BDB235 FOREIGN KEY (station_id) REFERENCES stu_station (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
127
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_13D25E7321BDB235 ON stu_trade_posts (station_id)'); |
|
128
|
|
|
$this->addSql('CREATE INDEX trade_post_station_idx ON stu_trade_posts (station_id)'); |
|
129
|
|
|
|
|
130
|
|
|
// DROP OLD TABLES |
|
131
|
|
|
$this->dropStuShips(); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
private function createSpacecraft(): void |
|
135
|
|
|
{ |
|
136
|
|
|
$this->addSql('CREATE TABLE stu_spacecraft (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, user_id INT NOT NULL, rump_id INT NOT NULL, plan_id INT DEFAULT NULL, direction SMALLINT NOT NULL, name VARCHAR(255) NOT NULL, alvl SMALLINT NOT NULL, lss_mode SMALLINT NOT NULL, huelle INT NOT NULL, max_huelle INT NOT NULL, schilde INT NOT NULL, max_schilde INT NOT NULL, tractored_ship_id INT DEFAULT NULL, holding_web_id INT DEFAULT NULL, database_id INT DEFAULT NULL, disabled BOOLEAN NOT NULL, hit_chance SMALLINT NOT NULL, evade_chance SMALLINT NOT NULL, base_damage SMALLINT NOT NULL, sensor_range SMALLINT NOT NULL, shield_regeneration_timer INT NOT NULL, state SMALLINT NOT NULL, location_id INT NOT NULL, in_emergency BOOLEAN NOT NULL, type VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); |
|
137
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_4BD20E2EEE54A42E ON stu_spacecraft (tractored_ship_id)'); |
|
138
|
|
|
$this->addSql('CREATE INDEX IDX_4BD20E2E73D3801E ON stu_spacecraft (holding_web_id)'); |
|
139
|
|
|
$this->addSql('CREATE INDEX IDX_4BD20E2EA76ED395 ON stu_spacecraft (user_id)'); |
|
140
|
|
|
$this->addSql('CREATE INDEX IDX_4BD20E2E2EE98D4C ON stu_spacecraft (rump_id)'); |
|
141
|
|
|
$this->addSql('CREATE INDEX IDX_4BD20E2EE899029B ON stu_spacecraft (plan_id)'); |
|
142
|
|
|
$this->addSql('CREATE INDEX IDX_4BD20E2E64D218E ON stu_spacecraft (location_id)'); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
private function createShip(): void |
|
146
|
|
|
{ |
|
147
|
|
|
$this->addSql('CREATE TABLE stu_ship (id INT NOT NULL, fleet_id INT DEFAULT NULL, docked_to_id INT DEFAULT NULL, is_fleet_leader BOOLEAN NOT NULL, PRIMARY KEY(id))'); |
|
148
|
|
|
$this->addSql('CREATE INDEX IDX_65024D724B061DF9 ON stu_ship (fleet_id)'); |
|
149
|
|
|
$this->addSql('CREATE INDEX IDX_65024D729B76929F ON stu_ship (docked_to_id)'); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
private function createStation(): void |
|
153
|
|
|
{ |
|
154
|
|
|
$this->addSql('CREATE TABLE stu_station (id INT NOT NULL, influence_area_id INT DEFAULT NULL, PRIMARY KEY(id))'); |
|
155
|
|
|
$this->addSql('CREATE INDEX station_influence_area_idx ON stu_station (influence_area_id)'); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
private function createTrumfield(): void |
|
159
|
|
|
{ |
|
160
|
|
|
$this->addSql('CREATE TABLE stu_trumfield (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, huelle INT NOT NULL, former_rump_id INT NOT NULL, location_id INT NOT NULL, PRIMARY KEY(id))'); |
|
161
|
|
|
$this->addSql('CREATE INDEX IDX_3CBB9A4E64D218E ON stu_trumfield (location_id)'); |
|
162
|
|
|
$this->addSql('ALTER TABLE stu_trumfield ADD CONSTRAINT FK_3CBB9A4E64D218E FOREIGN KEY (location_id) REFERENCES stu_location (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
private function fillSpacecraft(): void |
|
166
|
|
|
{ |
|
167
|
|
|
$this->addSql('INSERT INTO stu_spacecraft |
|
168
|
|
|
(id, user_id, rump_id, plan_id,direction, name, alvl, lss_mode, huelle, max_huelle, schilde, max_schilde, tractored_ship_id, holding_web_id, database_id, disabled, |
|
169
|
|
|
hit_chance, evade_chance, base_damage, sensor_range, shield_regeneration_timer, state, location_id, in_emergency, type) |
|
170
|
|
|
SELECT id, user_id, rumps_id, plans_id, direction, name, alvl, lss_mode, huelle, max_huelle, schilde, max_schilde, tractored_ship_id, holding_web_id, database_id, disabled, |
|
171
|
|
|
hit_chance, evade_chance, base_damage, sensor_range, shield_regeneration_timer, state, location_id, in_emergency, (CASE WHEN type = 0 THEN \'SHIP\' ELSE \'STATION\' END) |
|
172
|
|
|
FROM stu_ships |
|
173
|
|
|
WHERE type in (0,1)'); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
private function fillShip(): void |
|
177
|
|
|
{ |
|
178
|
|
|
$this->addSql('INSERT INTO stu_ship |
|
179
|
|
|
(id, fleet_id, docked_to_id, is_fleet_leader) |
|
180
|
|
|
SELECT id, fleets_id, dock, is_fleet_leader |
|
181
|
|
|
FROM stu_ships |
|
182
|
|
|
WHERE type = 0'); |
|
183
|
|
|
} |
|
184
|
|
|
private function fillStation(): void |
|
185
|
|
|
{ |
|
186
|
|
|
$this->addSql('INSERT INTO stu_station |
|
187
|
|
|
(id, influence_area_id) |
|
188
|
|
|
SELECT id, influence_area_id |
|
189
|
|
|
FROM stu_ships |
|
190
|
|
|
WHERE type = 1'); |
|
191
|
|
|
} |
|
192
|
|
|
private function fillTrumfield(): void |
|
193
|
|
|
{ |
|
194
|
|
|
$this->addSql('DELETE FROM stu_construction_progress cp |
|
195
|
|
|
WHERE EXISTS (SELECT * FROM stu_ships s |
|
196
|
|
|
WHERE cp.ship_id = s.id |
|
197
|
|
|
AND s.type = 2)'); |
|
198
|
|
|
$this->addSql('DELETE FROM stu_dockingrights dr |
|
199
|
|
|
WHERE EXISTS (SELECT * FROM stu_ships s |
|
200
|
|
|
WHERE dr.ships_id = s.id |
|
201
|
|
|
AND s.type = 2)'); |
|
202
|
|
|
$this->addSql('DELETE FROM stu_spacecraft_emergency se |
|
203
|
|
|
WHERE EXISTS (SELECT * FROM stu_ships s |
|
204
|
|
|
WHERE se.ship_id = s.id |
|
205
|
|
|
AND s.type = 2)'); |
|
206
|
|
|
$this->addSql('INSERT INTO stu_trumfield |
|
207
|
|
|
(huelle, former_rump_id, location_id) |
|
208
|
|
|
SELECT huelle, former_rumps_id, location_id |
|
209
|
|
|
FROM stu_ships |
|
210
|
|
|
WHERE type = 2'); |
|
211
|
|
|
$this->addSql('DELETE FROM stu_storage st |
|
212
|
|
|
WHERE EXISTS (SELECT * FROM stu_ships s |
|
213
|
|
|
WHERE s.id = st.ship_id |
|
214
|
|
|
AND s.type = 2)'); |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
private function extendExistingData(): void |
|
218
|
|
|
{ |
|
219
|
|
|
$this->addSql('ALTER TABLE stu_rumps_categories ADD type VARCHAR(255) DEFAULT NULL'); |
|
220
|
|
|
$this->addSql('UPDATE stu_rumps_categories SET type = \'STATION\' WHERE ID IN (11,12)'); |
|
221
|
|
|
$this->addSql('UPDATE stu_rumps_categories SET type = \'SHIP\' WHERE type IS NULL'); |
|
222
|
|
|
$this->addSql('ALTER TABLE stu_rumps_categories ALTER type SET NOT NULL'); |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
private function addConstraints(): void |
|
226
|
|
|
{ |
|
227
|
|
|
//SPACECRAFT |
|
228
|
|
|
$this->addSql('ALTER TABLE stu_spacecraft ADD CONSTRAINT FK_4BD20E2EEE54A42E FOREIGN KEY (tractored_ship_id) REFERENCES stu_ship (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
229
|
|
|
$this->addSql('ALTER TABLE stu_spacecraft ADD CONSTRAINT FK_4BD20E2E73D3801E FOREIGN KEY (holding_web_id) REFERENCES stu_tholian_web (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
230
|
|
|
$this->addSql('ALTER TABLE stu_spacecraft ADD CONSTRAINT FK_4BD20E2EA76ED395 FOREIGN KEY (user_id) REFERENCES stu_user (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
231
|
|
|
$this->addSql('ALTER TABLE stu_spacecraft ADD CONSTRAINT FK_4BD20E2E2EE98D4C FOREIGN KEY (rump_id) REFERENCES stu_rumps (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
232
|
|
|
$this->addSql('ALTER TABLE stu_spacecraft ADD CONSTRAINT FK_4BD20E2EE899029B FOREIGN KEY (plan_id) REFERENCES stu_buildplans (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
233
|
|
|
$this->addSql('ALTER TABLE stu_spacecraft ADD CONSTRAINT FK_4BD20E2E64D218E FOREIGN KEY (location_id) REFERENCES stu_location (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
234
|
|
|
//SHIP |
|
235
|
|
|
$this->addSql('ALTER TABLE stu_ship ADD CONSTRAINT FK_65024D724B061DF9 FOREIGN KEY (fleet_id) REFERENCES stu_fleets (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
236
|
|
|
$this->addSql('ALTER TABLE stu_ship ADD CONSTRAINT FK_65024D729B76929F FOREIGN KEY (docked_to_id) REFERENCES stu_station (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
237
|
|
|
$this->addSql('ALTER TABLE stu_ship ADD CONSTRAINT FK_65024D72BF396750 FOREIGN KEY (id) REFERENCES stu_spacecraft (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
238
|
|
|
//STATION |
|
239
|
|
|
$this->addSql('ALTER TABLE stu_station ADD CONSTRAINT FK_C782E0C3915ABAF6 FOREIGN KEY (influence_area_id) REFERENCES stu_systems (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
240
|
|
|
$this->addSql('ALTER TABLE stu_station ADD CONSTRAINT FK_C782E0C3BF396750 FOREIGN KEY (id) REFERENCES stu_spacecraft (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
private function dropStuShips(): void |
|
244
|
|
|
{ |
|
245
|
|
|
$this->addSql('ALTER TABLE stu_ships DROP CONSTRAINT fk_a560dd56235bf180'); |
|
246
|
|
|
$this->addSql('ALTER TABLE stu_ships DROP CONSTRAINT fk_a560dd56423bb3e1'); |
|
247
|
|
|
$this->addSql('ALTER TABLE stu_ships DROP CONSTRAINT fk_a560dd5664d218e'); |
|
248
|
|
|
$this->addSql('ALTER TABLE stu_ships DROP CONSTRAINT fk_a560dd5673d3801e'); |
|
249
|
|
|
$this->addSql('ALTER TABLE stu_ships DROP CONSTRAINT fk_a560dd5680446eeb'); |
|
250
|
|
|
$this->addSql('ALTER TABLE stu_ships DROP CONSTRAINT fk_a560dd56915abaf6'); |
|
251
|
|
|
$this->addSql('ALTER TABLE stu_ships DROP CONSTRAINT fk_a560dd5698355913'); |
|
252
|
|
|
$this->addSql('ALTER TABLE stu_ships DROP CONSTRAINT fk_a560dd56a76ed395'); |
|
253
|
|
|
$this->addSql('ALTER TABLE stu_ships DROP CONSTRAINT fk_a560dd56ee54a42e'); |
|
254
|
|
|
$this->addSql('ALTER TABLE stu_ships DROP CONSTRAINT fk_a560dd56f0aa09db'); |
|
255
|
|
|
$this->addSql('DROP TABLE stu_ships'); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
public function down(Schema $schema): void |
|
259
|
|
|
{ |
|
260
|
|
|
// Sorry, but no way back! |
|
261
|
|
|
} |
|
262
|
|
|
} |
|
263
|
|
|
|