|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics) |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU Affero General Public License as published |
|
9
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
|
10
|
|
|
* (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
declare(strict_types=1); |
|
22
|
|
|
|
|
23
|
|
|
namespace DoctrineMigrations; |
|
24
|
|
|
|
|
25
|
|
|
use App\Migrations\AbstractMultiPlatformMigration; |
|
26
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
27
|
|
|
use Doctrine\Migrations\AbstractMigration; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Auto-generated Migration: Please modify to your needs! |
|
31
|
|
|
*/ |
|
32
|
|
|
final class Version20190924113252 extends AbstractMultiPlatformMigration |
|
33
|
|
|
{ |
|
34
|
|
|
public function getDescription(): string |
|
35
|
|
|
{ |
|
36
|
|
|
return ''; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function mySQLUp(Schema $schema): void |
|
40
|
|
|
{ |
|
41
|
|
|
// this up() migration is auto-generated, please modify it to your needs |
|
42
|
|
|
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); |
|
43
|
|
|
|
|
44
|
|
|
$this->addSql('ALTER TABLE users ADD id_preview_attachement INT DEFAULT NULL, ADD pw_reset_token VARCHAR(255) DEFAULT NULL, ADD pw_reset_expires DATETIME DEFAULT NULL, ADD disabled TINYINT(1) NOT NULL, DROP config_image_path'); |
|
45
|
|
|
$this->addSql('ALTER TABLE users ADD CONSTRAINT FK_1483A5E96DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
|
46
|
|
|
$this->addSql('CREATE INDEX IDX_1483A5E96DEDCEC2 ON users (id_preview_attachement)'); |
|
47
|
|
|
$this->addSql('ALTER TABLE attachment_types ADD id_preview_attachement INT DEFAULT NULL'); |
|
48
|
|
|
$this->addSql('ALTER TABLE attachment_types ADD CONSTRAINT FK_EFAED7196DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
|
49
|
|
|
$this->addSql('CREATE INDEX IDX_EFAED7196DEDCEC2 ON attachment_types (id_preview_attachement)'); |
|
50
|
|
|
$this->addSql('ALTER TABLE categories ADD id_preview_attachement INT DEFAULT NULL'); |
|
51
|
|
|
$this->addSql('ALTER TABLE categories ADD CONSTRAINT FK_3AF346686DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
|
52
|
|
|
$this->addSql('CREATE INDEX IDX_3AF346686DEDCEC2 ON categories (id_preview_attachement)'); |
|
53
|
|
|
$this->addSql('ALTER TABLE currencies ADD id_preview_attachement INT DEFAULT NULL'); |
|
54
|
|
|
$this->addSql('ALTER TABLE currencies ADD CONSTRAINT FK_37C446936DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
|
55
|
|
|
$this->addSql('CREATE INDEX IDX_37C446936DEDCEC2 ON currencies (id_preview_attachement)'); |
|
56
|
|
|
$this->addSql('ALTER TABLE devices ADD id_preview_attachement INT DEFAULT NULL'); |
|
57
|
|
|
$this->addSql('ALTER TABLE devices ADD CONSTRAINT FK_11074E9A6DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
|
58
|
|
|
$this->addSql('CREATE INDEX IDX_11074E9A6DEDCEC2 ON devices (id_preview_attachement)'); |
|
59
|
|
|
|
|
60
|
|
|
$this->addSql('ALTER TABLE attachments DROP FOREIGN KEY FK_47C4FAD61F1F2A24'); |
|
61
|
|
|
$this->addSql('ALTER TABLE attachments ADD original_filename VARCHAR(255) DEFAULT NULL, CHANGE filename path VARCHAR(255) NOT NULL'); |
|
62
|
|
|
|
|
63
|
|
|
//Before we drop the filename and filename_3d properties we have to migrate the data to attachments |
|
64
|
|
|
$this->addSql("INSERT IGNORE INTO `attachment_types` (`id`, `name`, `parent_id`, `comment`, `datetime_added`, `last_modified`, `filetype_filter`) |
|
65
|
|
|
VALUES |
|
66
|
|
|
(1000, 'Footprints', NULL, 'Created during automatic migration of the footprint files.', current_timestamp(), current_timestamp(), 'image/*'), |
|
67
|
|
|
(1001, 'Footprints (3D)', NULL, 'Created during automatic migration of the footprint files.', current_timestamp(), current_timestamp(), '.x3d') |
|
68
|
|
|
"); |
|
69
|
|
|
|
|
70
|
|
|
//Add a attachment for each footprint attachment |
|
71
|
|
|
$this->addSql( |
|
72
|
|
|
'INSERT IGNORE INTO attachments (element_id, type_id, name, class_name, path, last_modified, datetime_added) '. |
|
73
|
|
|
"SELECT footprints.id, 1000, 'Footprint', 'Footprint', REPLACE(footprints.filename, '%BASE%/img/footprints', '%FOOTPRINTS%' ), NOW(), NOW() FROM footprints ". |
|
74
|
|
|
"WHERE footprints.filename <> ''" |
|
75
|
|
|
); |
|
76
|
|
|
|
|
77
|
|
|
//Do the same for 3D Footprints |
|
78
|
|
|
$this->addSql( |
|
79
|
|
|
'INSERT IGNORE INTO attachments (element_id, type_id, name, class_name, path, last_modified, datetime_added) '. |
|
80
|
|
|
"SELECT footprints.id, 1001, 'Footprint 3D', 'Footprint', REPLACE(footprints.filename_3d, '%BASE%/models', '%FOOTPRINTS3D%' ), NOW(), NOW() FROM footprints ". |
|
81
|
|
|
"WHERE footprints.filename_3d <> ''" |
|
82
|
|
|
); |
|
83
|
|
|
|
|
84
|
|
|
$this->addSql('ALTER TABLE footprints ADD id_footprint_3d INT DEFAULT NULL, ADD id_preview_attachement INT DEFAULT NULL, DROP filename, DROP filename_3d'); |
|
85
|
|
|
$this->addSql('ALTER TABLE footprints ADD CONSTRAINT FK_A34D68A232A38C34 FOREIGN KEY (id_footprint_3d) REFERENCES `attachments` (id)'); |
|
86
|
|
|
$this->addSql('ALTER TABLE footprints ADD CONSTRAINT FK_A34D68A26DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
|
87
|
|
|
$this->addSql('CREATE INDEX IDX_A34D68A232A38C34 ON footprints (id_footprint_3d)'); |
|
88
|
|
|
$this->addSql('CREATE INDEX IDX_A34D68A26DEDCEC2 ON footprints (id_preview_attachement)'); |
|
89
|
|
|
|
|
90
|
|
|
//Set the created footprint attachments as preview image / 3D footprint image |
|
91
|
|
|
$this->addSql('UPDATE footprints, attachments |
|
92
|
|
|
SET footprints.id_preview_attachement = attachments.id |
|
93
|
|
|
WHERE attachments.class_name = "Footprint" AND attachments.element_id = footprints.id |
|
94
|
|
|
AND attachments.type_id = 1000; |
|
95
|
|
|
'); |
|
96
|
|
|
|
|
97
|
|
|
$this->addSql('UPDATE footprints, attachments |
|
98
|
|
|
SET footprints.id_footprint_3d = attachments.id |
|
99
|
|
|
WHERE attachments.class_name = "Footprint" AND attachments.element_id = footprints.id |
|
100
|
|
|
AND attachments.type_id = 1001; |
|
101
|
|
|
'); |
|
102
|
|
|
|
|
103
|
|
|
$this->addSql('ALTER TABLE manufacturers ADD id_preview_attachement INT DEFAULT NULL'); |
|
104
|
|
|
$this->addSql('ALTER TABLE manufacturers ADD CONSTRAINT FK_94565B126DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
|
105
|
|
|
$this->addSql('CREATE INDEX IDX_94565B126DEDCEC2 ON manufacturers (id_preview_attachement)'); |
|
106
|
|
|
$this->addSql('ALTER TABLE measurement_units ADD id_preview_attachement INT DEFAULT NULL'); |
|
107
|
|
|
$this->addSql('ALTER TABLE measurement_units ADD CONSTRAINT FK_F5AF83CF6DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
|
108
|
|
|
$this->addSql('CREATE INDEX IDX_F5AF83CF6DEDCEC2 ON measurement_units (id_preview_attachement)'); |
|
109
|
|
|
$this->addSql('ALTER TABLE storelocations ADD id_preview_attachement INT DEFAULT NULL'); |
|
110
|
|
|
$this->addSql('ALTER TABLE storelocations ADD CONSTRAINT FK_75170206DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
|
111
|
|
|
$this->addSql('CREATE INDEX IDX_75170206DEDCEC2 ON storelocations (id_preview_attachement)'); |
|
112
|
|
|
$this->addSql('ALTER TABLE suppliers ADD id_preview_attachement INT DEFAULT NULL'); |
|
113
|
|
|
$this->addSql('ALTER TABLE suppliers ADD CONSTRAINT FK_AC28B95C6DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
|
114
|
|
|
$this->addSql('CREATE INDEX IDX_AC28B95C6DEDCEC2 ON suppliers (id_preview_attachement)'); |
|
115
|
|
|
$this->addSql('ALTER TABLE `groups` ADD id_preview_attachement INT DEFAULT NULL'); |
|
116
|
|
|
$this->addSql('ALTER TABLE `groups` ADD CONSTRAINT FK_F06D39706DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
|
117
|
|
|
$this->addSql('CREATE INDEX IDX_F06D39706DEDCEC2 ON `groups` (id_preview_attachement)'); |
|
118
|
|
|
$this->addSql('ALTER TABLE parts DROP FOREIGN KEY FK_6940A7FEEBBCC786'); |
|
119
|
|
|
$this->addSql('DROP INDEX IDX_6940A7FEEBBCC786 ON parts'); |
|
120
|
|
|
$this->addSql('ALTER TABLE parts CHANGE id_master_picture_attachement id_preview_attachement INT DEFAULT NULL'); |
|
121
|
|
|
$this->addSql('ALTER TABLE parts ADD CONSTRAINT FK_6940A7FE6DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
|
122
|
|
|
$this->addSql('CREATE INDEX IDX_6940A7FE6DEDCEC2 ON parts (id_preview_attachement)'); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function mySQLDown(Schema $schema): void |
|
126
|
|
|
{ |
|
127
|
|
|
// this down() migration is auto-generated, please modify it to your needs |
|
128
|
|
|
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); |
|
129
|
|
|
|
|
130
|
|
|
$this->addSql('ALTER TABLE `attachment_types` DROP FOREIGN KEY FK_EFAED7196DEDCEC2'); |
|
131
|
|
|
$this->addSql('DROP INDEX IDX_EFAED7196DEDCEC2 ON `attachment_types`'); |
|
132
|
|
|
$this->addSql('ALTER TABLE `attachment_types` DROP id_preview_attachement'); |
|
133
|
|
|
$this->addSql('ALTER TABLE `attachments` DROP original_filename, CHANGE path filename VARCHAR(255) NOT NULL COLLATE utf8_unicode_ci'); |
|
134
|
|
|
$this->addSql('ALTER TABLE `attachments` ADD CONSTRAINT FK_47C4FAD61F1F2A24 FOREIGN KEY (element_id) REFERENCES parts (id) ON DELETE CASCADE'); |
|
135
|
|
|
$this->addSql('ALTER TABLE `categories` DROP FOREIGN KEY FK_3AF346686DEDCEC2'); |
|
136
|
|
|
$this->addSql('DROP INDEX IDX_3AF346686DEDCEC2 ON `categories`'); |
|
137
|
|
|
$this->addSql('ALTER TABLE `categories` DROP id_preview_attachement'); |
|
138
|
|
|
$this->addSql('ALTER TABLE currencies DROP FOREIGN KEY FK_37C446936DEDCEC2'); |
|
139
|
|
|
$this->addSql('DROP INDEX IDX_37C446936DEDCEC2 ON currencies'); |
|
140
|
|
|
$this->addSql('ALTER TABLE currencies DROP id_preview_attachement'); |
|
141
|
|
|
$this->addSql('ALTER TABLE `devices` DROP FOREIGN KEY FK_11074E9A6DEDCEC2'); |
|
142
|
|
|
$this->addSql('DROP INDEX IDX_11074E9A6DEDCEC2 ON `devices`'); |
|
143
|
|
|
$this->addSql('ALTER TABLE `devices` DROP id_preview_attachement'); |
|
144
|
|
|
$this->addSql('ALTER TABLE `footprints` DROP FOREIGN KEY FK_A34D68A232A38C34'); |
|
145
|
|
|
$this->addSql('ALTER TABLE `footprints` DROP FOREIGN KEY FK_A34D68A26DEDCEC2'); |
|
146
|
|
|
$this->addSql('DROP INDEX IDX_A34D68A232A38C34 ON `footprints`'); |
|
147
|
|
|
$this->addSql('DROP INDEX IDX_A34D68A26DEDCEC2 ON `footprints`'); |
|
148
|
|
|
$this->addSql('ALTER TABLE `footprints` ADD filename MEDIUMTEXT NOT NULL COLLATE utf8_unicode_ci, ADD filename_3d MEDIUMTEXT NOT NULL COLLATE utf8_unicode_ci, DROP id_footprint_3d, DROP id_preview_attachement'); |
|
149
|
|
|
$this->addSql('ALTER TABLE `groups` DROP FOREIGN KEY FK_F06D39706DEDCEC2'); |
|
150
|
|
|
$this->addSql('DROP INDEX IDX_F06D39706DEDCEC2 ON `groups`'); |
|
151
|
|
|
$this->addSql('ALTER TABLE `groups` DROP id_preview_attachement'); |
|
152
|
|
|
$this->addSql('ALTER TABLE `manufacturers` DROP FOREIGN KEY FK_94565B126DEDCEC2'); |
|
153
|
|
|
$this->addSql('DROP INDEX IDX_94565B126DEDCEC2 ON `manufacturers`'); |
|
154
|
|
|
$this->addSql('ALTER TABLE `manufacturers` DROP id_preview_attachement'); |
|
155
|
|
|
$this->addSql('ALTER TABLE `measurement_units` DROP FOREIGN KEY FK_F5AF83CF6DEDCEC2'); |
|
156
|
|
|
$this->addSql('DROP INDEX IDX_F5AF83CF6DEDCEC2 ON `measurement_units`'); |
|
157
|
|
|
$this->addSql('ALTER TABLE `measurement_units` DROP id_preview_attachement'); |
|
158
|
|
|
$this->addSql('ALTER TABLE `parts` DROP FOREIGN KEY FK_6940A7FE6DEDCEC2'); |
|
159
|
|
|
$this->addSql('DROP INDEX IDX_6940A7FE6DEDCEC2 ON `parts`'); |
|
160
|
|
|
$this->addSql('ALTER TABLE `parts` CHANGE id_preview_attachement id_master_picture_attachement INT DEFAULT NULL'); |
|
161
|
|
|
$this->addSql('ALTER TABLE `parts` ADD CONSTRAINT FK_6940A7FEEBBCC786 FOREIGN KEY (id_master_picture_attachement) REFERENCES attachments (id)'); |
|
162
|
|
|
$this->addSql('CREATE INDEX IDX_6940A7FEEBBCC786 ON `parts` (id_master_picture_attachement)'); |
|
163
|
|
|
$this->addSql('ALTER TABLE `storelocations` DROP FOREIGN KEY FK_75170206DEDCEC2'); |
|
164
|
|
|
$this->addSql('DROP INDEX IDX_75170206DEDCEC2 ON `storelocations`'); |
|
165
|
|
|
$this->addSql('ALTER TABLE `storelocations` DROP id_preview_attachement'); |
|
166
|
|
|
$this->addSql('ALTER TABLE `suppliers` DROP FOREIGN KEY FK_AC28B95C6DEDCEC2'); |
|
167
|
|
|
$this->addSql('DROP INDEX IDX_AC28B95C6DEDCEC2 ON `suppliers`'); |
|
168
|
|
|
$this->addSql('ALTER TABLE `suppliers` DROP id_preview_attachement'); |
|
169
|
|
|
$this->addSql('ALTER TABLE `users` DROP FOREIGN KEY FK_1483A5E96DEDCEC2'); |
|
170
|
|
|
$this->addSql('DROP INDEX IDX_1483A5E96DEDCEC2 ON `users`'); |
|
171
|
|
|
$this->addSql('ALTER TABLE `users` ADD config_image_path TEXT NOT NULL COLLATE utf8_general_ci, DROP id_preview_attachement, DROP pw_reset_token, DROP pw_reset_expires, DROP disabled'); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
public function sqLiteUp(Schema $schema): void |
|
175
|
|
|
{ |
|
176
|
|
|
$this->skipIf(true, "Migration not needed for SQLite. Skipping..."); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
public function sqLiteDown(Schema $schema): void |
|
180
|
|
|
{ |
|
181
|
|
|
$this->skipIf(true, "Migration not needed for SQLite. Skipping..."); |
|
182
|
|
|
} |
|
183
|
|
|
} |
|
184
|
|
|
|