-- Migration: add pre_planting_synced_merges table
-- 预种合成树算力切换幂等标记表
-- 每当5份预种合成1棵树并签署合同后，contribution-service 完成算力切换后写入本表
CREATE TABLE "pre_planting_synced_merges" (
  "id"                     BIGSERIAL PRIMARY KEY,
  "merge_no"               VARCHAR(50)  NOT NULL,
  "account_sequence"       VARCHAR(20)  NOT NULL,
  "source_order_nos"       JSONB        NOT NULL,
  "new_source_adoption_id" BIGINT       NOT NULL,
  "swapped_at"             TIMESTAMPTZ  NOT NULL DEFAULT now(),
  "source_topic"           VARCHAR(200) NOT NULL,
  "source_offset"          BIGINT       NOT NULL,
  CONSTRAINT "pre_planting_synced_merges_merge_no_key" UNIQUE ("merge_no")
);

CREATE INDEX "pre_planting_synced_merges_account_sequence_idx"
  ON "pre_planting_synced_merges"("account_sequence");
