no_tax, 1 => exclusive, 2 => inclusive', `note` TEXT NOT NULL DEFAULT '', `ip_address` TEXT NOT NULL DEFAULT '', `completed_at` DATETIME NULL DEFAULT NULL, `refunded_at` DATETIME NULL DEFAULT NULL, `uuid` VARCHAR(100) NOT NULL, `config` json DEFAULT NULL, `created_at` DATETIME NULL, `updated_at` DATETIME NULL, INDEX `{$indexPrefix}_invoice_no` (`invoice_no`(191) ASC), INDEX `{$indexPrefix}_status_type` (`type` ASC), INDEX `{$indexPrefix}_customer_id` (`customer_id` ASC), INDEX `{$indexPrefix}_date_created_completed` (`created_at` ASC, `completed_at` ASC), INDEX `{$indexPrefix}_uuid` (`uuid` ASC)"; } public static function migrated() { static::addFeeTotalColumn(); static::addTaxBehaviorColumn(); static::addReceiptNumberColumn(); static::renameDiscountTotalColumn(); static::addPaymentStatusIndex(); static::addUuidIndex(); } public static function addFeeTotalColumn() { // "ALTER TABLE %i ADD COLUMN `fee_total` BIGINT NOT NULL DEFAULT '0' AFTER `shipping_total`" static::addColumnIfNotExists('fee_total', "BIGINT NOT NULL DEFAULT '0'", 'shipping_total'); } public static function addTaxBehaviorColumn() { // "ALTER TABLE %i ADD COLUMN `tax_behavior` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '...' AFTER `rate`" static::addColumnIfNotExists('tax_behavior', "TINYINT(1) NOT NULL DEFAULT 0 COMMENT '0 => no_tax, 1 => exclusive, 2 => inclusive'", 'rate'); } public static function addReceiptNumberColumn() { // "ALTER TABLE %i ADD COLUMN `receipt_number` BIGINT NULL AFTER `parent_id`" static::addColumnIfNotExists('receipt_number', 'BIGINT NULL', 'parent_id'); } public static function renameDiscountTotalColumn() { // "ALTER TABLE %i CHANGE `discount_total` `manual_discount_total` BIGINT NOT NULL DEFAULT '0'" static::renameColumnIfExists('discount_total', 'manual_discount_total', "BIGINT NOT NULL DEFAULT '0'"); } public static function addPaymentStatusIndex() { // "ALTER TABLE %i ADD INDEX `fct_payment_status` (`payment_status`, `id`)" static::addIndexIfNotExists('fct_payment_status', ['payment_status', 'id']); } public static function addUuidIndex() { // "ALTER TABLE %i ADD INDEX `{prefix}fct_ord__uuid` (`uuid`)" // Non-unique on purpose: speeds up the uuid collision check and every // by-value order lookup (receipts, webhooks, customer profile) without // enforcing a UNIQUE constraint. static::addIndexIfNotExists(static::getDbPrefix() . 'fct_ord__uuid', 'uuid'); } }