|
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\Migration\AbstractMultiPlatformMigration; |
|
26
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Auto-generated Migration: Please modify to your needs! |
|
30
|
|
|
*/ |
|
31
|
|
|
final class Version1 extends AbstractMultiPlatformMigration |
|
32
|
|
|
{ |
|
33
|
|
|
public function getDescription(): string |
|
34
|
|
|
{ |
|
35
|
|
|
return 'Creates an inital empty database'; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function mySQLUp(Schema $schema): void |
|
39
|
|
|
{ |
|
40
|
|
|
//Skip if old DB is detected |
|
41
|
|
|
if ($this->getOldDBVersion() > 0) { |
|
42
|
|
|
$this->warnIf(true, 'Old Part-DB Database detected! Continue with upgrade...'); |
|
43
|
|
|
return; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$this->abortIf('mysql' !== $this->getDatabaseType(), 'Migration can only be executed safely on \'mysql\'.'); |
|
47
|
|
|
|
|
48
|
|
|
$this->addSql('CREATE TABLE `attachment_types` (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, filetype_filter LONGTEXT NOT NULL, comment LONGTEXT NOT NULL, not_selectable TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_EFAED719727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); |
|
49
|
|
|
$this->addSql('CREATE TABLE `categories` (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, partname_hint LONGTEXT NOT NULL, partname_regex LONGTEXT NOT NULL, disable_footprints TINYINT(1) NOT NULL, disable_manufacturers TINYINT(1) NOT NULL, disable_autodatasheets TINYINT(1) NOT NULL, disable_properties TINYINT(1) NOT NULL, default_description LONGTEXT NOT NULL, default_comment LONGTEXT NOT NULL, comment LONGTEXT NOT NULL, not_selectable TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_3AF34668727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); |
|
50
|
|
|
$this->addSql('CREATE TABLE currencies (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, iso_code VARCHAR(255) NOT NULL, exchange_rate NUMERIC(11, 5) DEFAULT NULL, comment LONGTEXT NOT NULL, not_selectable TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_37C44693727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); |
|
51
|
|
|
$this->addSql('CREATE TABLE `devices` (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, order_quantity INT NOT NULL, order_only_missing_parts TINYINT(1) NOT NULL, comment LONGTEXT NOT NULL, not_selectable TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_11074E9A727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); |
|
52
|
|
|
$this->addSql('CREATE TABLE `footprints` (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, filename LONGTEXT NOT NULL, filename_3d LONGTEXT NOT NULL, comment LONGTEXT NOT NULL, not_selectable TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_A34D68A2727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); |
|
53
|
|
|
$this->addSql('CREATE TABLE `manufacturers` (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, address VARCHAR(255) NOT NULL, phone_number VARCHAR(255) NOT NULL, fax_number VARCHAR(255) NOT NULL, email_address VARCHAR(255) NOT NULL, website VARCHAR(255) NOT NULL, auto_product_url VARCHAR(255) NOT NULL, comment LONGTEXT NOT NULL, not_selectable TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_94565B12727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); |
|
54
|
|
|
$this->addSql('CREATE TABLE `measurement_units` (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, unit VARCHAR(255) DEFAULT NULL, is_integer TINYINT(1) NOT NULL, use_si_prefix TINYINT(1) NOT NULL, comment LONGTEXT NOT NULL, not_selectable TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_F5AF83CF727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); |
|
55
|
|
|
$this->addSql('CREATE TABLE `storelocations` (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, storage_type_id INT DEFAULT NULL, is_full TINYINT(1) NOT NULL, only_single_part TINYINT(1) NOT NULL, limit_to_existing_parts TINYINT(1) NOT NULL, comment LONGTEXT NOT NULL, not_selectable TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_7517020727ACA70 (parent_id), INDEX IDX_7517020B270BFF1 (storage_type_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); |
|
56
|
|
|
$this->addSql('CREATE TABLE `suppliers` (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, default_currency_id INT DEFAULT NULL, shipping_costs NUMERIC(11, 5) DEFAULT NULL, address VARCHAR(255) NOT NULL, phone_number VARCHAR(255) NOT NULL, fax_number VARCHAR(255) NOT NULL, email_address VARCHAR(255) NOT NULL, website VARCHAR(255) NOT NULL, auto_product_url VARCHAR(255) NOT NULL, comment LONGTEXT NOT NULL, not_selectable TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_AC28B95C727ACA70 (parent_id), INDEX IDX_AC28B95CECD792C0 (default_currency_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); |
|
57
|
|
|
$this->addSql('CREATE TABLE `attachments` (id INT AUTO_INCREMENT NOT NULL, type_id INT DEFAULT NULL, element_id INT NOT NULL, show_in_table TINYINT(1) NOT NULL, filename VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, class_name VARCHAR(255) NOT NULL, INDEX IDX_47C4FAD6C54C8C93 (type_id), INDEX IDX_47C4FAD61F1F2A24 (element_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); |
|
58
|
|
|
$this->addSql('CREATE TABLE `parts` (id INT AUTO_INCREMENT NOT NULL, id_category INT NOT NULL, id_footprint INT DEFAULT NULL, id_manufacturer INT DEFAULT NULL, id_master_picture_attachement INT DEFAULT NULL, order_orderdetails_id INT DEFAULT NULL, id_part_unit INT DEFAULT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, name VARCHAR(255) NOT NULL, description LONGTEXT NOT NULL, minamount DOUBLE PRECISION NOT NULL, comment LONGTEXT NOT NULL, visible TINYINT(1) NOT NULL, favorite TINYINT(1) NOT NULL, order_quantity INT NOT NULL, manual_order TINYINT(1) NOT NULL, manufacturer_product_url VARCHAR(255) NOT NULL, manufacturer_product_number VARCHAR(255) NOT NULL, manufacturing_status VARCHAR(255) DEFAULT NULL, needs_review TINYINT(1) NOT NULL, tags LONGTEXT NOT NULL, mass DOUBLE PRECISION DEFAULT NULL, INDEX IDX_6940A7FE5697F554 (id_category), INDEX IDX_6940A7FE7E371A10 (id_footprint), INDEX IDX_6940A7FE1ECB93AE (id_manufacturer), INDEX IDX_6940A7FEEBBCC786 (id_master_picture_attachement), UNIQUE INDEX UNIQ_6940A7FE81081E9B (order_orderdetails_id), INDEX IDX_6940A7FE2626CEF9 (id_part_unit), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); |
|
59
|
|
|
$this->addSql('CREATE TABLE `users` (id INT AUTO_INCREMENT NOT NULL, group_id INT DEFAULT NULL, name VARCHAR(180) NOT NULL, password VARCHAR(255) DEFAULT NULL, need_pw_change TINYINT(1) NOT NULL, first_name VARCHAR(255) DEFAULT NULL, last_name VARCHAR(255) DEFAULT NULL, department VARCHAR(255) DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, config_language VARCHAR(255) DEFAULT NULL, config_timezone VARCHAR(255) DEFAULT NULL, config_theme VARCHAR(255) DEFAULT NULL, config_currency VARCHAR(255) NOT NULL, config_image_path LONGTEXT NOT NULL, config_instock_comment_w LONGTEXT NOT NULL, config_instock_comment_a LONGTEXT NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, perms_system INT NOT NULL, perms_groups INT NOT NULL, perms_users INT NOT NULL, perms_self INT NOT NULL, perms_system_config INT NOT NULL, perms_system_database INT NOT NULL, perms_parts BIGINT NOT NULL, perms_parts_name SMALLINT NOT NULL, perms_parts_description SMALLINT NOT NULL, perms_parts_instock SMALLINT NOT NULL, perms_parts_mininstock SMALLINT NOT NULL, perms_parts_footprint SMALLINT NOT NULL, perms_parts_storelocation SMALLINT NOT NULL, perms_parts_manufacturer SMALLINT NOT NULL, perms_parts_comment SMALLINT NOT NULL, perms_parts_order SMALLINT NOT NULL, perms_parts_orderdetails SMALLINT NOT NULL, perms_parts_prices SMALLINT NOT NULL, perms_parts_attachements SMALLINT NOT NULL, perms_devices INT NOT NULL, perms_devices_parts INT NOT NULL, perms_storelocations INT NOT NULL, perms_footprints INT NOT NULL, perms_categories INT NOT NULL, perms_suppliers INT NOT NULL, perms_manufacturers INT NOT NULL, perms_attachement_types INT NOT NULL, perms_tools INT NOT NULL, perms_labels INT NOT NULL, UNIQUE INDEX UNIQ_1483A5E95E237E06 (name), INDEX IDX_1483A5E9FE54D947 (group_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); |
|
60
|
|
|
$this->addSql('CREATE TABLE `device_parts` (id INT AUTO_INCREMENT NOT NULL, id_device INT DEFAULT NULL, id_part INT DEFAULT NULL, quantity INT NOT NULL, mountnames LONGTEXT NOT NULL, INDEX IDX_AFC547992F180363 (id_device), INDEX IDX_AFC54799C22F6CC4 (id_part), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); |
|
61
|
|
|
$this->addSql('CREATE TABLE part_lots (id INT AUTO_INCREMENT NOT NULL, id_store_location INT DEFAULT NULL, id_part INT NOT NULL, description LONGTEXT NOT NULL, comment LONGTEXT NOT NULL, expiration_date DATETIME DEFAULT NULL, instock_unknown TINYINT(1) NOT NULL, amount DOUBLE PRECISION NOT NULL, needs_refill TINYINT(1) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_EBC8F9435D8F4B37 (id_store_location), INDEX IDX_EBC8F943C22F6CC4 (id_part), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); |
|
62
|
|
|
$this->addSql('CREATE TABLE `orderdetails` (id INT AUTO_INCREMENT NOT NULL, part_id INT NOT NULL, id_supplier INT DEFAULT NULL, supplierpartnr VARCHAR(255) NOT NULL, obsolete TINYINT(1) NOT NULL, supplier_product_url VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_489AFCDC4CE34BEC (part_id), INDEX IDX_489AFCDCCBF180EB (id_supplier), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); |
|
63
|
|
|
$this->addSql('CREATE TABLE `pricedetails` (id INT AUTO_INCREMENT NOT NULL, orderdetails_id INT NOT NULL, id_currency INT DEFAULT NULL, price NUMERIC(11, 5) NOT NULL, price_related_quantity DOUBLE PRECISION NOT NULL, min_discount_quantity DOUBLE PRECISION NOT NULL, manual_input TINYINT(1) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_C68C44594A01DDC7 (orderdetails_id), INDEX IDX_C68C4459398D64AA (id_currency), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); |
|
64
|
|
|
$this->addSql('CREATE TABLE `groups` (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, comment LONGTEXT NOT NULL, not_selectable TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, perms_system INT NOT NULL, perms_groups INT NOT NULL, perms_users INT NOT NULL, perms_self INT NOT NULL, perms_system_config INT NOT NULL, perms_system_database INT NOT NULL, perms_parts BIGINT NOT NULL, perms_parts_name SMALLINT NOT NULL, perms_parts_description SMALLINT NOT NULL, perms_parts_instock SMALLINT NOT NULL, perms_parts_mininstock SMALLINT NOT NULL, perms_parts_footprint SMALLINT NOT NULL, perms_parts_storelocation SMALLINT NOT NULL, perms_parts_manufacturer SMALLINT NOT NULL, perms_parts_comment SMALLINT NOT NULL, perms_parts_order SMALLINT NOT NULL, perms_parts_orderdetails SMALLINT NOT NULL, perms_parts_prices SMALLINT NOT NULL, perms_parts_attachements SMALLINT NOT NULL, perms_devices INT NOT NULL, perms_devices_parts INT NOT NULL, perms_storelocations INT NOT NULL, perms_footprints INT NOT NULL, perms_categories INT NOT NULL, perms_suppliers INT NOT NULL, perms_manufacturers INT NOT NULL, perms_attachement_types INT NOT NULL, perms_tools INT NOT NULL, perms_labels INT NOT NULL, INDEX IDX_F06D3970727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); |
|
65
|
|
|
$this->addSql('ALTER TABLE `attachment_types` ADD CONSTRAINT FK_EFAED719727ACA70 FOREIGN KEY (parent_id) REFERENCES `attachment_types` (id)'); |
|
66
|
|
|
$this->addSql('ALTER TABLE `categories` ADD CONSTRAINT FK_3AF34668727ACA70 FOREIGN KEY (parent_id) REFERENCES `categories` (id)'); |
|
67
|
|
|
$this->addSql('ALTER TABLE currencies ADD CONSTRAINT FK_37C44693727ACA70 FOREIGN KEY (parent_id) REFERENCES currencies (id)'); |
|
68
|
|
|
$this->addSql('ALTER TABLE `devices` ADD CONSTRAINT FK_11074E9A727ACA70 FOREIGN KEY (parent_id) REFERENCES `devices` (id)'); |
|
69
|
|
|
$this->addSql('ALTER TABLE `footprints` ADD CONSTRAINT FK_A34D68A2727ACA70 FOREIGN KEY (parent_id) REFERENCES `footprints` (id)'); |
|
70
|
|
|
$this->addSql('ALTER TABLE `manufacturers` ADD CONSTRAINT FK_94565B12727ACA70 FOREIGN KEY (parent_id) REFERENCES `manufacturers` (id)'); |
|
71
|
|
|
$this->addSql('ALTER TABLE `measurement_units` ADD CONSTRAINT FK_F5AF83CF727ACA70 FOREIGN KEY (parent_id) REFERENCES `measurement_units` (id)'); |
|
72
|
|
|
$this->addSql('ALTER TABLE `storelocations` ADD CONSTRAINT FK_7517020727ACA70 FOREIGN KEY (parent_id) REFERENCES `storelocations` (id)'); |
|
73
|
|
|
$this->addSql('ALTER TABLE `storelocations` ADD CONSTRAINT FK_7517020B270BFF1 FOREIGN KEY (storage_type_id) REFERENCES `measurement_units` (id)'); |
|
74
|
|
|
$this->addSql('ALTER TABLE `suppliers` ADD CONSTRAINT FK_AC28B95C727ACA70 FOREIGN KEY (parent_id) REFERENCES `suppliers` (id)'); |
|
75
|
|
|
$this->addSql('ALTER TABLE `suppliers` ADD CONSTRAINT FK_AC28B95CECD792C0 FOREIGN KEY (default_currency_id) REFERENCES currencies (id)'); |
|
76
|
|
|
$this->addSql('ALTER TABLE `attachments` ADD CONSTRAINT FK_47C4FAD6C54C8C93 FOREIGN KEY (type_id) REFERENCES `attachment_types` (id)'); |
|
77
|
|
|
$this->addSql('ALTER TABLE `attachments` ADD CONSTRAINT FK_47C4FAD61F1F2A24 FOREIGN KEY (element_id) REFERENCES `parts` (id) ON DELETE CASCADE'); |
|
78
|
|
|
$this->addSql('ALTER TABLE `parts` ADD CONSTRAINT FK_6940A7FE5697F554 FOREIGN KEY (id_category) REFERENCES `categories` (id)'); |
|
79
|
|
|
$this->addSql('ALTER TABLE `parts` ADD CONSTRAINT FK_6940A7FE7E371A10 FOREIGN KEY (id_footprint) REFERENCES `footprints` (id)'); |
|
80
|
|
|
$this->addSql('ALTER TABLE `parts` ADD CONSTRAINT FK_6940A7FE1ECB93AE FOREIGN KEY (id_manufacturer) REFERENCES `manufacturers` (id)'); |
|
81
|
|
|
$this->addSql('ALTER TABLE `parts` ADD CONSTRAINT FK_6940A7FEEBBCC786 FOREIGN KEY (id_master_picture_attachement) REFERENCES `attachments` (id)'); |
|
82
|
|
|
$this->addSql('ALTER TABLE `parts` ADD CONSTRAINT FK_6940A7FE81081E9B FOREIGN KEY (order_orderdetails_id) REFERENCES `orderdetails` (id)'); |
|
83
|
|
|
$this->addSql('ALTER TABLE `parts` ADD CONSTRAINT FK_6940A7FE2626CEF9 FOREIGN KEY (id_part_unit) REFERENCES `measurement_units` (id)'); |
|
84
|
|
|
$this->addSql('ALTER TABLE `users` ADD CONSTRAINT FK_1483A5E9FE54D947 FOREIGN KEY (group_id) REFERENCES `groups` (id)'); |
|
85
|
|
|
$this->addSql('ALTER TABLE `device_parts` ADD CONSTRAINT FK_AFC547992F180363 FOREIGN KEY (id_device) REFERENCES `devices` (id)'); |
|
86
|
|
|
$this->addSql('ALTER TABLE `device_parts` ADD CONSTRAINT FK_AFC54799C22F6CC4 FOREIGN KEY (id_part) REFERENCES `parts` (id)'); |
|
87
|
|
|
$this->addSql('ALTER TABLE part_lots ADD CONSTRAINT FK_EBC8F9435D8F4B37 FOREIGN KEY (id_store_location) REFERENCES `storelocations` (id)'); |
|
88
|
|
|
$this->addSql('ALTER TABLE part_lots ADD CONSTRAINT FK_EBC8F943C22F6CC4 FOREIGN KEY (id_part) REFERENCES `parts` (id) ON DELETE CASCADE'); |
|
89
|
|
|
$this->addSql('ALTER TABLE `orderdetails` ADD CONSTRAINT FK_489AFCDC4CE34BEC FOREIGN KEY (part_id) REFERENCES `parts` (id) ON DELETE CASCADE'); |
|
90
|
|
|
$this->addSql('ALTER TABLE `orderdetails` ADD CONSTRAINT FK_489AFCDCCBF180EB FOREIGN KEY (id_supplier) REFERENCES `suppliers` (id)'); |
|
91
|
|
|
$this->addSql('ALTER TABLE `pricedetails` ADD CONSTRAINT FK_C68C44594A01DDC7 FOREIGN KEY (orderdetails_id) REFERENCES `orderdetails` (id) ON DELETE CASCADE'); |
|
92
|
|
|
$this->addSql('ALTER TABLE `pricedetails` ADD CONSTRAINT FK_C68C4459398D64AA FOREIGN KEY (id_currency) REFERENCES currencies (id)'); |
|
93
|
|
|
$this->addSql('ALTER TABLE `groups` ADD CONSTRAINT FK_F06D3970727ACA70 FOREIGN KEY (parent_id) REFERENCES `groups` (id)'); |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* IGNORE is important here, or we get errors on MySQL 5.7 or higher. |
|
97
|
|
|
* TODO: Maybe find a better way (like explicitly define default value), so we can use the strict mode. |
|
98
|
|
|
*/ |
|
99
|
|
|
|
|
100
|
|
|
//Create table for user logs: |
|
101
|
|
|
$sql = $updateSteps[] = 'CREATE TABLE `log` '. |
|
|
|
|
|
|
102
|
|
|
'( `id` INT NOT NULL AUTO_INCREMENT , `datetime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() ,'. |
|
103
|
|
|
' `id_user` INT NOT NULL ,'. |
|
104
|
|
|
' `level` TINYINT NOT NULL ,'. |
|
105
|
|
|
' `type` SMALLINT NOT NULL ,'. |
|
106
|
|
|
' `target_id` INT NOT NULL ,'. |
|
107
|
|
|
' `target_type` SMALLINT NOT NULL ,'. |
|
108
|
|
|
' `extra` MEDIUMTEXT NOT NULL ,'. |
|
109
|
|
|
' PRIMARY KEY (`id`),'. |
|
110
|
|
|
' INDEX (`id_user`)) ENGINE = InnoDB;'; |
|
111
|
|
|
$this->addSql($sql); |
|
112
|
|
|
//Create first groups and users: |
|
113
|
|
|
//Add needed groups. |
|
114
|
|
|
$sql = <<<'EOD' |
|
115
|
|
|
INSERT IGNORE INTO `groups` |
|
116
|
|
|
(`id`,`name`,`parent_id`,`comment`,`perms_system`,`perms_groups`, |
|
117
|
|
|
`perms_users`, |
|
118
|
|
|
`perms_self`,`perms_system_config`,`perms_system_database`, |
|
119
|
|
|
`perms_parts`,`perms_parts_name`,`perms_parts_description`, |
|
120
|
|
|
`perms_parts_instock`,`perms_parts_mininstock`, |
|
121
|
|
|
`perms_parts_footprint`,`perms_parts_storelocation`, |
|
122
|
|
|
`perms_parts_manufacturer`,`perms_parts_comment`, |
|
123
|
|
|
`perms_parts_order`,`perms_parts_orderdetails`,`perms_parts_prices` |
|
124
|
|
|
,`perms_parts_attachements`,`perms_devices`,`perms_devices_parts`, |
|
125
|
|
|
`perms_storelocations`,`perms_footprints`,`perms_categories`, |
|
126
|
|
|
`perms_suppliers`,`perms_manufacturers`,`perms_attachement_types`, |
|
127
|
|
|
`perms_tools`) |
|
128
|
|
|
VALUES (1, 'admins', NULL, 'Users of this group can do everything: Read, Write and Administrative actions.', |
|
129
|
|
|
21, 1365, 87381, 85, 85, 21, 1431655765, 5, 5, 5, 5, 5, 5, 5, 5, 5, 325, 325, 325, 5461, 325, 5461, 5461, |
|
130
|
|
|
5461, 5461, 5461, 1365, 1365), |
|
131
|
|
|
(2, 'readonly', NULL, |
|
132
|
|
|
'Users of this group can only read informations, use tools, and don\'t have access to administrative tools.', |
|
133
|
|
|
42, 2730, 174762, 154, 170, 42, -1516939607, 9, 9, 9, 9, 9, 9, 9, 9, 9, 649, 649, 649, 1705, 649, 1705, 1705, |
|
134
|
|
|
1705, 1705, 1705, 681, 1366), |
|
135
|
|
|
(3, 'users', NULL, |
|
136
|
|
|
'Users of this group, can edit part informations, create new ones, etc. but are not allowed to use administrative tools. (But can read current configuration, and see Server status)', |
|
137
|
|
|
42, 2730, 109226, 89, 105, 41, 1431655765, 5, 5, 5, 5, 5, 5, 5, 5, 5, 325, 325, 325, 5461, 325, 5461, 5461, 5461, |
|
138
|
|
|
5461, 5461, 1365, 1365); |
|
139
|
|
|
EOD; |
|
140
|
|
|
$this->addSql($sql); |
|
141
|
|
|
$admin_pw = $this->getInitalAdminPW(); |
|
142
|
|
|
$sql = <<<EOD |
|
143
|
|
|
INSERT IGNORE INTO `users` |
|
144
|
|
|
(`id`,`name`,`password`,`first_name`,`last_name`,`department`, |
|
145
|
|
|
`email`, |
|
146
|
|
|
`need_pw_change`,`group_id`,`perms_system`,`perms_groups`, |
|
147
|
|
|
`perms_users`,`perms_self`,`perms_system_config`, |
|
148
|
|
|
`perms_system_database`,`perms_parts`,`perms_parts_name`, |
|
149
|
|
|
`perms_parts_description`,`perms_parts_instock`, |
|
150
|
|
|
`perms_parts_mininstock`,`perms_parts_footprint`, |
|
151
|
|
|
`perms_parts_storelocation`,`perms_parts_manufacturer`, |
|
152
|
|
|
`perms_parts_comment`,`perms_parts_order`, |
|
153
|
|
|
`perms_parts_orderdetails`,`perms_parts_prices`, |
|
154
|
|
|
`perms_parts_attachements`,`perms_devices`,`perms_devices_parts`, |
|
155
|
|
|
`perms_storelocations`,`perms_footprints`,`perms_categories`, |
|
156
|
|
|
`perms_suppliers`,`perms_manufacturers`,`perms_attachement_types`, |
|
157
|
|
|
`perms_tools`) |
|
158
|
|
|
VALUES (1,'anonymous','','','','','',0,2,21844,20480,0,0,0,0,0,21840,21840, |
|
159
|
|
|
21840,21840, |
|
160
|
|
|
21840,21840,21840,21840,21840,21520,21520,21520,20480,21520,20480, |
|
161
|
|
|
20480,20480,20480,20480,21504,20480), |
|
162
|
|
|
( |
|
163
|
|
|
2,'admin', '${admin_pw}','','', |
|
164
|
|
|
'','',1,1,21845,21845,21845,21,85,21,349525,21845,21845,21845,21845 |
|
165
|
|
|
,21845,21845,21845,21845,21845,21845,21845,21845,21845,21845,21845, |
|
166
|
|
|
21845,21845,21845,21845,21845,21845); |
|
167
|
|
|
EOD; |
|
168
|
|
|
$this->addSql($sql); |
|
169
|
|
|
//Allow users and admins full use of labels. readonly can not write/delete profiles. |
|
170
|
|
|
$this->addSql("UPDATE `groups` SET `perms_labels` = '85' WHERE `groups`.`id` = 1;"); |
|
171
|
|
|
$this->addSql("UPDATE `groups` SET `perms_labels` = '165' WHERE `groups`.`id` = 2;"); |
|
172
|
|
|
$this->addSql("UPDATE `groups` SET `perms_labels` = '85' WHERE `groups`.`id` = 3;"); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
public function mySQLDown(Schema $schema): void |
|
176
|
|
|
{ |
|
177
|
|
|
// this down() migration is auto-generated, please modify it to your needs |
|
178
|
|
|
$this->abortIf('mysql' !== $this->getDatabaseType(), 'Migration can only be executed safely on \'mysql\'.'); |
|
179
|
|
|
|
|
180
|
|
|
$this->addSql('ALTER TABLE `attachment_types` DROP FOREIGN KEY FK_EFAED719727ACA70'); |
|
181
|
|
|
$this->addSql('ALTER TABLE `attachments` DROP FOREIGN KEY FK_47C4FAD6C54C8C93'); |
|
182
|
|
|
$this->addSql('ALTER TABLE `categories` DROP FOREIGN KEY FK_3AF34668727ACA70'); |
|
183
|
|
|
$this->addSql('ALTER TABLE `parts` DROP FOREIGN KEY FK_6940A7FE5697F554'); |
|
184
|
|
|
$this->addSql('ALTER TABLE currencies DROP FOREIGN KEY FK_37C44693727ACA70'); |
|
185
|
|
|
$this->addSql('ALTER TABLE `suppliers` DROP FOREIGN KEY FK_AC28B95CECD792C0'); |
|
186
|
|
|
$this->addSql('ALTER TABLE `pricedetails` DROP FOREIGN KEY FK_C68C4459398D64AA'); |
|
187
|
|
|
$this->addSql('ALTER TABLE `devices` DROP FOREIGN KEY FK_11074E9A727ACA70'); |
|
188
|
|
|
$this->addSql('ALTER TABLE `device_parts` DROP FOREIGN KEY FK_AFC547992F180363'); |
|
189
|
|
|
$this->addSql('ALTER TABLE `footprints` DROP FOREIGN KEY FK_A34D68A2727ACA70'); |
|
190
|
|
|
$this->addSql('ALTER TABLE `parts` DROP FOREIGN KEY FK_6940A7FE7E371A10'); |
|
191
|
|
|
$this->addSql('ALTER TABLE `manufacturers` DROP FOREIGN KEY FK_94565B12727ACA70'); |
|
192
|
|
|
$this->addSql('ALTER TABLE `parts` DROP FOREIGN KEY FK_6940A7FE1ECB93AE'); |
|
193
|
|
|
$this->addSql('ALTER TABLE `measurement_units` DROP FOREIGN KEY FK_F5AF83CF727ACA70'); |
|
194
|
|
|
$this->addSql('ALTER TABLE `storelocations` DROP FOREIGN KEY FK_7517020B270BFF1'); |
|
195
|
|
|
$this->addSql('ALTER TABLE `parts` DROP FOREIGN KEY FK_6940A7FE2626CEF9'); |
|
196
|
|
|
$this->addSql('ALTER TABLE `storelocations` DROP FOREIGN KEY FK_7517020727ACA70'); |
|
197
|
|
|
$this->addSql('ALTER TABLE part_lots DROP FOREIGN KEY FK_EBC8F9435D8F4B37'); |
|
198
|
|
|
$this->addSql('ALTER TABLE `suppliers` DROP FOREIGN KEY FK_AC28B95C727ACA70'); |
|
199
|
|
|
$this->addSql('ALTER TABLE `orderdetails` DROP FOREIGN KEY FK_489AFCDCCBF180EB'); |
|
200
|
|
|
$this->addSql('ALTER TABLE `parts` DROP FOREIGN KEY FK_6940A7FEEBBCC786'); |
|
201
|
|
|
$this->addSql('ALTER TABLE `attachments` DROP FOREIGN KEY FK_47C4FAD61F1F2A24'); |
|
202
|
|
|
$this->addSql('ALTER TABLE `device_parts` DROP FOREIGN KEY FK_AFC54799C22F6CC4'); |
|
203
|
|
|
$this->addSql('ALTER TABLE part_lots DROP FOREIGN KEY FK_EBC8F943C22F6CC4'); |
|
204
|
|
|
$this->addSql('ALTER TABLE `orderdetails` DROP FOREIGN KEY FK_489AFCDC4CE34BEC'); |
|
205
|
|
|
$this->addSql('ALTER TABLE `parts` DROP FOREIGN KEY FK_6940A7FE81081E9B'); |
|
206
|
|
|
$this->addSql('ALTER TABLE `pricedetails` DROP FOREIGN KEY FK_C68C44594A01DDC7'); |
|
207
|
|
|
$this->addSql('ALTER TABLE `users` DROP FOREIGN KEY FK_1483A5E9FE54D947'); |
|
208
|
|
|
$this->addSql('ALTER TABLE `groups` DROP FOREIGN KEY FK_F06D3970727ACA70'); |
|
209
|
|
|
$this->addSql('DROP TABLE `attachment_types`'); |
|
210
|
|
|
$this->addSql('DROP TABLE `categories`'); |
|
211
|
|
|
$this->addSql('DROP TABLE currencies'); |
|
212
|
|
|
$this->addSql('DROP TABLE `devices`'); |
|
213
|
|
|
$this->addSql('DROP TABLE `footprints`'); |
|
214
|
|
|
$this->addSql('DROP TABLE `manufacturers`'); |
|
215
|
|
|
$this->addSql('DROP TABLE `measurement_units`'); |
|
216
|
|
|
$this->addSql('DROP TABLE `storelocations`'); |
|
217
|
|
|
$this->addSql('DROP TABLE `suppliers`'); |
|
218
|
|
|
$this->addSql('DROP TABLE `attachments`'); |
|
219
|
|
|
$this->addSql('DROP TABLE `parts`'); |
|
220
|
|
|
$this->addSql('DROP TABLE `users`'); |
|
221
|
|
|
$this->addSql('DROP TABLE `device_parts`'); |
|
222
|
|
|
$this->addSql('DROP TABLE part_lots'); |
|
223
|
|
|
$this->addSql('DROP TABLE `orderdetails`'); |
|
224
|
|
|
$this->addSql('DROP TABLE `pricedetails`'); |
|
225
|
|
|
$this->addSql('DROP TABLE `groups`'); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
|
|
229
|
|
|
public function sqLiteUp(Schema $schema): void |
|
230
|
|
|
{ |
|
231
|
|
|
$this->warnIf(true, "Migration not needed for SQLite. Skipping..."); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
public function sqLiteDown(Schema $schema): void |
|
235
|
|
|
{ |
|
236
|
|
|
$this->warnIf(true, "Migration not needed for SQLite. Skipping..."); |
|
237
|
|
|
} |
|
238
|
|
|
} |
|
239
|
|
|
|