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 Version20190913141126 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 `groups` ADD perms_parts_category SMALLINT NOT NULL, ADD perms_parts_minamount SMALLINT NOT NULL, ADD perms_parts_lots SMALLINT NOT NULL, ADD perms_parts_tags SMALLINT NOT NULL, ADD perms_parts_unit SMALLINT NOT NULL, ADD perms_parts_mass SMALLINT NOT NULL, ADD perms_parts_status SMALLINT NOT NULL, ADD perms_parts_mpn SMALLINT NOT NULL, ADD perms_currencies INT NOT NULL, ADD perms_measurement_units INT NOT NULL, DROP perms_parts_instock, DROP perms_parts_mininstock, DROP perms_parts_storelocation'); |
45
|
|
|
$this->addSql('ALTER TABLE users ADD currency_id INT DEFAULT NULL, ADD settings LONGTEXT NOT NULL COMMENT \'(DC2Type:json)\', ADD perms_parts_category SMALLINT NOT NULL, ADD perms_parts_minamount SMALLINT NOT NULL, ADD perms_parts_lots SMALLINT NOT NULL, ADD perms_parts_tags SMALLINT NOT NULL, ADD perms_parts_unit SMALLINT NOT NULL, ADD perms_parts_mass SMALLINT NOT NULL, ADD perms_parts_status SMALLINT NOT NULL, ADD perms_parts_mpn SMALLINT NOT NULL, ADD perms_currencies INT NOT NULL, ADD perms_measurement_units INT NOT NULL, DROP config_currency, DROP perms_parts_instock, DROP perms_parts_mininstock, DROP perms_parts_storelocation'); |
46
|
|
|
$this->addSql('ALTER TABLE users ADD CONSTRAINT FK_1483A5E938248176 FOREIGN KEY (currency_id) REFERENCES currencies (id)'); |
47
|
|
|
$this->addSql('CREATE INDEX IDX_1483A5E938248176 ON users (currency_id)'); |
48
|
|
|
|
49
|
|
|
//Set some default permissions for the groups |
50
|
|
|
|
51
|
|
|
$sql = 'UPDATE `groups` |
52
|
|
|
SET perms_parts_category = 9, perms_parts_minamount = 9, perms_parts_lots = 169, perms_parts_tags= 9, |
53
|
|
|
perms_parts_unit = 9, perms_parts_mass = 9, perms_parts_status = 9, perms_parts_mpn = 9, |
54
|
|
|
perms_currencies = 9897, perms_measurement_units = 9897, perms_parts_attachements = 681, |
55
|
|
|
perms_parts_orderdetails = 681, perms_parts_prices = 681 |
56
|
|
|
WHERE id = 2 AND name = "readonly";'; |
57
|
|
|
|
58
|
|
|
$this->addSql($sql); |
59
|
|
|
|
60
|
|
|
$sql = 'UPDATE `groups` |
61
|
|
|
SET perms_parts_category = 5, perms_parts_minamount = 5, perms_parts_lots = 85, perms_parts_tags= 5, |
62
|
|
|
perms_parts_unit = 5, perms_parts_mass = 5, perms_parts_status = 5, perms_parts_mpn = 5, |
63
|
|
|
perms_currencies = 5461, perms_measurement_units = 5461, perms_parts_attachements = 341, |
64
|
|
|
perms_parts_orderdetails = 341, perms_parts_prices = 341 |
65
|
|
|
WHERE (id = 1 AND name = "admins") |
66
|
|
|
OR (id = 3 AND name = "users"); |
67
|
|
|
'; |
68
|
|
|
|
69
|
|
|
$this->addSql($sql); |
70
|
|
|
|
71
|
|
|
$this->printPermissionUpdateMessage(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function mySQLDown(Schema $schema): void |
75
|
|
|
{ |
76
|
|
|
// this down() migration is auto-generated, please modify it to your needs |
77
|
|
|
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); |
78
|
|
|
|
79
|
|
|
$this->addSql('ALTER TABLE `groups` ADD perms_parts_instock SMALLINT NOT NULL, ADD perms_parts_mininstock SMALLINT NOT NULL, ADD perms_parts_storelocation SMALLINT NOT NULL, DROP perms_parts_category, DROP perms_parts_minamount, DROP perms_parts_lots, DROP perms_parts_tags, DROP perms_parts_unit, DROP perms_parts_mass, DROP perms_parts_status, DROP perms_parts_mpn, DROP perms_currencies, DROP perms_measurement_units'); |
80
|
|
|
$this->addSql('ALTER TABLE `users` DROP FOREIGN KEY FK_1483A5E938248176'); |
81
|
|
|
$this->addSql('DROP INDEX IDX_1483A5E938248176 ON `users`'); |
82
|
|
|
$this->addSql('ALTER TABLE `users` ADD config_currency VARCHAR(255) NOT NULL COLLATE utf8_general_ci, ADD perms_parts_instock SMALLINT NOT NULL, ADD perms_parts_mininstock SMALLINT NOT NULL, ADD perms_parts_storelocation SMALLINT NOT NULL, DROP currency_id, DROP settings, DROP perms_parts_category, DROP perms_parts_minamount, DROP perms_parts_lots, DROP perms_parts_tags, DROP perms_parts_unit, DROP perms_parts_mass, DROP perms_parts_status, DROP perms_parts_mpn, DROP perms_currencies, DROP perms_measurement_units'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function sqLiteUp(Schema $schema): void |
86
|
|
|
{ |
87
|
|
|
$this->skipIf(true, "Migration not needed for SQLite. Skipping..."); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function sqLiteDown(Schema $schema): void |
91
|
|
|
{ |
92
|
|
|
$this->skipIf(true, "Migration not needed for SQLite. Skipping..."); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|