-- ============================================================
-- P1.1: germplasm 护照块（规格 §4 line 558）—— 新增 12 列
-- ------------------------------------------------------------
-- 幂等。bre_germplasm 表已由 bre_tables.sql 建好。
-- 登记号唯一（仅约束未软删记录，与 model __table_args__ 一致）。
-- ============================================================

ALTER TABLE bre_germplasm ADD COLUMN IF NOT EXISTS accession_no varchar(64);
CREATE UNIQUE INDEX IF NOT EXISTS uniq_bre_germplasm_accession_no
    ON bre_germplasm (accession_no) WHERE is_deleted = false;

ALTER TABLE bre_germplasm ADD COLUMN IF NOT EXISTS stage varchar(32);
ALTER TABLE bre_germplasm ADD COLUMN IF NOT EXISTS generation varchar(16);
ALTER TABLE bre_germplasm ADD COLUMN IF NOT EXISTS storage_type varchar(16);
ALTER TABLE bre_germplasm ADD COLUMN IF NOT EXISTS is_rootstock boolean NOT NULL DEFAULT false;
ALTER TABLE bre_germplasm ADD COLUMN IF NOT EXISTS rootstock_id integer REFERENCES bre_germplasm(id);
CREATE INDEX IF NOT EXISTS ix_bre_germplasm_rootstock_id ON bre_germplasm (rootstock_id);

ALTER TABLE bre_germplasm ADD COLUMN IF NOT EXISTS institute_code varchar(64);
ALTER TABLE bre_germplasm ADD COLUMN IF NOT EXISTS country_origin varchar(64);
ALTER TABLE bre_germplasm ADD COLUMN IF NOT EXISTS collection_site varchar(200);
ALTER TABLE bre_germplasm ADD COLUMN IF NOT EXISTS acquisition_date date;
ALTER TABLE bre_germplasm ADD COLUMN IF NOT EXISTS biological_status varchar(32);
ALTER TABLE bre_germplasm ADD COLUMN IF NOT EXISTS breeding_program varchar(128);
