Files
hfb_sys/backend/migrations/000065_distribution_init.sql
T
yml2213 cbd5412315 test: 后端测试从 SQLite 全面切换到 MySQL,与生产环境对齐
测试库不再使用 SQLite 内存库,改为每个测试包独立的 MySQL 库,
表结构由 backend/migrations 的真实迁移建立。

基础设施
- 新增 internal/database/testdb.go:NewTestDB() 保持原签名(28 处调用零改动),
  内部连接 MySQL 测试库,首次调用重建库并执行全部真实迁移,之后每次调用清空全表
- 库名 = 测试库基础名 + 包目录名,同包共享、跨包隔离,使 go test ./... 可并发执行
  (共用一库时各包会互相 DROP/CREATE 导致 database exists)
- 新增 NewDryRunDB():MySQL 方言 + DryRun,供断言 SQL 形态的 5 处测试使用
- 新增 AutoMigrateIfMissing():只对不存在的表 AutoMigrate,
  避免改动迁移定义的索引与约束
- 新增 scripts/prepare-test-db.sh:建库与通配授权,可重复执行
- 33 处 sqlite.Open 全部替换,26 个测试文件改用 MySQL
- 删除 46 处手写 SQLite 方言 DDL(AUTOINCREMENT / INTEGER PRIMARY KEY / TEXT),
  表统一由真实迁移建立
- go.mod 移除 gorm.io/driver/sqlite 与 mattn/go-sqlite3
- 删除生产代码里 distribution/repository.go 的 sqlite 方言分支(strftime)

对齐环境后暴露并修复的真实问题
- DATE(col) 在 MySQL 返回 DATE 类型,使 Date string 字段变成 RFC3339 时间串,
  大盘日期会带出时间部分;28 处改为 DATE_FORMAT(col, '%Y-%m-%d')
- 系统自动创建分销结算批次时 created_by 写入 0,违反指向 admin_users 的外键,
  生产会直接插入失败;改为写 NULL(新增 adminRef helper)
- MySQL DATETIME 仅到秒,静默截断 Go 侧写入的时间,
  导致租用时长计算与结算时点回读比对偏差;
  rental_orders 的 9 个业务时间列提到 DATETIME(6)
- 测试数据补齐严格模式要求的 NOT NULL 列、修正超出列长的取值、补齐外键父记录

迁移
- 000065 的 ALTER TABLE rental_orders 一并完成业务时间列精度调整,
  feature 侧不再单开迁移文件

脚本与文档
- check.sh / check-backend-coverage.sh 去掉 -p 1 串行与 SQLite 相关注释
- 更新 docs/Repository层测试补充总结.md 的测试运行说明
2026-09-10 14:34:01 +08:00

366 lines
18 KiB
SQL

