· 4 years ago · May 05, 2021, 09:56 AM
1CREATE TABLE IF NOT EXISTS `order` (
2 `id` binary(16) NOT NULL,
3 `version_id` binary(16) NOT NULL,
4 `state_id` binary(16) NOT NULL,
5 `auto_increment` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
6 `order_number` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
7 `currency_id` binary(16) NOT NULL,
8 `language_id` binary(16) NOT NULL,
9 `currency_factor` double DEFAULT NULL,
10 `sales_channel_id` binary(16) NOT NULL,
11 `billing_address_id` binary(16) NOT NULL,
12 `billing_address_version_id` binary(16) NOT NULL,
13 `price` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
14 `order_date_time` datetime(3) NOT NULL,
15 `order_date` date GENERATED ALWAYS AS (cast(`order_date_time` as date)) STORED,
16 `amount_total` double GENERATED ALWAYS AS (json_unquote(json_extract(`price`,'$.totalPrice'))) VIRTUAL,
17 `amount_net` double GENERATED ALWAYS AS (json_unquote(json_extract(`price`,'$.netPrice'))) VIRTUAL,
18 `position_price` double GENERATED ALWAYS AS (json_unquote(json_extract(`price`,'$.positionPrice'))) VIRTUAL,
19 `tax_status` varchar(255) COLLATE utf8mb4_unicode_ci GENERATED ALWAYS AS (json_unquote(json_extract(`price`,'$.taxStatus'))) VIRTUAL,
20 `shipping_costs` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
21 `shipping_total` double GENERATED ALWAYS AS (json_unquote(json_extract(`shipping_costs`,'$.totalPrice'))) VIRTUAL,
22 `deep_link_code` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
23 `custom_fields` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
24 `affiliate_code` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
25 `campaign_code` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
26 `customer_comment` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL,
27 `created_at` datetime(3) NOT NULL,
28 `updated_at` datetime(3) DEFAULT NULL,
29 `rule_ids` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
30 `created_by_id` binary(16) DEFAULT NULL,
31 `updated_by_id` binary(16) DEFAULT NULL,
32 PRIMARY KEY (`id`,`version_id`),
33 UNIQUE KEY `uniq.auto_increment` (`auto_increment`),
34 UNIQUE KEY `uniq.deep_link_code` (`deep_link_code`,`version_id`),
35 KEY `idx.state_index` (`state_id`),
36 KEY `fk.order.currency_id` (`currency_id`),
37 KEY `fk.order.sales_channel_id` (`sales_channel_id`),
38 KEY `fk.language_id` (`language_id`),
39 KEY `fk.order.created_by_id` (`created_by_id`),
40 KEY `fk.order.updated_by_id` (`updated_by_id`),
41 KEY `idx.order_date_time` (`order_date_time`),
42 KEY `idx.order_date` (`order_date`)
43) ;