Adding sync with imported parts
This commit is contained in:
1 parent
00fb43c8ed
commit
c320595423
11 files changed
+300
-4
No files matched your search
@@ -1,6 +1,6 @@
|
||||
"""Import all models so they register with ``Base.metadata``."""
|
||||
|
||||
from app.models.associations import role_permissions, user_roles
|
||||
from app.models.associations import augmented_part_imported_parts, role_permissions, user_roles
|
||||
from app.models.audit_log import AuditLog
|
||||
from app.models.augmented_part import AugmentedPart
|
||||
from app.models.imported_part import ImportedPart
|
||||
@@ -35,6 +35,7 @@ __all__ = [
|
||||
"Role",
|
||||
"UncThread",
|
||||
"User",
|
||||
"augmented_part_imported_parts",
|
||||
"role_permissions",
|
||||
"user_roles",
|
||||
]
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Many-to-many association tables for RBAC."""
|
||||
"""Many-to-many association tables."""
|
||||
|
||||
from sqlalchemy import Column, ForeignKey, Table
|
||||
from sqlalchemy import Column, ForeignKey, String, Table
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
@@ -21,3 +21,19 @@ role_permissions = Table(
|
||||
primary_key=True,
|
||||
),
|
||||
)
|
||||
|
||||
augmented_part_imported_parts = Table(
|
||||
"augmented_part_imported_parts",
|
||||
Base.metadata,
|
||||
Column(
|
||||
"augmented_part_id",
|
||||
ForeignKey("augmented_parts.id", ondelete="CASCADE"),
|
||||
primary_key=True,
|
||||
),
|
||||
Column(
|
||||
"imported_part_id",
|
||||
String,
|
||||
ForeignKey("imported_parts.InventoryID", ondelete="CASCADE"),
|
||||
primary_key=True,
|
||||
),
|
||||
)
|
||||
@@ -2,6 +2,8 @@ from sqlalchemy import ForeignKey, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.core.database import Base
|
||||
from app.models.associations import augmented_part_imported_parts
|
||||
from app.models.imported_part import ImportedPart
|
||||
from app.models.manufacturer import Manufacturer
|
||||
from app.models.part_colour import PartColour
|
||||
from app.models.part_type import PartType
|
||||
@@ -31,6 +33,11 @@ class AugmentedPart(Base):
|
||||
ForeignKey("sub_part_types.id", ondelete="SET NULL"), nullable=True, default=None
|
||||
)
|
||||
|
||||
# linked imported parts — not eagerly loaded; used by sync service only
|
||||
imported_parts: Mapped[list[ImportedPart]] = relationship(
|
||||
secondary=augmented_part_imported_parts, lazy="select"
|
||||
)
|
||||
|
||||
colour: Mapped[PartColour] = relationship(lazy="selectin")
|
||||
manufacturer: Mapped[Manufacturer] = relationship(lazy="selectin")
|
||||
scope_model: Mapped[ScopeModel | None] = relationship(lazy="selectin")
|
||||
|
||||
Reference in new issue
Block a user