· 4 years ago · Mar 04, 2021, 04:30 PM
1<?php declare(strict_types=1);
2
3namespace Swag\BundleExample\Migration;
4
5use Doctrine\DBAL\Connection;
6use Shopware\Core\Framework\Migration\InheritanceUpdaterTrait;
7use Shopware\Core\Framework\Migration\MigrationStep;
8
9class Migration1554708925Bundle extends MigrationStep
10{
11 use InheritanceUpdaterTrait;
12
13 public function getCreationTimestamp(): int
14 {
15 return 1554708925;
16 }
17
18 public function update(Connection $connection): void
19 {
20 $connection->executeUpdate('
21 CREATE TABLE IF NOT EXISTS `swag_bundle` (
22 `id` BINARY(16) NOT NULL,
23 `discount_type` VARCHAR(255) NOT NULL,
24 `discount` DOUBLE NOT NULL,
25 `created_at` DATETIME(3) NOT NULL,
26 `updated_at` DATETIME(3) NULL,
27 PRIMARY KEY (`id`)
28 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
29 ');
30
31 $connection->executeUpdate('
32 CREATE TABLE IF NOT EXISTS `swag_bundle_translation` (
33 `swag_bundle_id` BINARY(16) NOT NULL,
34 `language_id` BINARY(16) NOT NULL,
35 `name` VARCHAR(255),
36 `created_at` DATETIME(3) NOT NULL,
37 `updated_at` DATETIME(3) NULL,
38 PRIMARY KEY (`swag_bundle_id`, `language_id`),
39 CONSTRAINT `fk.bundle_translation.bundle_id` FOREIGN KEY (`swag_bundle_id`)
40 REFERENCES `swag_bundle` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
41 CONSTRAINT `fk.bundle_translation.language_id` FOREIGN KEY (`language_id`)
42 REFERENCES `language` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
43 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
44 ');
45
46 $connection->executeUpdate('
47 CREATE TABLE IF NOT EXISTS `swag_bundle_product` (
48 `bundle_id` BINARY(16) NOT NULL,
49 `product_id` BINARY(16) NOT NULL,
50 `product_version_id` BINARY(16) NOT NULL,
51 `created_at` DATETIME(3) NOT NULL,
52 PRIMARY KEY (`bundle_id`, `product_id`, `product_version_id`),
53 CONSTRAINT `fk.bundle_product.bundle_id` FOREIGN KEY (`bundle_id`)
54 REFERENCES `swag_bundle` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
55 CONSTRAINT `fk.bundle_product.product_id__product_version_id` FOREIGN KEY (`product_id`, `product_version_id`)
56 REFERENCES `product` (`id`, `version_id`) ON DELETE CASCADE ON UPDATE CASCADE
57 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
58 ');
59
60 $this->updateInheritance($connection, 'product', 'bundles');
61 }
62
63 public function updateDestructive(Connection $connection): void
64 {
65 }
66}
67