1198ecc556
集成分支曾把已上线的 000020_ad_bonus_minutes(#21)/000021_devices_user_scoped_uuid(#27) 两个迁移错误覆盖成 codes_lib_legacy_rename/pay_purchases,与生产(schema_migrations=21) 的实际血统冲突,导致 golang-migrate 在生产上找不到 version 21 文件而报错。 恢复为:020 ad_bonus / 021 devices / 022 codes_lib_legacy_rename / 023 pay_purchases。 生产库副本完整试跑通过:version→23,pay_purchases 建好,subscriptions CHECK 加 'pay', codes 库表就位,3 用户/3 订阅数据零丢失。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013nMthbVEmQquxBRKb9Fj8u
22 lines
1.2 KiB
SQL
22 lines
1.2 KiB
SQL
-- pay v2 接入:订阅来源扩 'pay' + 购买台账(biz_ref↔out_trade_no 映射 + webhook 幂等消费)
|
|
ALTER TABLE subscriptions MODIFY source ENUM('trial','code','pay') NOT NULL;
|
|
|
|
CREATE TABLE pay_purchases (
|
|
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
biz_ref CHAR(36) NOT NULL, -- users.uuid 冗余(webhook 兜底定位)
|
|
sku VARCHAR(64) NOT NULL, -- pay products.biz_code
|
|
out_trade_no VARCHAR(64) NOT NULL UNIQUE, -- pay 订单号 = 幂等键
|
|
method VARCHAR(32) NOT NULL, -- alipay | crypto(retry 换渠道时更新)
|
|
status ENUM('created','paid','canceled') NOT NULL DEFAULT 'created',
|
|
amount_minor BIGINT NOT NULL DEFAULT 0, -- webhook 回填,最小单位
|
|
currency VARCHAR(16) NOT NULL DEFAULT '',
|
|
channel VARCHAR(32) NOT NULL DEFAULT '',
|
|
sub_id BIGINT UNSIGNED NULL, -- 开通/延长的 subscriptions.id
|
|
paid_at DATETIME(6) NULL,
|
|
created_at DATETIME(6) NOT NULL,
|
|
updated_at DATETIME(6) NOT NULL,
|
|
INDEX idx_pay_user (user_id, created_at),
|
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|