From 1765ab905e649403aecd2b300a86de9de3ec4017 Mon Sep 17 00:00:00 2001 From: spwoodcock Date: Wed, 3 Jul 2024 19:34:56 +0100 Subject: [PATCH] refactor: remove references to removed tables in sqlalchemy models --- src/backend/app/db/db_models.py | 181 -------------------------------- src/backend/app/models/enums.py | 25 ----- 2 files changed, 206 deletions(-) diff --git a/src/backend/app/db/db_models.py b/src/backend/app/db/db_models.py index 4dc87c6f80..a1ead34251 100644 --- a/src/backend/app/db/db_models.py +++ b/src/backend/app/db/db_models.py @@ -54,7 +54,6 @@ BackgroundTaskStatus, CommunityType, MappingLevel, - MappingPermission, OrganisationType, ProjectPriority, ProjectRole, @@ -63,9 +62,7 @@ TaskAction, TaskSplitType, TaskStatus, - TeamVisibility, UserRole, - ValidationPermission, ) @@ -127,9 +124,6 @@ class DbUser(Base): # projects_notifications = Column(Boolean, default=True, nullable=False) # tasks_notifications = Column(Boolean, default=True, nullable=False) # tasks_comments_notifications = Column(Boolean, default=False, nullable=False) - # teams_announcement_notifications = Column( - # Boolean, default=True, nullable=False - # ) date_registered = cast(datetime, Column(DateTime, default=timestamp)) # Represents the date the user last had one of their tasks validated @@ -184,48 +178,6 @@ class DbOrganisation(Base): ) -class DbTeam(Base): - """Describes a team.""" - - __tablename__ = "teams" - - # Columns - id = cast(int, Column(Integer, primary_key=True)) - organisation_id = cast( - int, - Column( - Integer, - ForeignKey("organisations.id", name="fk_organisations"), - nullable=False, - ), - ) - name = cast(str, Column(String(512), nullable=False)) - logo = cast(str, Column(String)) # URL of a logo - description = cast(str, Column(String)) - invite_only = cast(bool, Column(Boolean, default=False, nullable=False)) - visibility = cast( - TeamVisibility, - Column(Enum(TeamVisibility), default=TeamVisibility.PUBLIC, nullable=False), - ) - organisation = relationship(DbOrganisation, backref="teams") - - -class DbProjectTeams(Base): - """Link table between teams and projects.""" - - __tablename__ = "project_teams" - team_id = cast(int, Column(Integer, ForeignKey("teams.id"), primary_key=True)) - project_id = cast(int, Column(Integer, ForeignKey("projects.id"), primary_key=True)) - role = cast(int, Column(Integer, nullable=False)) - - project = relationship( - "DbProject", backref=backref("teams", cascade="all, delete-orphan") - ) - team = relationship( - DbTeam, backref=backref("projects", cascade="all, delete-orphan") - ) - - class DbProjectInfo(Base): """Contains all project info localized into supported languages.""" @@ -247,22 +199,6 @@ class DbProjectInfo(Base): ) -class DbProjectChat(Base): - """Contains all project info localized into supported languages.""" - - __tablename__ = "project_chat" - id = cast(int, Column(BigInteger, primary_key=True)) - project_id = cast( - int, Column(Integer, ForeignKey("projects.id"), index=True, nullable=False) - ) - user_id = cast(int, Column(Integer, ForeignKey("users.id"), nullable=False)) - time_stamp = cast(datetime, Column(DateTime, nullable=False, default=timestamp)) - message = cast(str, Column(String, nullable=False)) - - # Relationships - posted_by = relationship(DbUser, foreign_keys=[user_id]) - - class DbXLSForm(Base): """XLSForm templates and custom uploads.""" @@ -291,83 +227,6 @@ class DbXForm(Base): category = cast(str, Column(String)) -class DbTaskInvalidationHistory(Base): - """Information on task invalidation. - - Describes the most recent history of task invalidation and subsequent validation. - """ - - __tablename__ = "task_invalidation_history" - id = cast(int, Column(Integer, primary_key=True)) - project_id = cast(int, Column(Integer, ForeignKey("projects.id"), nullable=False)) - task_id = cast(int, Column(Integer, nullable=False)) - is_closed = cast(bool, Column(Boolean, default=False)) - mapper_id = cast(int, Column(BigInteger, ForeignKey("users.id", name="fk_mappers"))) - mapped_date = cast(datetime, Column(DateTime)) - invalidator_id = cast( - int, Column(BigInteger, ForeignKey("users.id", name="fk_invalidators")) - ) - invalidated_date = cast(datetime, Column(DateTime)) - invalidation_history_id = cast( - int, - Column(Integer, ForeignKey("task_history.id", name="fk_invalidation_history")), - ) - validator_id = cast( - int, Column(BigInteger, ForeignKey("users.id", name="fk_validators")) - ) - validated_date = cast(datetime, Column(DateTime)) - updated_date = cast(datetime, Column(DateTime, default=timestamp)) - - __table_args__ = ( - ForeignKeyConstraint( - [task_id, project_id], ["tasks.id", "tasks.project_id"], name="fk_tasks" - ), - Index("idx_task_validation_history_composite", "task_id", "project_id"), - Index( - "idx_task_validation_validator_status_composite", - "invalidator_id", - "is_closed", - ), - Index("idx_task_validation_mapper_status_composite", "mapper_id", "is_closed"), - {}, - ) - - -class DbTaskMappingIssue(Base): - """Describes mapping issues. - - An issue (along with an occurrence count) with a - task mapping that contributed to invalidation of the task. - """ - - __tablename__ = "task_mapping_issues" - id = cast(int, Column(Integer, primary_key=True)) - task_history_id = cast( - int, Column(Integer, ForeignKey("task_history.id"), nullable=False, index=True) - ) - issue = cast(str, Column(String, nullable=False)) - mapping_issue_category_id = cast( - int, - Column( - Integer, - ForeignKey("mapping_issue_categories.id", name="fk_issue_category"), - nullable=False, - ), - ) - count = cast(int, Column(Integer, nullable=False)) - - -class DbMappingIssueCategory(Base): - """Represents a category of task mapping issues identified during validation.""" - - __tablename__ = "mapping_issue_categories" - - id = cast(int, Column(Integer, primary_key=True)) - name = cast(str, Column(String, nullable=False, unique=True)) - description = cast(str, Column(String, nullable=True)) - archived = cast(bool, Column(Boolean, default=False, nullable=False)) - - class DbTaskHistory(Base): """Describes the history associated with a task.""" @@ -391,11 +250,7 @@ class DbTaskHistory(Base): # Define relationships user = relationship(DbUser, uselist=False, backref="task_history_user") - invalidation_history = relationship( - DbTaskInvalidationHistory, lazy="dynamic", cascade="all" - ) actioned_by = relationship(DbUser, overlaps="task_history_user,user") - task_mapping_issues = relationship(DbTaskMappingIssue, cascade="all") __table_args__ = ( ForeignKeyConstraint( @@ -623,14 +478,6 @@ def tasks_bad(self): featured = cast( bool, Column(Boolean, default=False) ) # Only admins can set a project as featured - mapping_permission = cast( - MappingPermission, - Column(Enum(MappingPermission), default=MappingPermission.ANY), - ) - validation_permission = cast( - ValidationPermission, - Column(Enum(ValidationPermission), default=ValidationPermission.LEVEL), - ) # Means only users with validator role can validate changeset_comment = cast(str, Column(String)) # Odk central server @@ -665,9 +512,6 @@ def tasks_bad(self): josm_preset = cast(str, Column(String)) id_presets = cast(list, Column(ARRAY(String))) extra_id_params = cast(str, Column(String)) - license_id = cast( - int, Column(Integer, ForeignKey("licenses.id", name="fk_licenses")) - ) # GEOMETRY # country = Column(ARRAY(String), default=[]) @@ -679,31 +523,6 @@ def tasks_bad(self): due_date = cast(datetime, Column(DateTime)) -# Secondary table defining the many-to-many join -user_licenses_table = Table( - "user_licenses", - FmtmMetadata, - Column("user", BigInteger, ForeignKey("users.id")), - Column("license", Integer, ForeignKey("licenses.id")), -) - - -class DbLicense(Base): - """Describes an individual license.""" - - __tablename__ = "licenses" - - id = cast(int, Column(Integer, primary_key=True)) - name = cast(str, Column(String, unique=True)) - description = cast(str, Column(String)) - plain_text = cast(str, Column(String)) - - projects = relationship(DbProject, backref="license") - users = relationship( - DbUser, secondary=user_licenses_table - ) # Many to Many relationship - - class BackgroundTasks(Base): """Table managing long running background tasks.""" diff --git a/src/backend/app/models/enums.py b/src/backend/app/models/enums.py index 18bf241406..3e6a7b1c6c 100644 --- a/src/backend/app/models/enums.py +++ b/src/backend/app/models/enums.py @@ -54,13 +54,6 @@ class HTTPStatus(IntEnum): NOT_IMPLEMENTED = 501 -class TeamVisibility(IntEnum, Enum): - """Describes the visibility associated with an Team.""" - - PUBLIC = 0 - PRIVATE = 1 - - class OrganisationType(IntEnum, Enum): """Describes an organisation's subscription type.""" @@ -126,24 +119,6 @@ class MappingLevel(IntEnum, Enum): ADVANCED = 3 -class MappingPermission(IntEnum, Enum): - """Describes a set of permissions for mapping on a project.""" - - ANY = 0 - LEVEL = 1 - TEAMS = 2 - TEAMS_LEVEL = 3 - - -class ValidationPermission(IntEnum, Enum): - """Describes a set of permissions for validating on a project.""" - - ANY = 0 - LEVEL = 1 - TEAMS = 2 - TEAMS_LEVEL = 3 - - class TaskStatus(IntEnum, Enum): """Enum describing available Task Statuses."""