PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / database / Migrations / ShippingMethodsMigrator.php

ShippingMethodsMigrator.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at database/Migrations/ShippingMethodsMigrator.php

61 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\Database\Migrations;
4
5 class ShippingMethodsMigrator extends Migrator
6 {
7 public static string $tableName = 'fct_shipping_methods';
8
9 public static function getSqlSchema(): string
10 {
11 $indexPrefix = static::getDbPrefix() . 'fct_sm_';
12 return "`id` BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
13 `zone_id` BIGINT UNSIGNED NOT NULL,
14 `title` VARCHAR(192) NOT NULL,
15 `type` VARCHAR(50) NOT NULL,
16 `settings` LONGTEXT NULL,
17 `is_enabled` TINYINT(1) NOT NULL DEFAULT 1,
18 `states` json DEFAULT NULL,
19 `amount` DECIMAL(10, 2) NULL DEFAULT 0.00,
20 `order` INT UNSIGNED NOT NULL DEFAULT 0,
21 `meta` json DEFAULT NULL,
22 `created_at` DATETIME NULL,
23 `updated_at` DATETIME NULL,
24
25 INDEX `{$indexPrefix}_zone_id_idx` (`zone_id` ASC),
26 INDEX `{$indexPrefix}_order_idx` (`order` ASC)";
27 }
28
29 public static function migrated()
30 {
31 static::addStatesColumn();
32 static::modifyStatesToJson();
33 static::addMetaColumn();
34 static::changeAmountToDecimal();
35 }
36
37 public static function addStatesColumn()
38 {
39 // "ALTER TABLE %i ADD COLUMN `states` JSON NULL AFTER `is_enabled`"
40 static::addColumnIfNotExists('states', 'JSON NULL', 'is_enabled');
41 }
42
43 public static function modifyStatesToJson()
44 {
45 // "ALTER TABLE %i MODIFY COLUMN `states` JSON NULL"
46 static::modifyColumnIfExists('states', 'JSON NULL');
47 }
48
49 public static function addMetaColumn()
50 {
51 // "ALTER TABLE %i ADD COLUMN `meta` JSON NULL AFTER `order`"
52 static::addColumnIfNotExists('meta', 'JSON NULL', 'order');
53 }
54
55 public static function changeAmountToDecimal()
56 {
57 // "ALTER TABLE %i MODIFY COLUMN `amount` DECIMAL(10, 2) NULL DEFAULT 0.00"
58 static::modifyColumnIfExists('amount', 'DECIMAL(10, 2) NULL DEFAULT 0.00');
59 }
60 }
61