Timestamps and uuids everywhere
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from sqlalchemy import Column, Integer, String
|
||||
from flask import current_app as app
|
||||
|
||||
from atst.models import Base
|
||||
from atst.models import Base, types, mixins
|
||||
from atst.database import db
|
||||
from atst.uploader import UploadError
|
||||
|
||||
@@ -10,10 +10,10 @@ class AttachmentError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class Attachment(Base):
|
||||
class Attachment(Base, mixins.TimestampsMixin):
|
||||
__tablename__ = "attachments"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
id = types.Id()
|
||||
filename = Column(String)
|
||||
object_name = Column(String, unique=True)
|
||||
|
||||
|
||||
@@ -3,18 +3,17 @@ from sqlalchemy import Index, ForeignKey, Column, String
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from atst.models import Base
|
||||
from .types import Id
|
||||
from atst.models import Base, types, mixins
|
||||
|
||||
|
||||
class CSPRole(Enum):
|
||||
NONSENSE_ROLE = "nonesense_role"
|
||||
|
||||
|
||||
class EnvironmentRole(Base):
|
||||
class EnvironmentRole(Base, mixins.TimestampsMixin):
|
||||
__tablename__ = "environment_roles"
|
||||
|
||||
id = Id()
|
||||
id = types.Id()
|
||||
environment_id = Column(UUID(as_uuid=True), ForeignKey("environments.id"))
|
||||
environment = relationship("Environment", backref="roles")
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from atst.models import Base
|
||||
|
||||
|
||||
class PENumber(Base):
|
||||
__tablename__ = "pe_number"
|
||||
__tablename__ = "pe_numbers"
|
||||
|
||||
number = Column(String, primary_key=True)
|
||||
description = Column(String)
|
||||
|
||||
@@ -2,8 +2,7 @@ from sqlalchemy import Column, func, ForeignKey
|
||||
from sqlalchemy.types import DateTime
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from atst.models import Base
|
||||
from atst.models.types import Id
|
||||
from atst.models import Base, types, mixins
|
||||
from atst.models.request_status_event import RequestStatus
|
||||
from atst.utils import first_or_none
|
||||
from atst.models.request_revision import RequestRevision
|
||||
@@ -25,10 +24,10 @@ def update_dict_with_properties(instance, body, top_level_key, properties):
|
||||
return body
|
||||
|
||||
|
||||
class Request(Base):
|
||||
class Request(Base, mixins.TimestampsMixin):
|
||||
__tablename__ = "requests"
|
||||
|
||||
id = Id()
|
||||
id = types.Id()
|
||||
time_created = Column(DateTime(timezone=True), server_default=func.now())
|
||||
status_events = relationship(
|
||||
"RequestStatusEvent", backref="request", order_by="RequestStatusEvent.sequence"
|
||||
@@ -39,7 +38,7 @@ class Request(Base):
|
||||
user_id = Column(ForeignKey("users.id"), nullable=False)
|
||||
creator = relationship("User", backref="owned_requests")
|
||||
|
||||
task_order_id = Column(ForeignKey("task_order.id"))
|
||||
task_order_id = Column(ForeignKey("task_orders.id"))
|
||||
task_order = relationship("TaskOrder")
|
||||
|
||||
revisions = relationship(
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from sqlalchemy import Column, String, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from atst.models import Base, types
|
||||
from atst.models import Base, types, mixins
|
||||
|
||||
|
||||
class RequestInternalComment(Base):
|
||||
class RequestInternalComment(Base, mixins.TimestampsMixin):
|
||||
__tablename__ = "request_internal_comments"
|
||||
|
||||
id = types.Id()
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
from sqlalchemy import Column, BigInteger, String, ForeignKey
|
||||
from sqlalchemy import Column, String, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from atst.models import Base
|
||||
from atst.models import Base, mixins, types
|
||||
|
||||
|
||||
class RequestReview(Base):
|
||||
class RequestReview(Base, mixins.TimestampsMixin):
|
||||
__tablename__ = "request_reviews"
|
||||
|
||||
id = Column(BigInteger, primary_key=True)
|
||||
id = types.Id()
|
||||
status = relationship("RequestStatusEvent", uselist=False, back_populates="review")
|
||||
|
||||
user_id = Column(ForeignKey("users.id"), nullable=False)
|
||||
|
||||
@@ -5,7 +5,7 @@ from sqlalchemy.types import DateTime, BigInteger
|
||||
from sqlalchemy.schema import Sequence
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
|
||||
from atst.models import Base
|
||||
from atst.models import Base, mixins
|
||||
from atst.models.types import Id
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class RequestStatus(Enum):
|
||||
DELETED = "Deleted"
|
||||
|
||||
|
||||
class RequestStatusEvent(Base):
|
||||
class RequestStatusEvent(Base, mixins.TimestampsMixin):
|
||||
__tablename__ = "request_status_events"
|
||||
|
||||
id = Id()
|
||||
|
||||
@@ -2,14 +2,13 @@ from sqlalchemy import String, Column
|
||||
from sqlalchemy.dialects.postgresql import ARRAY
|
||||
from sqlalchemy.orm.attributes import flag_modified
|
||||
|
||||
from atst.models import Base
|
||||
from .types import Id
|
||||
from atst.models import Base, types, mixins
|
||||
|
||||
|
||||
class Role(Base):
|
||||
class Role(Base, mixins.TimestampsMixin):
|
||||
__tablename__ = "roles"
|
||||
|
||||
id = Id()
|
||||
id = types.Id()
|
||||
name = Column(String, index=True, unique=True)
|
||||
description = Column(String)
|
||||
permissions = Column(ARRAY(String), index=True, server_default="{}")
|
||||
|
||||
@@ -3,7 +3,7 @@ from enum import Enum
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, Enum as SQLAEnum, Date
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from atst.models import Base
|
||||
from atst.models import Base, types, mixins
|
||||
|
||||
|
||||
class Source(Enum):
|
||||
@@ -18,10 +18,10 @@ class FundingType(Enum):
|
||||
OTHER = "OTHER"
|
||||
|
||||
|
||||
class TaskOrder(Base):
|
||||
__tablename__ = "task_order"
|
||||
class TaskOrder(Base, mixins.TimestampsMixin):
|
||||
__tablename__ = "task_orders"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
id = types.Id()
|
||||
number = Column(String, unique=True)
|
||||
source = Column(SQLAEnum(Source, native_enum=False))
|
||||
funding_type = Column(SQLAEnum(FundingType, native_enum=False))
|
||||
|
||||
@@ -2,15 +2,14 @@ from sqlalchemy import String, ForeignKey, Column
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
|
||||
from atst.models import Base
|
||||
from .types import Id
|
||||
from atst.models import Base, types, mixins
|
||||
from atst.models.permissions import Permissions
|
||||
|
||||
|
||||
class User(Base):
|
||||
class User(Base, mixins.TimestampsMixin):
|
||||
__tablename__ = "users"
|
||||
|
||||
id = Id()
|
||||
id = types.Id()
|
||||
username = Column(String)
|
||||
atat_role_id = Column(UUID(as_uuid=True), ForeignKey("roles.id"))
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@ from sqlalchemy import Index, ForeignKey, Column
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from atst.models import Base
|
||||
from atst.models import Base, mixins
|
||||
from .types import Id
|
||||
|
||||
|
||||
class WorkspaceRole(Base):
|
||||
__tablename__ = "workspace_role"
|
||||
class WorkspaceRole(Base, mixins.TimestampsMixin):
|
||||
__tablename__ = "workspace_roles"
|
||||
|
||||
id = Id()
|
||||
workspace_id = Column(UUID(as_uuid=True), ForeignKey("workspaces.id"), index=True)
|
||||
|
||||
Reference in New Issue
Block a user