PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.26
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.26
1.6.5 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 All 48 releases
fluent-cart / database / Migrations / TaxClassesMigrator.php

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

63 lines 1.8 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
6 use FluentCart\Framework\Database\Schema;
7
8 class TaxClassesMigrator extends Migrator
9 {
10
11 public static string $tableName = 'fct_tax_classes';
12
13 public static function getSqlSchema(): string
14 {
15 $indexPrefix = static::getDbPrefix() . 'fct_tcl_';
16 return "`id` BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
17 `title` VARCHAR(192) NULL,
18 `slug` VARCHAR(100) NULL,
19 `description` longtext NULL,
20 `meta` json DEFAULT NULL,
21 `created_at` DATETIME NULL ,
22 `updated_at` DATETIME NULL";
23 }
24
25 public static function migrated()
26 {
27 static::renameCategoriesToMeta();
28 static::addMetaColumn();
29 static::addSlugColumn();
30 static::addDescriptionColumn();
31 }
32
33 public static function renameCategoriesToMeta()
34 {
35 // "ALTER TABLE %i CHANGE `categories` `meta` JSON"
36 // Only rename if categories exists and meta doesn't (avoid collision)
37 if (Schema::hasColumn('categories', static::$tableName) && !Schema::hasColumn('meta', static::$tableName)) {
38 Schema::alterTable(
39 static::$tableName,
40 "CHANGE `categories` `meta` JSON"
41 );
42 }
43 }
44
45 public static function addMetaColumn()
46 {
47 // "ALTER TABLE %i ADD COLUMN `meta` JSON"
48 static::addColumnIfNotExists('meta', 'JSON');
49 }
50
51 public static function addSlugColumn()
52 {
53 // "ALTER TABLE %i ADD COLUMN `slug` VARCHAR(100) NULL AFTER `title`"
54 static::addColumnIfNotExists('slug', 'VARCHAR(100) NULL', 'title');
55 }
56
57 public static function addDescriptionColumn()
58 {
59 // "ALTER TABLE %i ADD COLUMN `description` LONGTEXT NULL AFTER `slug`"
60 static::addColumnIfNotExists('description', 'LONGTEXT NULL', 'slug');
61 }
62 }
63