Files
junhong_cmp_fiber/migrations/000266_rename_outbound_to_first_purchase.up.sql
邹进 62ec94adec
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Failing after 38s
refactor: 出库时间更名为首次购买套餐时间,换货新资产不再按换货完成时间记录
- 字段 outbound_at → first_purchase_at,记录表 tb_asset_outbound_record → tb_asset_first_purchase_record,接口 /outbound-records → /first-purchase-records,筛选参数与导出列同步更名
- 换货后的新资产不因换货写入,在当前世代真正支付套餐订单时才记录;记录来源只保留 order / backfill,去掉换货单字段
- 迁移 000266 重命名列、表、索引与约束;同步 Spec、设计、任务与前端接口变更说明

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 16:47:02 +09:00

28 lines
2.7 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 出库时间更名为"首次购买套餐时间",并取消换货新资产按换货完成时间记录(add-package-silence-period)。
-- 口径:资产当前世代第一笔套餐订单(主套餐或加油包)的支付时间;换货后的新资产在当前世代真正购买套餐后才记录。
-- 设备上绑定的卡不记录;只做记录展示,不参与业务判断,不受沉默期总开关影响。
ALTER TABLE tb_iot_card RENAME COLUMN outbound_at TO first_purchase_at;
ALTER TABLE tb_device RENAME COLUMN outbound_at TO first_purchase_at;
ALTER INDEX IF EXISTS idx_iot_card_outbound_at RENAME TO idx_iot_card_first_purchase_at;
ALTER INDEX IF EXISTS idx_device_outbound_at RENAME TO idx_device_first_purchase_at;
COMMENT ON COLUMN tb_iot_card.first_purchase_at IS '首次购买套餐时间(当前世代第一笔套餐订单的支付时间;绑定在设备上的卡不记录)';
COMMENT ON COLUMN tb_device.first_purchase_at IS '首次购买套餐时间(当前世代第一笔套餐订单的支付时间)';
DELETE FROM tb_asset_outbound_record WHERE source = 'exchange';
ALTER TABLE tb_asset_outbound_record RENAME TO tb_asset_first_purchase_record;
ALTER TABLE tb_asset_first_purchase_record RENAME COLUMN outbound_at TO first_purchase_at;
ALTER TABLE tb_asset_first_purchase_record DROP COLUMN IF EXISTS exchange_order_id;
ALTER TABLE tb_asset_first_purchase_record DROP COLUMN IF EXISTS exchange_no;
ALTER TABLE tb_asset_first_purchase_record RENAME CONSTRAINT tb_asset_outbound_record_pkey TO tb_asset_first_purchase_record_pkey;
ALTER SEQUENCE IF EXISTS tb_asset_outbound_record_id_seq RENAME TO tb_asset_first_purchase_record_id_seq;
ALTER TABLE tb_asset_first_purchase_record RENAME CONSTRAINT ck_asset_outbound_asset_type TO ck_asset_first_purchase_asset_type;
ALTER TABLE tb_asset_first_purchase_record DROP CONSTRAINT IF EXISTS ck_asset_outbound_source;
ALTER TABLE tb_asset_first_purchase_record ADD CONSTRAINT ck_asset_first_purchase_source CHECK (source IN ('order', 'backfill'));
ALTER INDEX IF EXISTS uq_asset_outbound_generation RENAME TO uq_asset_first_purchase_generation;
ALTER INDEX IF EXISTS idx_asset_outbound_created RENAME TO idx_asset_first_purchase_created;
COMMENT ON TABLE tb_asset_first_purchase_record IS '资产首次购买套餐记录:每个世代一条,只新增与填写结束信息,不修改时间、不删除';
COMMENT ON COLUMN tb_asset_first_purchase_record.first_purchase_at IS '首次购买套餐时间(该世代第一笔套餐订单的支付时间)';
COMMENT ON COLUMN tb_asset_first_purchase_record.source IS '来源:order-首次购买套餐 backfill-历史回填';
COMMENT ON COLUMN tb_asset_first_purchase_record.end_reason IS '结束原因:exchange_return-换货回库(世代 +1)';