feat(server): add attachment ORM models and table provisioning
Adds 5 tables in the CargoTrace schema: attachment_category, finished_goods_attachment, finished_goods_attachment_item, finished_goods_attachment_location, finished_goods_box_attachment_item. Includes a one-off create_all script and extends test cleanup. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -34,7 +34,36 @@ def cleanup_test_data(db: Session):
|
||||
"26T998",
|
||||
"26B998",
|
||||
"26C998",
|
||||
"26BW0011",
|
||||
"26BW0012",
|
||||
]
|
||||
|
||||
# Attachment tables (order: children before parents / before shared box)
|
||||
from app.models.attachment import (
|
||||
AttachmentCategory,
|
||||
FinishedGoodsAttachment,
|
||||
FinishedGoodsAttachmentItem,
|
||||
FinishedGoodsAttachmentLocation,
|
||||
FinishedGoodsBoxAttachmentItem,
|
||||
)
|
||||
|
||||
db.query(FinishedGoodsBoxAttachmentItem).filter(
|
||||
FinishedGoodsBoxAttachmentItem.zongpai_no.in_(test_zongpai_nos)
|
||||
).delete(synchronize_session=False)
|
||||
db.query(FinishedGoodsAttachmentLocation).filter(
|
||||
FinishedGoodsAttachmentLocation.zongpai_no.in_(test_zongpai_nos)
|
||||
).delete(synchronize_session=False)
|
||||
db.query(FinishedGoodsAttachmentItem).filter(
|
||||
FinishedGoodsAttachmentItem.zongpai_no.in_(test_zongpai_nos)
|
||||
).delete(synchronize_session=False)
|
||||
db.query(FinishedGoodsAttachment).filter(
|
||||
FinishedGoodsAttachment.zongpai_no.in_(test_zongpai_nos)
|
||||
).delete(synchronize_session=False)
|
||||
db.query(AttachmentCategory).filter(
|
||||
AttachmentCategory.name.like("TEST_%")
|
||||
).delete(synchronize_session=False)
|
||||
|
||||
# Existing product cleanup (unchanged) — attachment box items for these boxes:
|
||||
db.query(FinishedGoodsLocation).filter(
|
||||
FinishedGoodsLocation.zongpai_no.in_(test_zongpai_nos)
|
||||
).delete(synchronize_session=False)
|
||||
@@ -48,6 +77,9 @@ def cleanup_test_data(db: Session):
|
||||
)
|
||||
test_box_ids = [box.id for box in test_boxes]
|
||||
if test_box_ids:
|
||||
db.query(FinishedGoodsBoxAttachmentItem).filter(
|
||||
FinishedGoodsBoxAttachmentItem.box_id.in_(test_box_ids)
|
||||
).delete(synchronize_session=False)
|
||||
db.query(FinishedGoodsBoxItem).filter(
|
||||
FinishedGoodsBoxItem.box_id.in_(test_box_ids)
|
||||
).delete(synchronize_session=False)
|
||||
|
||||
22
tests/test_attachment_models_smoke.py
Normal file
22
tests/test_attachment_models_smoke.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.models.attachment import AttachmentCategory, FinishedGoodsAttachment
|
||||
|
||||
|
||||
def test_category_round_trip(db: Session):
|
||||
cat = AttachmentCategory(name="TEST_SMOKE", sort_order=1, is_active=True)
|
||||
db.add(cat)
|
||||
db.commit()
|
||||
db.refresh(cat)
|
||||
assert cat.id is not None
|
||||
fetched = db.query(AttachmentCategory).filter_by(name="TEST_SMOKE").first()
|
||||
assert fetched is not None
|
||||
assert fetched.is_active is True
|
||||
|
||||
|
||||
def test_attachment_defaults_to_undetermined(db: Session):
|
||||
att = FinishedGoodsAttachment(zongpai_no="26BW0011")
|
||||
db.add(att)
|
||||
db.commit()
|
||||
db.refresh(att)
|
||||
assert att.determination == "undetermined"
|
||||
Reference in New Issue
Block a user