Passed
Branch master (bbfb46)
by Jan
22:41 queued 14:44
created

Migration1536232940SalesChannel   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 147
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 64
dl 0
loc 147
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Migration;
4
5
use Doctrine\DBAL\Connection;
6
use Shopware\Core\Framework\Migration\MigrationStep;
7
8
class Migration1536232940SalesChannel extends MigrationStep
9
{
10
    public function getCreationTimestamp(): int
11
    {
12
        return 1536232940;
13
    }
14
15
    public function update(Connection $connection): void
16
    {
17
        $sql = <<<SQL
18
            CREATE TABLE `sales_channel` (
19
              `id` BINARY(16) NOT NULL,
20
              `type_id` BINARY(16) NOT NULL,
21
              `short_name` VARCHAR(45) NULL,
22
              `configuration` JSON NULL,
23
              `access_key` VARCHAR(255) COLLATE utf8mb4_unicode_ci NOT NULL,
24
              `language_id` BINARY(16) NOT NULL,
25
              `currency_id` BINARY(16) NOT NULL,
26
              `payment_method_id` BINARY(16) NOT NULL,
27
              `shipping_method_id` BINARY(16) NOT NULL,
28
              `country_id` BINARY(16) NOT NULL,
29
              `navigation_category_id` BINARY(16) NOT NULL,
30
              `navigation_category_version_id` BINARY(16) NOT NULL,
31
              `footer_category_id` BINARY(16) NULL,
32
              `footer_category_version_id` BINARY(16) NULL,
33
              `service_category_id` BINARY(16) NULL,
34
              `service_category_version_id` BINARY(16) NULL,
35
              `active` TINYINT(1) NOT NULL DEFAULT '1',
36
              `tax_calculation_type` VARCHAR(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'vertical',
37
              `navigation_id` BINARY(16) NULL,
38
              `navigation_version_id` BINARY(16),
39
              `customer_group_id` BINARY(16) NOT NULL,
40
              `mail_header_footer_id` BINARY(16) NULL,
41
              `created_at` DATETIME(3) NOT NULL,
42
              `updated_at` DATETIME(3) NULL,
43
              PRIMARY KEY (`id`),
44
              UNIQUE `uniq.access_key` (`access_key`),
45
              CONSTRAINT `json.sales_channel.configuration` CHECK (JSON_VALID(`configuration`)),
46
              CONSTRAINT `fk.sales_channel.country_id` FOREIGN KEY (`country_id`)
47
                REFERENCES `country` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
48
              CONSTRAINT `fk.sales_channel.currency_id` FOREIGN KEY (`currency_id`)
49
                REFERENCES `currency` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
50
              CONSTRAINT `fk.sales_channel.language_id` FOREIGN KEY (`language_id`)
51
                REFERENCES `language` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
52
              CONSTRAINT `fk.sales_channel.payment_method_id` FOREIGN KEY (`payment_method_id`)
53
                REFERENCES `payment_method` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
54
              CONSTRAINT `fk.sales_channel.shipping_method_id` FOREIGN KEY (`shipping_method_id`)
55
                REFERENCES `shipping_method` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
56
              CONSTRAINT `fk.sales_channel.type_id` FOREIGN KEY (`type_id`)
57
                REFERENCES `sales_channel_type` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
58
              CONSTRAINT `fk.sales_channel.navigation_category_id` FOREIGN KEY (`navigation_category_id`, `navigation_category_version_id`)
59
                REFERENCES `category` (`id`, `version_id`) ON DELETE RESTRICT ON UPDATE CASCADE,
60
              CONSTRAINT `fk.sales_channel.footer_category_id` FOREIGN KEY (`footer_category_id`, `footer_category_version_id`)
61
                REFERENCES `category` (`id`, `version_id`) ON DELETE RESTRICT ON UPDATE CASCADE,
62
              CONSTRAINT `fk.sales_channel.service_category_id` FOREIGN KEY (`service_category_id`, `service_category_version_id`)
63
                REFERENCES `category` (`id`, `version_id`) ON DELETE RESTRICT ON UPDATE CASCADE,
64
              CONSTRAINT `fk.sales_channel.navigation_id` FOREIGN KEY (`navigation_id`, `navigation_version_id`)
65
                REFERENCES `navigation` (`id`, `version_id`) ON DELETE NO ACTION ON UPDATE CASCADE,
66
              CONSTRAINT `fk.sales_channel.customer_group_id` FOREIGN KEY (`customer_group_id`) 
67
                REFERENCES `customer_group` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
68
              CONSTRAINT `fk.sales_channel.id` FOREIGN KEY (`mail_header_footer_id`)
69
                REFERENCES `mail_header_footer` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
70
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
71
SQL;
72
73
        $connection->executeQuery($sql);
74
75
        $connection->executeQuery('
76
            CREATE TABLE `sales_channel_translation` (
77
              `sales_channel_id` BINARY(16) NOT NULL,
78
              `language_id` BINARY(16) NOT NULL,
79
              `name` VARCHAR(255) COLLATE utf8mb4_unicode_ci NULL,
80
              `custom_fields` JSON NULL,
81
              `created_at` DATETIME(3) NOT NULL,
82
              `updated_at` DATETIME(3) NULL,
83
              PRIMARY KEY (`sales_channel_id`, `language_id`),
84
              CONSTRAINT `json.sales_channel_translation.custom_fields` CHECK (JSON_VALID(`custom_fields`)),
85
              CONSTRAINT `fk.sales_channel_translation.language_id` FOREIGN KEY (`language_id`)
86
                REFERENCES `language` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
87
              CONSTRAINT `fk.sales_channel_translation.sales_channel_id` FOREIGN KEY (`sales_channel_id`)
88
                REFERENCES `sales_channel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
89
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
90
        ');
91
92
        $connection->executeQuery('
93
            CREATE TABLE `sales_channel_language` (
94
              `sales_channel_id` BINARY(16) NOT NULL,
95
              `language_id` BINARY(16) NOT NULL,
96
              PRIMARY KEY (`sales_channel_id`, `language_id`),
97
              CONSTRAINT `fk.sales_channel_language.sales_channel_id` FOREIGN KEY (`sales_channel_id`)
98
                REFERENCES `sales_channel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
99
              CONSTRAINT `fk.sales_channel_language.language_id` FOREIGN KEY (`language_id`)
100
                REFERENCES `language` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
101
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
102
        ');
103
104
        $connection->executeQuery('
105
            CREATE TABLE `sales_channel_currency` (
106
              `sales_channel_id` BINARY(16) NOT NULL,
107
              `currency_id` BINARY(16) NOT NULL,
108
              PRIMARY KEY (`sales_channel_id`, `currency_id`),
109
              CONSTRAINT `fk.sales_channel_currency.sales_channel_id` FOREIGN KEY (`sales_channel_id`)
110
                REFERENCES `sales_channel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
111
              CONSTRAINT `fk.sales_channel_currency.currency_id` FOREIGN KEY (`currency_id`)
112
                REFERENCES `currency` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
113
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
114
        ');
115
116
        $connection->executeQuery('
117
            CREATE TABLE `sales_channel_country` (
118
              `sales_channel_id` BINARY(16) NOT NULL,
119
              `country_id` BINARY(16) NOT NULL,
120
              PRIMARY KEY (`sales_channel_id`, `country_id`),
121
              CONSTRAINT `fk.sales_channel_country.sales_channel_id` FOREIGN KEY (`sales_channel_id`)
122
                REFERENCES `sales_channel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
123
              CONSTRAINT `fk.sales_channel_country.country_id` FOREIGN KEY (`country_id`)
124
                REFERENCES `country` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
125
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
126
        ');
127
128
        $connection->executeQuery('
129
            CREATE TABLE `sales_channel_shipping_method` (
130
              `sales_channel_id` BINARY(16) NOT NULL,
131
              `shipping_method_id` BINARY(16) NOT NULL,
132
              PRIMARY KEY (`sales_channel_id`, `shipping_method_id`),
133
              CONSTRAINT `fk.sales_channel_shipping_method.sales_channel_id` FOREIGN KEY (`sales_channel_id`)
134
                REFERENCES `sales_channel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
135
              CONSTRAINT `fk.sales_channel_shipping_method.shipping_method_id` FOREIGN KEY (`shipping_method_id`)
136
                REFERENCES `shipping_method` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
137
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
138
        ');
139
140
        $connection->executeQuery('
141
            CREATE TABLE `sales_channel_payment_method` (
142
              `sales_channel_id` BINARY(16) NOT NULL,
143
              `payment_method_id` BINARY(16) NOT NULL,
144
              PRIMARY KEY (`sales_channel_id`, `payment_method_id`),
145
              CONSTRAINT `fk.sales_channel_payment_method.sales_channel_id` FOREIGN KEY (`sales_channel_id`)
146
                REFERENCES `sales_channel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
147
              CONSTRAINT `fk.sales_channel_payment_method.payment_method_id` FOREIGN KEY (`payment_method_id`)
148
                REFERENCES `payment_method` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
149
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
150
        ');
151
    }
152
153
    public function updateDestructive(Connection $connection): void
154
    {
155
        // implement update destructive
156
    }
157
}
158