fix: schema.sql 迁移语句移到索引创建之前,避免 product_id 列不存在时索引创建失败

This commit is contained in:
selfrelease
2026-07-15 11:51:07 +08:00
parent fc6ba087e9
commit fdf1bb44be
+5 -5
View File
@@ -113,11 +113,6 @@ CREATE TABLE IF NOT EXISTS deal (
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_deal_salesperson ON deal(salesperson_id);
CREATE INDEX IF NOT EXISTS idx_deal_customer ON deal(customer_id);
CREATE INDEX IF NOT EXISTS idx_deal_date ON deal(deal_date);
CREATE INDEX IF NOT EXISTS idx_deal_product ON deal(product_id);
-- 迁移:为已存在的 deal 表补充 product_id 列(首次执行时若列已存在则跳过)
DO $$
BEGIN
@@ -132,6 +127,11 @@ BEGIN
END IF;
END $$;
CREATE INDEX IF NOT EXISTS idx_deal_salesperson ON deal(salesperson_id);
CREATE INDEX IF NOT EXISTS idx_deal_customer ON deal(customer_id);
CREATE INDEX IF NOT EXISTS idx_deal_date ON deal(deal_date);
CREATE INDEX IF NOT EXISTS idx_deal_product ON deal(product_id);
-- 预置产品数据(幂等)
INSERT INTO product (id, name, category, spec, price, description, positioning, selling_points, target_audience) VALUES
(1, '益童宝益生菌', '儿童益生菌', '3盒套餐', 798.00,