Files
dpb/backend/sql/weld_pedigree_ablup.sql
34047007@qq.com b95053c52c init: 初始化 dpb 桃育种系统代码库
前后端 + 后端 FastAPI 全量源码、部署脚本与文档。
2026-08-06 00:17:49 +08:00

28 lines
1.6 KiB
SQL
Raw Permalink 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.
-- ============================================================
-- 断链焊接:系谱锚点 + 遗传力落库
-- 幂等:全部 IF NOT EXISTS。
-- 1) bre_tree 加 母本 dam_id / 父本 sire_idFK→bre_germplasm
-- —— A 矩阵的系谱锚点(单株为子代、种质为亲本)
-- 2) 按杂交组合回填现有单株的 dam/sire(组合无亲本的保持 NULL → founder
-- 3) bre_prediction 加 遗传力 heritability(§3.12
-- 注:SQLAlchemy create_all 只建新表、不改已有表,故已有库需执行本脚本一次。
-- ============================================================
-- ── 1) bre_tree:母本/父本 ──────────────────────────────
ALTER TABLE bre_tree ADD COLUMN IF NOT EXISTS dam_id INTEGER REFERENCES bre_germplasm(id) ON DELETE SET NULL;
ALTER TABLE bre_tree ADD COLUMN IF NOT EXISTS sire_id INTEGER REFERENCES bre_germplasm(id) ON DELETE SET NULL;
CREATE INDEX IF NOT EXISTS ix_bre_tree_dam ON bre_tree(dam_id);
CREATE INDEX IF NOT EXISTS ix_bre_tree_sire ON bre_tree(sire_id);
-- ── 2) 回填现有单株(组合 female/male 亲本 → 树 dam/sire)────
-- 重复执行安全:再次回填与组合同步(覆盖早期手工/旧值)。
UPDATE bre_tree t
SET dam_id = c.female_parent_id,
sire_id = c.male_parent_id
FROM bre_cross_combination c
WHERE t.combination_id = c.id
AND t.is_deleted = false;
-- ── 3) bre_prediction:遗传力 h² ─────────────────────────
ALTER TABLE bre_prediction ADD COLUMN IF NOT EXISTS heritability NUMERIC;