· 4 years ago · Mar 04, 2021, 04:34 PM
1<?php
2
3declare(strict_types = 1);
4
5namespace S360Experts\Migration;
6
7use Doctrine\DBAL\Connection;
8use Shopware\Core\Framework\Migration\InheritanceUpdaterTrait;
9use Shopware\Core\Framework\Migration\MigrationStep;
10
11class Migration1614796973Expert extends MigrationStep
12{
13
14 use InheritanceUpdaterTrait;
15
16 public function getCreationTimestamp(): int {
17 return 1614796973;
18 }
19
20 public function update(Connection $connection): void {
21
22 $this->createExpertTable($connection);
23 }
24
25 public function updateDestructive(Connection $connection): void {
26 // implement update destructive
27 }
28
29 private function createExpertTable($connection) {
30 $connection->executeQuery('
31 CREATE TABLE IF NOT EXISTS `s360_experts_expert` (
32 `id` BINARY(16) NOT NULL,
33 `active` BOOLEAN DEFAULT FALSE,
34 `name` MEDIUMTEXT NOT NULL,
35 `image` BINARY(32) NULL,
36 `created_at` DATETIME(3) NOT NULL,
37 `updated_at` DATETIME(3) NULL,
38 PRIMARY KEY (`id`)
39 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
40 ');
41 $connection->executeQuery('
42 CREATE TABLE IF NOT EXISTS `s360_experts_expert_translation` (
43 `s360_experts_expert_id` BINARY(16) NOT NULL,
44 `language_id` BINARY(16) NOT NULL,
45 `quote` MEDIUMTEXT NULL,
46 `created_at` DATETIME(3) NOT NULL,
47 `updated_at` DATETIME(3) NULL,
48 PRIMARY KEY (`s360_experts_expert_id`, `language_id`),
49 CONSTRAINT `fk.s360_experts_expert_translation.entity_id` FOREIGN KEY (`s360_experts_expert_id`)
50 REFERENCES `s360_experts_expert` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
51 CONSTRAINT `fk.s360_experts_expert_translation.language_id` FOREIGN KEY (`language_id`)
52 REFERENCES `language` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
53 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
54 ');
55
56 $connection->executeUpdate('
57 CREATE TABLE IF NOT EXISTS `s360_expert_product` (
58 `expert_id` BINARY(16) NOT NULL,
59 `product_id` BINARY(16) NOT NULL,
60 `product_version_id` BINARY(16) NOT NULL,
61 `created_at` DATETIME(3) NOT NULL,
62 PRIMARY KEY (`expert_id`, `product_id`, `product_version_id`),
63 CONSTRAINT `fk.expert_product.expert_id` FOREIGN KEY (`expert_id`)
64 REFERENCES `swag_bundle` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
65 CONSTRAINT `fk.expert_product.product_id__product_version_id` FOREIGN KEY (`product_id`, `product_version_id`)
66 REFERENCES `product` (`id`, `version_id`) ON DELETE CASCADE ON UPDATE CASCADE
67 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
68 ');
69
70 $this->updateInheritance($connection, 'product', 'experts');
71 }
72
73}
74