Standardize table names and foreign key references for consistency across area, brand, inventory, item, room function, room, user, and work log models
This commit is contained in:
parent
ae5ffc82b3
commit
58f8a040b7
8 changed files with 18 additions and 18 deletions
|
@ -10,7 +10,7 @@ from ..temp import is_temp_id
|
||||||
from ..utils.validation import ValidatableMixin
|
from ..utils.validation import ValidatableMixin
|
||||||
|
|
||||||
class Area(ValidatableMixin, db.Model):
|
class Area(ValidatableMixin, db.Model):
|
||||||
__tablename__ = 'Areas'
|
__tablename__ = 'area'
|
||||||
VALIDATION_LABEL = "Area"
|
VALIDATION_LABEL = "Area"
|
||||||
|
|
||||||
id: Mapped[int] = mapped_column(Integer, Identity(start=1, increment=1), primary_key=True)
|
id: Mapped[int] = mapped_column(Integer, Identity(start=1, increment=1), primary_key=True)
|
||||||
|
|
|
@ -10,7 +10,7 @@ from ..temp import is_temp_id
|
||||||
from ..utils.validation import ValidatableMixin
|
from ..utils.validation import ValidatableMixin
|
||||||
|
|
||||||
class Brand(ValidatableMixin, db.Model):
|
class Brand(ValidatableMixin, db.Model):
|
||||||
__tablename__ = 'Brands'
|
__tablename__ = 'brand'
|
||||||
VALIDATION_LABEL = 'Brand'
|
VALIDATION_LABEL = 'Brand'
|
||||||
|
|
||||||
id: Mapped[int] = mapped_column(Integer, Identity(start=1, increment=1), primary_key=True)
|
id: Mapped[int] = mapped_column(Integer, Identity(start=1, increment=1), primary_key=True)
|
||||||
|
|
|
@ -12,7 +12,7 @@ import datetime
|
||||||
from . import db
|
from . import db
|
||||||
|
|
||||||
class Inventory(db.Model):
|
class Inventory(db.Model):
|
||||||
__tablename__ = 'Inventory'
|
__tablename__ = 'inventory'
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
Index('Inventory$Barcode', 'barcode'),
|
Index('Inventory$Barcode', 'barcode'),
|
||||||
)
|
)
|
||||||
|
@ -20,15 +20,15 @@ class Inventory(db.Model):
|
||||||
id: Mapped[int] = mapped_column(Integer, Identity(start=1, increment=1), primary_key=True)
|
id: Mapped[int] = mapped_column(Integer, Identity(start=1, increment=1), primary_key=True)
|
||||||
timestamp: Mapped[datetime.datetime] = mapped_column(DateTime)
|
timestamp: Mapped[datetime.datetime] = mapped_column(DateTime)
|
||||||
condition: Mapped[str] = mapped_column(Unicode(255))
|
condition: Mapped[str] = mapped_column(Unicode(255))
|
||||||
type_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("Items.id"), nullable=True)
|
type_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("item.id"), nullable=True)
|
||||||
name: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
name: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
||||||
serial: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
serial: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
||||||
model: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
model: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
||||||
notes: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
notes: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
||||||
owner_id = mapped_column(Integer, ForeignKey('Users.id'))
|
owner_id = mapped_column(Integer, ForeignKey('users.id'))
|
||||||
brand_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("Brands.id"))
|
brand_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("brand.id"))
|
||||||
# Photo: Mapped[Optional[str]] = mapped_column(String(8000)) Will be replacing with something that actually works.
|
# Photo: Mapped[Optional[str]] = mapped_column(String(8000)) Will be replacing with something that actually works.
|
||||||
location_id: Mapped[Optional[str]] = mapped_column(ForeignKey("Rooms.id"))
|
location_id: Mapped[Optional[str]] = mapped_column(ForeignKey("rooms.id"))
|
||||||
barcode: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
barcode: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
||||||
shared: Mapped[Optional[bool]] = mapped_column(Boolean, server_default=text('((0))'))
|
shared: Mapped[Optional[bool]] = mapped_column(Boolean, server_default=text('((0))'))
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ from ..temp import is_temp_id
|
||||||
from ..utils.validation import ValidatableMixin
|
from ..utils.validation import ValidatableMixin
|
||||||
|
|
||||||
class Item(ValidatableMixin, db.Model):
|
class Item(ValidatableMixin, db.Model):
|
||||||
__tablename__ = 'Items'
|
__tablename__ = 'item'
|
||||||
VALIDATION_LABEL = 'Item'
|
VALIDATION_LABEL = 'Item'
|
||||||
|
|
||||||
id: Mapped[int] = mapped_column(Integer, Identity(start=1, increment=1), primary_key=True)
|
id: Mapped[int] = mapped_column(Integer, Identity(start=1, increment=1), primary_key=True)
|
||||||
|
|
|
@ -10,7 +10,7 @@ from ..temp import is_temp_id
|
||||||
from ..utils.validation import ValidatableMixin
|
from ..utils.validation import ValidatableMixin
|
||||||
|
|
||||||
class RoomFunction(ValidatableMixin, db.Model):
|
class RoomFunction(ValidatableMixin, db.Model):
|
||||||
__tablename__ = 'Room Functions'
|
__tablename__ = 'room_function'
|
||||||
VALIDATION_LABEL = "Function"
|
VALIDATION_LABEL = "Function"
|
||||||
|
|
||||||
id: Mapped[int] = mapped_column(Integer, Identity(start=1, increment=1), primary_key=True)
|
id: Mapped[int] = mapped_column(Integer, Identity(start=1, increment=1), primary_key=True)
|
||||||
|
|
|
@ -13,13 +13,13 @@ from . import db
|
||||||
from ..utils.validation import ValidatableMixin
|
from ..utils.validation import ValidatableMixin
|
||||||
|
|
||||||
class Room(ValidatableMixin, db.Model):
|
class Room(ValidatableMixin, db.Model):
|
||||||
__tablename__ = 'Rooms'
|
__tablename__ = 'rooms'
|
||||||
VALIDATION_LABEL = "Room"
|
VALIDATION_LABEL = "Room"
|
||||||
|
|
||||||
id: Mapped[int] = mapped_column(Integer, Identity(start=1, increment=1), primary_key=True)
|
id: Mapped[int] = mapped_column(Integer, Identity(start=1, increment=1), primary_key=True)
|
||||||
name: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
|
name: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
|
||||||
area_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("Areas.id"))
|
area_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("area.id"))
|
||||||
function_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("Room Functions.id"))
|
function_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("room_function.id"))
|
||||||
|
|
||||||
area: Mapped[Optional['Area']] = relationship('Area', back_populates='rooms')
|
area: Mapped[Optional['Area']] = relationship('Area', back_populates='rooms')
|
||||||
room_function: Mapped[Optional['RoomFunction']] = relationship('RoomFunction', back_populates='rooms')
|
room_function: Mapped[Optional['RoomFunction']] = relationship('RoomFunction', back_populates='rooms')
|
||||||
|
|
|
@ -10,15 +10,15 @@ from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||||
from . import db
|
from . import db
|
||||||
|
|
||||||
class User(db.Model):
|
class User(db.Model):
|
||||||
__tablename__ = 'Users'
|
__tablename__ = 'users'
|
||||||
|
|
||||||
id: Mapped[int] = mapped_column(Integer, Identity(start=1, increment=1), primary_key=True)
|
id: Mapped[int] = mapped_column(Integer, Identity(start=1, increment=1), primary_key=True)
|
||||||
staff: Mapped[Optional[bool]] = mapped_column(Boolean, server_default=text('((0))'))
|
staff: Mapped[Optional[bool]] = mapped_column(Boolean, server_default=text('((0))'))
|
||||||
active: Mapped[Optional[bool]] = mapped_column(Boolean, server_default=text('((0))'))
|
active: Mapped[Optional[bool]] = mapped_column(Boolean, server_default=text('((0))'))
|
||||||
last_name: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
|
last_name: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
|
||||||
first_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)
|
location_id: Mapped[Optional[int]] = mapped_column(ForeignKey("rooms.id"), nullable=True)
|
||||||
supervisor_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("Users.id"))
|
supervisor_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("users.id"))
|
||||||
|
|
||||||
supervisor: Mapped[Optional['User']] = relationship('User', remote_side='User.id', back_populates='subordinates')
|
supervisor: Mapped[Optional['User']] = relationship('User', remote_side='User.id', back_populates='subordinates')
|
||||||
subordinates: Mapped[List['User']] = relationship('User', back_populates='supervisor')
|
subordinates: Mapped[List['User']] = relationship('User', back_populates='supervisor')
|
||||||
|
|
|
@ -10,7 +10,7 @@ import datetime
|
||||||
from . import db
|
from . import db
|
||||||
|
|
||||||
class WorkLog(db.Model):
|
class WorkLog(db.Model):
|
||||||
__tablename__ = 'Work Log'
|
__tablename__ = 'work_log'
|
||||||
|
|
||||||
id: Mapped[int] = mapped_column(Integer, Identity(start=1, increment=1), primary_key=True)
|
id: Mapped[int] = mapped_column(Integer, Identity(start=1, increment=1), primary_key=True)
|
||||||
start_time: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime)
|
start_time: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime)
|
||||||
|
@ -18,9 +18,9 @@ class WorkLog(db.Model):
|
||||||
notes: Mapped[Optional[str]] = mapped_column(Unicode())
|
notes: Mapped[Optional[str]] = mapped_column(Unicode())
|
||||||
complete: Mapped[Optional[bool]] = mapped_column(Boolean, server_default=text('((0))'))
|
complete: Mapped[Optional[bool]] = mapped_column(Boolean, server_default=text('((0))'))
|
||||||
followup: 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"))
|
||||||
analysis: Mapped[Optional[bool]] = mapped_column(Boolean, server_default=text('((0))'))
|
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"))
|
||||||
|
|
||||||
work_item: Mapped[Optional['Inventory']] = relationship('Inventory', back_populates='work_logs')
|
work_item: Mapped[Optional['Inventory']] = relationship('Inventory', back_populates='work_logs')
|
||||||
contact: Mapped[Optional['User']] = relationship('User', back_populates='work_logs')
|
contact: Mapped[Optional['User']] = relationship('User', back_populates='work_logs')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue