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:
Misaka_Company
2026-08-12 13:32:26 +08:00
parent eec0fd3189
commit baa841ae42
5 changed files with 248 additions and 1 deletions

View File

@@ -0,0 +1,39 @@
"""One-off: create the 5 attachment tables in the configured DB.
Run from services/fastapi/ with the venv active:
python scripts/create_attachment_tables.py
"""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from app.core.database import Base, engine # noqa: E402
from app.models.attachment import ( # noqa: E402
AttachmentCategory,
FinishedGoodsAttachment,
FinishedGoodsAttachmentItem,
FinishedGoodsAttachmentLocation,
FinishedGoodsBoxAttachmentItem,
)
NEW_TABLES = [
AttachmentCategory,
FinishedGoodsAttachment,
FinishedGoodsAttachmentItem,
FinishedGoodsAttachmentLocation,
FinishedGoodsBoxAttachmentItem,
]
def main() -> None:
Base.metadata.create_all(
engine,
tables=[t.__table__ for t in NEW_TABLES],
)
print(f"Created {len(NEW_TABLES)} attachment tables.")
if __name__ == "__main__":
main()