-- +goose Up
-- 分销站点、规则、分账、结算,以及主站表上的租户隔离列。
-- 分成字段存百分数:收号 35、卖出 40、服务费 25。
-- 货架调价存 shelf_ratio_delta(分站 1 元兑换哈夫币比例相对主站的增量)。
-- 同时把 rental_orders 的业务时间列提到微秒精度(见下方第二条 ALTER)。
CREATE TABLE distribution_sites (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
site_code VARCHAR(64) NOT NULL,
site_name VARCHAR(128) NOT NULL,
domain VARCHAR(255) NOT NULL,
status VARCHAR(16) NOT NULL DEFAULT 'active',
display_account_enabled TINYINT(1) NOT NULL DEFAULT 1,
logo_url VARCHAR(512) NOT NULL DEFAULT '',
favicon_url VARCHAR(512) NOT NULL DEFAULT '',
banners_json TEXT NULL,
announcements_json TEXT NULL,
footer_info_json TEXT NULL,
default_support_group_id BIGINT UNSIGNED NULL,
tax_enabled TINYINT(1) NOT NULL DEFAULT 0,
tax_rate_bps BIGINT NOT NULL DEFAULT 100,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY uk_distribution_sites_code (site_code),
UNIQUE KEY uk_distribution_sites_domain (domain),
KEY idx_distribution_sites_status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='分销网站主体';
CREATE TABLE distribution_site_members (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
site_id BIGINT UNSIGNED NOT NULL,
admin_user_id BIGINT UNSIGNED NOT NULL,
member_type VARCHAR(32) NOT NULL,
status VARCHAR(16) NOT NULL DEFAULT 'active',
data_scope VARCHAR(32) NOT NULL DEFAULT 'site',
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY uk_distribution_site_member (site_id, admin_user_id),
KEY idx_distribution_site_members_admin (admin_user_id, status),
CONSTRAINT fk_distribution_site_members_site FOREIGN KEY (site_id) REFERENCES distribution_sites (id),
CONSTRAINT fk_distribution_site_members_admin FOREIGN KEY (admin_user_id) REFERENCES admin_users (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='分销网站后台成员';
CREATE TABLE distribution_site_accounts (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
site_id BIGINT UNSIGNED NOT NULL,
account_id BIGINT UNSIGNED NOT NULL,
listing_id BIGINT UNSIGNED NOT NULL,
display_status VARCHAR(16) NOT NULL DEFAULT 'enabled',
markup_amount_cent BIGINT NOT NULL DEFAULT 0,
shelf_ratio_delta DECIMAL(10,2) NOT NULL DEFAULT 0,
display_started_at DATETIME NULL,
display_ended_at DATETIME NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY uk_distribution_site_account (site_id, account_id),
KEY idx_distribution_site_accounts_listing (listing_id),
KEY idx_distribution_site_accounts_display (site_id, display_status),
CONSTRAINT fk_distribution_site_accounts_site FOREIGN KEY (site_id) REFERENCES distribution_sites (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='分销网站账号展示关系';
CREATE TABLE distribution_rule_versions (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
site_id BIGINT UNSIGNED NULL,
mode VARCHAR(32) NOT NULL,
version INT NOT NULL,
status VARCHAR(16) NOT NULL DEFAULT 'draft',
platform_receive_ratio DECIMAL(10,2) NOT NULL DEFAULT 0,
platform_sell_ratio DECIMAL(10,2) NOT NULL DEFAULT 0,
distributor_receive_ratio DECIMAL(10,2) NOT NULL DEFAULT 0,
distributor_sell_ratio DECIMAL(10,2) NOT NULL DEFAULT 0,
distributor_a_ratio DECIMAL(10,2) NOT NULL DEFAULT 0,
distributor_b_ratio DECIMAL(10,2) NOT NULL DEFAULT 0,
service_fee_value DECIMAL(12,4) NOT NULL DEFAULT 0,
service_fee_unit VARCHAR(24) NOT NULL DEFAULT 'percent',
payment_fee_bps BIGINT NOT NULL DEFAULT 50,
tax_enabled TINYINT(1) NOT NULL DEFAULT 0,
tax_rate_bps BIGINT NOT NULL DEFAULT 100,
effective_from DATETIME NOT NULL,
effective_to DATETIME NULL,
created_by BIGINT UNSIGNED NULL,
created_at DATETIME NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY uk_distribution_rule_version (site_id, mode, version),
KEY idx_distribution_rule_effective (site_id, mode, status, effective_from),
CONSTRAINT fk_distribution_rule_site FOREIGN KEY (site_id) REFERENCES distribution_sites (id),
CONSTRAINT fk_distribution_rule_admin FOREIGN KEY (created_by) REFERENCES admin_users (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='分销分账规则版本';
CREATE TABLE distribution_order_financials (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
order_id BIGINT UNSIGNED NOT NULL,
site_id BIGINT UNSIGNED NOT NULL,
rule_version_id BIGINT UNSIGNED NOT NULL,
gross_paid_amount_cent BIGINT NOT NULL DEFAULT 0,
refund_amount_cent BIGINT NOT NULL DEFAULT 0,
net_paid_amount_cent BIGINT NOT NULL DEFAULT 0,
payment_fee_bps BIGINT NOT NULL DEFAULT 50,
payment_fee_cent BIGINT NOT NULL DEFAULT 0,
service_fee_value DECIMAL(12,4) NOT NULL DEFAULT 0,
service_fee_unit VARCHAR(24) NOT NULL DEFAULT 'percent',
service_fee_cent BIGINT NOT NULL DEFAULT 0,
markup_amount_cent BIGINT NOT NULL DEFAULT 0,
tax_enabled TINYINT(1) NOT NULL DEFAULT 0,
tax_rate_bps BIGINT NOT NULL DEFAULT 100,
tax_amount_cent BIGINT NOT NULL DEFAULT 0,
split_base_amount_cent BIGINT NOT NULL DEFAULT 0,
rounding_adjustment_cent BIGINT NOT NULL DEFAULT 0,
settlement_status VARCHAR(24) NOT NULL DEFAULT 'pending',
settled_at DATETIME NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY uk_distribution_order_financial_order (order_id),
KEY idx_distribution_order_financial_site_status (site_id, settlement_status),
CONSTRAINT fk_distribution_order_financial_order FOREIGN KEY (order_id) REFERENCES rental_orders (id),
CONSTRAINT fk_distribution_order_financial_site FOREIGN KEY (site_id) REFERENCES distribution_sites (id),
CONSTRAINT fk_distribution_order_financial_rule FOREIGN KEY (rule_version_id) REFERENCES distribution_rule_versions (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='分销正常订单财务快照';
CREATE TABLE distribution_order_parties (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
order_id BIGINT UNSIGNED NOT NULL,
site_id BIGINT UNSIGNED NOT NULL,
party_role VARCHAR(32) NOT NULL,
party_type VARCHAR(16) NOT NULL,
party_id BIGINT UNSIGNED NOT NULL,
ratio DECIMAL(10,2) NOT NULL DEFAULT 0,
income_amount_cent BIGINT NOT NULL DEFAULT 0,
cost_amount_cent BIGINT NOT NULL DEFAULT 0,
profit_amount_cent BIGINT NOT NULL DEFAULT 0,
tax_amount_cent BIGINT NOT NULL DEFAULT 0,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
PRIMARY KEY (id),
KEY idx_distribution_order_parties_order (order_id),
KEY idx_distribution_order_parties_site_role (site_id, party_role),
CONSTRAINT fk_distribution_order_parties_order FOREIGN KEY (order_id) REFERENCES rental_orders (id),
CONSTRAINT fk_distribution_order_parties_site FOREIGN KEY (site_id) REFERENCES distribution_sites (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='分销订单参与方快照';
CREATE TABLE distribution_settlement_batches (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
site_id BIGINT UNSIGNED NOT NULL,
batch_no VARCHAR(64) NOT NULL,
period_start DATETIME NOT NULL,
period_end DATETIME NOT NULL,
total_amount_cent BIGINT NOT NULL DEFAULT 0,
status VARCHAR(16) NOT NULL DEFAULT 'draft',
created_by BIGINT UNSIGNED NULL,
settled_at DATETIME NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY uk_distribution_settlement_batch_no (batch_no),
KEY idx_distribution_settlement_batches_site_status (site_id, status),
CONSTRAINT fk_distribution_settlement_batches_site FOREIGN KEY (site_id) REFERENCES distribution_sites (id),
CONSTRAINT fk_distribution_settlement_batches_admin FOREIGN KEY (created_by) REFERENCES admin_users (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='分销结算批次';
CREATE TABLE distribution_settlement_items (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
batch_id BIGINT UNSIGNED NOT NULL,
order_id BIGINT UNSIGNED NOT NULL,
party_id BIGINT UNSIGNED NOT NULL,
amount_cent BIGINT NOT NULL DEFAULT 0,
status VARCHAR(16) NOT NULL DEFAULT 'pending',
created_at DATETIME NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY uk_distribution_settlement_item (batch_id, order_id, party_id),
KEY idx_distribution_settlement_items_order (order_id),
CONSTRAINT fk_distribution_settlement_items_batch FOREIGN KEY (batch_id) REFERENCES distribution_settlement_batches (id),
CONSTRAINT fk_distribution_settlement_items_order FOREIGN KEY (order_id) REFERENCES rental_orders (id),
CONSTRAINT fk_distribution_settlement_items_party FOREIGN KEY (party_id) REFERENCES distribution_order_parties (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='分销结算明细';
CREATE TABLE distribution_site_payment_channels (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
site_id BIGINT UNSIGNED NOT NULL,
config_id BIGINT UNSIGNED NOT NULL,
priority INT NOT NULL DEFAULT 0,
status VARCHAR(16) NOT NULL DEFAULT 'active',
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY uk_distribution_site_payment (site_id, config_id),
KEY idx_distribution_site_payment_status (site_id, status, priority),
CONSTRAINT fk_distribution_site_payment_site FOREIGN KEY (site_id) REFERENCES distribution_sites (id),
CONSTRAINT fk_distribution_site_payment_config FOREIGN KEY (config_id) REFERENCES payment_merchant_configs (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='分销网站收款通道绑定';
ALTER TABLE rental_orders
ADD COLUMN base_price_cent BIGINT NOT NULL DEFAULT 0 AFTER platform_fee_cent,
ADD COLUMN shelf_markup_cent BIGINT NOT NULL DEFAULT 0 AFTER base_price_cent,
ADD COLUMN markup_site_id BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER shelf_markup_cent,
ADD COLUMN shelf_ratio DECIMAL(10,2) NOT NULL DEFAULT 0 AFTER markup_site_id,
ADD COLUMN shelf_ratio_delta DECIMAL(10,2) NOT NULL DEFAULT 0 AFTER shelf_ratio,
ADD COLUMN distribution_site_id BIGINT UNSIGNED NULL AFTER source_channel,
ADD COLUMN distribution_mode VARCHAR(32) NOT NULL DEFAULT '' AFTER distribution_site_id,
ADD COLUMN distribution_rule_version_id BIGINT UNSIGNED NULL AFTER distribution_mode,
ADD KEY idx_rental_orders_markup_site (markup_site_id),
ADD KEY idx_rental_orders_distribution_site (distribution_site_id, distribution_mode),
ADD CONSTRAINT fk_rental_orders_distribution_site FOREIGN KEY (distribution_site_id) REFERENCES distribution_sites (id),
ADD CONSTRAINT fk_rental_orders_distribution_rule FOREIGN KEY (distribution_rule_version_id) REFERENCES distribution_rule_versions (id);
-- 顺带把订单业务时间列提到微秒精度:秒级 DATETIME 会静默截断 Go 侧写入的时间,
-- 影响租用时长计算与结算时点回读比对。与分销字段同表,合并成一次 ALTER。
ALTER TABLE rental_orders
MODIFY COLUMN rented_at DATETIME(6) NULL COMMENT '租用开始时间',
MODIFY COLUMN handoff_started_at DATETIME(6) NULL COMMENT '进入待号主交接的时间,用于计算交接超时',
MODIFY COLUMN growth_points_awarded_at DATETIME(6) NULL COMMENT '成长积分发放时间',
MODIFY COLUMN offline_settled_at DATETIME(6) NULL COMMENT '线下结算确认时间',
MODIFY COLUMN refunded_at DATETIME(6) NULL COMMENT '退款完成时间',
MODIFY COLUMN deposit_held_at DATETIME(6) NULL COMMENT '暂扣时间',
MODIFY COLUMN deposit_hold_released_at DATETIME(6) NULL COMMENT '押金归还时间',
MODIFY COLUMN owner_settled_at DATETIME(6) NULL COMMENT '号主结算时间',
MODIFY COLUMN settled_at DATETIME(6) NULL COMMENT '订单结算时间';
ALTER TABLE rental_listings
ADD COLUMN distribution_site_id BIGINT UNSIGNED NULL AFTER managed_admin_id,
ADD COLUMN source_channel VARCHAR(64) NOT NULL DEFAULT '' AFTER distribution_site_id,
ADD KEY idx_rental_listings_distribution_site (distribution_site_id, status);
ALTER TABLE chat_qrcode_pool
ADD COLUMN distribution_site_id BIGINT UNSIGNED NULL AFTER group_name,
ADD KEY idx_chat_qrcode_distribution_site (distribution_site_id, status),
ADD CONSTRAINT fk_chat_qrcode_distribution_site FOREIGN KEY (distribution_site_id) REFERENCES distribution_sites (id);
ALTER TABLE chat_conversations
ADD COLUMN distribution_site_id BIGINT UNSIGNED NULL AFTER listing_id,
ADD KEY idx_chat_conversations_distribution_site (distribution_site_id, status);
ALTER TABLE wallet_accounts
ADD COLUMN distribution_site_id BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER user_id,
DROP KEY uk_wallet_accounts_user_id,
ADD UNIQUE KEY uk_wallet_accounts_user_site (user_id, distribution_site_id);
ALTER TABLE wallet_ledger
ADD COLUMN distribution_site_id BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER user_id,
ADD KEY idx_wallet_ledger_user_site (user_id, distribution_site_id);
ALTER TABLE withdrawal_requests
ADD COLUMN distribution_site_id BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER user_id,
ADD KEY idx_withdrawal_user_site (user_id, distribution_site_id);
ALTER TABLE notifications
ADD COLUMN distribution_site_id BIGINT UNSIGNED NULL AFTER biz_id,
ADD KEY idx_notifications_user_site (user_id, distribution_site_id, id);
INSERT INTO permissions (code, name, resource, action) VALUES
('distribution:site_view', '查看分销网站', 'distribution', 'site_view'),
('distribution:site_manage', '管理分销网站', 'distribution', 'site_manage'),
('distribution:order_view', '查看分销订单', 'distribution', 'order_view'),
('distribution:settlement_view', '查看分销结算', 'distribution', 'settlement_view'),
('distribution:settlement_manage', '管理分销结算', 'distribution', 'settlement_manage'),
('distribution:rule_view', '查看分销规则', 'distribution', 'rule_view'),
('distribution:rule_manage', '管理分销规则', 'distribution', 'rule_manage'),
('distribution:account_view', '查看分销账号', 'distribution', 'account_view'),
('distribution:account_display', '管理分销账号展示', 'distribution', 'account_display'),
('distribution:payment_view', '查看分销支付通道', 'distribution', 'payment_view'),
('distribution:payment_manage', '管理分销支付通道', 'distribution', 'payment_manage'),
('distribution:all_view', '查看全部分销站点', 'distribution', 'all_view')
ON DUPLICATE KEY UPDATE name = VALUES(name), resource = VALUES(resource), action = VALUES(action);
INSERT IGNORE INTO role_permissions (role_id, permission_id)
SELECT r.id, p.id FROM roles r CROSS JOIN permissions p
WHERE r.code = 'super_admin' AND p.code LIKE 'distribution:%';
INSERT IGNORE INTO role_permissions (role_id, permission_id)
SELECT r.id, p.id FROM roles r CROSS JOIN permissions p
WHERE r.code IN ('ops', 'finance')
AND p.code LIKE 'distribution:%'
AND p.code <> 'distribution:all_view';
INSERT INTO distribution_rule_versions (
site_id, mode, version, status,
platform_receive_ratio, platform_sell_ratio,
distributor_receive_ratio, distributor_sell_ratio,
distributor_a_ratio, distributor_b_ratio,
service_fee_value, service_fee_unit, payment_fee_bps,
tax_enabled, tax_rate_bps, effective_from, created_at
) VALUES
(NULL, 'two_party_distributor_receive', 1, 'active', 0, 40, 35, 0, 0, 0, 25, 'percent', 50, 0, 100, NOW(), NOW()),
(NULL, 'two_party_platform_receive', 1, 'active', 35, 0, 0, 40, 0, 0, 25, 'percent', 50, 0, 100, NOW(), NOW()),
(NULL, 'three_party', 1, 'active', 0, 0, 0, 0, 35, 40, 25, 'percent', 50, 0, 100, NOW(), NOW());
-- +goose Down
ALTER TABLE notifications
DROP KEY idx_notifications_user_site,
DROP COLUMN distribution_site_id;
ALTER TABLE withdrawal_requests
DROP KEY idx_withdrawal_user_site,
DROP COLUMN distribution_site_id;
ALTER TABLE wallet_ledger
DROP KEY idx_wallet_ledger_user_site,
DROP COLUMN distribution_site_id;
DELETE FROM wallet_accounts WHERE distribution_site_id <> 0;
ALTER TABLE wallet_accounts
DROP KEY uk_wallet_accounts_user_site,
DROP COLUMN distribution_site_id,
ADD UNIQUE KEY uk_wallet_accounts_user_id (user_id);
ALTER TABLE chat_conversations
DROP KEY idx_chat_conversations_distribution_site,
DROP COLUMN distribution_site_id;
ALTER TABLE chat_qrcode_pool
DROP FOREIGN KEY fk_chat_qrcode_distribution_site,
DROP KEY idx_chat_qrcode_distribution_site,
DROP COLUMN distribution_site_id;
ALTER TABLE rental_listings
DROP KEY idx_rental_listings_distribution_site,
DROP COLUMN source_channel,
DROP COLUMN distribution_site_id;
ALTER TABLE rental_orders
MODIFY COLUMN rented_at DATETIME NULL COMMENT '租用开始时间',
MODIFY COLUMN handoff_started_at DATETIME NULL COMMENT '进入待号主交接的时间,用于计算交接超时',
MODIFY COLUMN growth_points_awarded_at DATETIME NULL COMMENT '成长积分发放时间',
MODIFY COLUMN offline_settled_at DATETIME NULL COMMENT '线下结算确认时间',
MODIFY COLUMN refunded_at DATETIME NULL COMMENT '退款完成时间',
MODIFY COLUMN deposit_held_at DATETIME NULL COMMENT '暂扣时间',
MODIFY COLUMN deposit_hold_released_at DATETIME NULL COMMENT '押金归还时间',
MODIFY COLUMN owner_settled_at DATETIME NULL COMMENT '号主结算时间',
MODIFY COLUMN settled_at DATETIME NULL COMMENT '订单结算时间';
ALTER TABLE rental_orders
DROP FOREIGN KEY fk_rental_orders_distribution_rule,
DROP FOREIGN KEY fk_rental_orders_distribution_site,
DROP KEY idx_rental_orders_distribution_site,
DROP KEY idx_rental_orders_markup_site,
DROP COLUMN distribution_rule_version_id,
DROP COLUMN distribution_mode,
DROP COLUMN distribution_site_id,
DROP COLUMN shelf_ratio_delta,
DROP COLUMN shelf_ratio,
DROP COLUMN markup_site_id,
DROP COLUMN shelf_markup_cent,
DROP COLUMN base_price_cent;
DROP TABLE IF EXISTS distribution_settlement_items;
DROP TABLE IF EXISTS distribution_settlement_batches;
DROP TABLE IF EXISTS distribution_order_financials;
DROP TABLE IF EXISTS distribution_order_parties;
DROP TABLE IF EXISTS distribution_site_payment_channels;
DROP TABLE IF EXISTS distribution_rule_versions;
DROP TABLE IF EXISTS distribution_site_accounts;
DROP TABLE IF EXISTS distribution_site_members;
DROP TABLE IF EXISTS distribution_sites;
DELETE rp FROM role_permissions rp
JOIN permissions p ON p.id = rp.permission_id
WHERE p.code LIKE 'distribution:%';
DELETE FROM permissions WHERE code LIKE 'distribution:%';