Refactor model imports and add nullable indices for improved database performance and clarity
This commit is contained in:
parent
704638d07a
commit
dab23009c1
5 changed files with 43 additions and 43 deletions
|
@ -24,17 +24,17 @@ class Inventory(db.Model, ImageAttachable):
|
|||
id: Mapped[int] = mapped_column(Integer, Identity(start=1, increment=1), primary_key=True)
|
||||
timestamp: Mapped[datetime.datetime] = mapped_column(DateTime)
|
||||
condition: Mapped[str] = mapped_column(Unicode(255))
|
||||
type_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("item.id"), nullable=True)
|
||||
type_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("item.id"), nullable=True, index=True)
|
||||
name: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
||||
serial: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
||||
model: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
||||
notes: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
||||
owner_id = mapped_column(Integer, ForeignKey('users.id'))
|
||||
brand_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("brand.id"))
|
||||
location_id: Mapped[Optional[str]] = mapped_column(ForeignKey("rooms.id"))
|
||||
owner_id = mapped_column(Integer, ForeignKey('users.id'), nullable=True, index=True)
|
||||
brand_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("brand.id"), nullable=True, index=True)
|
||||
location_id: Mapped[Optional[str]] = mapped_column(ForeignKey("rooms.id"), nullable=True, index=True)
|
||||
barcode: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
||||
shared: Mapped[Optional[bool]] = mapped_column(Boolean, server_default=text('((0))'))
|
||||
image_id: Mapped[Optional[int]] = mapped_column(ForeignKey('images.id', ondelete='SET NULL'), nullable=True)
|
||||
image_id: Mapped[Optional[int]] = mapped_column(ForeignKey('images.id', ondelete='SET NULL'), nullable=True, index=True)
|
||||
|
||||
location: Mapped[Optional['Room']] = relationship('Room', back_populates='inventory')
|
||||
owner = relationship('User', back_populates='inventory')
|
||||
|
|
|
@ -18,8 +18,8 @@ class Room(ValidatableMixin, db.Model):
|
|||
|
||||
id: Mapped[int] = mapped_column(Integer, Identity(start=1, increment=1), primary_key=True)
|
||||
name: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
|
||||
area_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("area.id"))
|
||||
function_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("room_function.id"))
|
||||
area_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("area.id"), nullable=True, index=True)
|
||||
function_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("room_function.id"), nullable=True, index=True)
|
||||
|
||||
area: Mapped[Optional['Area']] = relationship('Area', back_populates='rooms')
|
||||
room_function: Mapped[Optional['RoomFunction']] = relationship('RoomFunction', back_populates='rooms')
|
||||
|
|
|
@ -19,9 +19,9 @@ class User(db.Model, ImageAttachable):
|
|||
active: Mapped[Optional[bool]] = mapped_column(Boolean, server_default=text('((0))'))
|
||||
last_name: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
|
||||
first_name: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
|
||||
location_id: Mapped[Optional[int]] = mapped_column(ForeignKey("rooms.id"), nullable=True)
|
||||
supervisor_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("users.id"))
|
||||
image_id: Mapped[Optional[int]] = mapped_column(ForeignKey('images.id', ondelete='SET NULL'), nullable=True)
|
||||
location_id: Mapped[Optional[int]] = mapped_column(ForeignKey("rooms.id"), nullable=True, index=True)
|
||||
supervisor_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("users.id"), nullable=True, index=True)
|
||||
image_id: Mapped[Optional[int]] = mapped_column(ForeignKey('images.id', ondelete='SET NULL'), nullable=True, index=True)
|
||||
|
||||
supervisor: Mapped[Optional['User']] = relationship('User', remote_side='User.id', back_populates='subordinates')
|
||||
subordinates: Mapped[List['User']] = relationship('User', back_populates='supervisor')
|
||||
|
|
|
@ -23,9 +23,9 @@ class WorkLog(db.Model, ImageAttachable):
|
|||
notes: Mapped[Optional[str]] = mapped_column(Unicode())
|
||||
complete: Mapped[Optional[bool]] = mapped_column(Boolean, server_default=text('((0))'))
|
||||
followup: Mapped[Optional[bool]] = mapped_column(Boolean, server_default=text('((0))'))
|
||||
contact_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("users.id"))
|
||||
contact_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("users.id"), nullable=True, index=True)
|
||||
analysis: Mapped[Optional[bool]] = mapped_column(Boolean, server_default=text('((0))'))
|
||||
work_item_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("inventory.id"))
|
||||
work_item_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("inventory.id"), nullable=True, index=True)
|
||||
|
||||
work_item: Mapped[Optional['Inventory']] = relationship('Inventory', back_populates='work_logs')
|
||||
contact: Mapped[Optional['User']] = relationship('User', back_populates='work_logs')
|
||||
|
|
|
@ -12,7 +12,7 @@ class WorkNote(db.Model):
|
|||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
work_log_id: Mapped[int] = mapped_column(ForeignKey('work_log.id', ondelete='CASCADE'), nullable=False)
|
||||
work_log_id: Mapped[int] = mapped_column(ForeignKey('work_log.id', ondelete='CASCADE'), nullable=False, index=True)
|
||||
timestamp: Mapped[datetime.datetime] = mapped_column(DateTime, default=func.now(), server_default=func.now())
|
||||
content: Mapped[str] = mapped_column(UnicodeText, nullable=False)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue