From 32f031b047a817e647bedd3f64e52118ecc736cb Mon Sep 17 00:00:00 2001 From: dxc Date: Thu, 12 Feb 2026 09:41:40 +0800 Subject: [PATCH] feat: add non-null and unique constraints to BOM model Co-authored-by: aider (openai/DeepSeek-V3.2-Thinking) --- inventory-backend/app/models/bom.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/inventory-backend/app/models/bom.py b/inventory-backend/app/models/bom.py index e4bd2fd..1af51f6 100644 --- a/inventory-backend/app/models/bom.py +++ b/inventory-backend/app/models/bom.py @@ -6,12 +6,16 @@ class BomTable(db.Model): id = db.Column(db.Integer, primary_key=True) parent_id = db.Column(db.Integer, db.ForeignKey('material_base.id'), nullable=False) child_id = db.Column(db.Integer, db.ForeignKey('material_base.id'), nullable=False) - bom_no = db.Column(db.String(100), comment='BOM编号') - version = db.Column(db.String(50), comment='版本') + bom_no = db.Column(db.String(100), nullable=False, comment='BOM编号') + version = db.Column(db.String(50), nullable=False, default='v1', comment='版本') dosage = db.Column(db.Numeric(19, 4), comment='个数') loss_rate = db.Column(db.Numeric(5, 2), comment='损耗率%(已废弃)', default=0, nullable=True) remark = db.Column(db.Text, comment='备注') + __table_args__ = ( + db.UniqueConstraint('bom_no', 'parent_id', 'child_id', name='uniq_bom_no_parent_child'), + ) + # relationships parent = db.relationship('MaterialBase', foreign_keys=[parent_id], backref='bom_parents') child = db.relationship('MaterialBase', foreign_keys=[child_id], backref='bom_children')