-- Migration: 为算力相关表添加 transfer_order_no 列
-- 背景：schema.prisma 中新增了转让订单号关联字段，但缺少对应迁移文件
-- 所有列均为可空，历史数据无需填充

-- contribution_records 表
ALTER TABLE "contribution_records"
  ADD COLUMN IF NOT EXISTS "transfer_order_no" VARCHAR(50);

-- system_contribution_records 表（如存在）
ALTER TABLE "system_contribution_records"
  ADD COLUMN IF NOT EXISTS "transfer_order_no" VARCHAR(50);

-- unallocated_contributions 表（如存在）
ALTER TABLE "unallocated_contributions"
  ADD COLUMN IF NOT EXISTS "transfer_order_no" VARCHAR(50);

-- 为新列添加索引（与 schema.prisma 中的 @@index 保持一致）
CREATE INDEX IF NOT EXISTS "contribution_records_transfer_order_no_idx"
  ON "contribution_records"("transfer_order_no");

CREATE INDEX IF NOT EXISTS "system_contribution_records_transfer_order_no_idx"
  ON "system_contribution_records"("transfer_order_no");

CREATE INDEX IF NOT EXISTS "unallocated_contributions_transfer_order_no_idx"
  ON "unallocated_contributions"("transfer_order_no");
