diff --git a/geoapi/migrations/versions/20241211_1753-1040b620b32f_remove_observabledataproject.py b/geoapi/migrations/versions/20241211_1753-1040b620b32f_remove_observabledataproject.py new file mode 100644 index 00000000..65e8e43d --- /dev/null +++ b/geoapi/migrations/versions/20241211_1753-1040b620b32f_remove_observabledataproject.py @@ -0,0 +1,63 @@ +"""remove_ObservableDataProject + +Revision ID: 1040b620b32f +Revises: f2d7f797c82a +Create Date: 2024-12-11 17:53:36.850536 + +""" + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = "1040b620b32f" +down_revision = "f2d7f797c82a" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index( + "ix_observable_data_projects_project_id", table_name="observable_data_projects" + ) + op.drop_table("observable_data_projects") + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "observable_data_projects", + sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), + sa.Column("project_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column( + "created_date", + postgresql.TIMESTAMP(timezone=True), + server_default=sa.text("now()"), + autoincrement=False, + nullable=True, + ), + sa.Column("system_id", sa.VARCHAR(), autoincrement=False, nullable=False), + sa.Column("path", sa.VARCHAR(), autoincrement=False, nullable=False), + sa.Column("watch_content", sa.BOOLEAN(), autoincrement=False, nullable=True), + sa.ForeignKeyConstraint( + ["project_id"], + ["projects.id"], + name="observable_data_projects_project_id_fkey", + onupdate="CASCADE", + ondelete="CASCADE", + ), + sa.PrimaryKeyConstraint("id", name="observable_data_projects_pkey"), + sa.UniqueConstraint( + "system_id", "path", name="observable_data_projects_system_id_path_key" + ), + ) + op.create_index( + "ix_observable_data_projects_project_id", + "observable_data_projects", + ["project_id"], + unique=False, + ) + # ### end Alembic commands ### diff --git a/geoapi/models/__init__.py b/geoapi/models/__init__.py index 8d788c53..16fad1a1 100644 --- a/geoapi/models/__init__.py +++ b/geoapi/models/__init__.py @@ -6,7 +6,6 @@ from .auth import Auth from .overlay import Overlay from .tile_server import TileServer -from .observable_data import ObservableDataProject from .notification import Notification, ProgressNotification from .imported_file import ImportedFile from .streetview import ( diff --git a/geoapi/models/observable_data.py b/geoapi/models/observable_data.py deleted file mode 100644 index 46c83759..00000000 --- a/geoapi/models/observable_data.py +++ /dev/null @@ -1,18 +0,0 @@ -from sqlalchemy import Column, Integer, String, Boolean, ForeignKey, DateTime -from sqlalchemy.orm import relationship -from sqlalchemy.sql import func -from geoapi.db import Base - - -# Deprecated; Replaced by watch_user and watch_content of Project table. See https://tacc-main.atlassian.net/browse/WG-377 -class ObservableDataProject(Base): - __tablename__ = "observable_data_projects" - id = Column(Integer, primary_key=True) - project_id = Column( - ForeignKey("projects.id", ondelete="CASCADE", onupdate="CASCADE"), index=True - ) - created_date = Column(DateTime(timezone=True), server_default=func.now()) - system_id = Column(String, nullable=False) - path = Column(String, nullable=False, default="RApp") - watch_content = Column(Boolean, default=True) - project = relationship("Project") diff --git a/geoapi/tools/check_observable_projects.py b/geoapi/tools/check_observable_projects.py deleted file mode 100644 index 02019219..00000000 --- a/geoapi/tools/check_observable_projects.py +++ /dev/null @@ -1,41 +0,0 @@ -from geoapi.models import ObservableDataProject, Project -from geoapi.db import create_task_session -from geoapi.log import logger - -# Check that migrations worked out as expected -# Remove this file with https://tacc-main.atlassian.net/browse/WG-377 - -with create_task_session() as session: - observable_projects = session.query(ObservableDataProject).all() - projects = session.query(Project).all() - - logger.info( - f"Checking observable_projects ({len(observable_projects)}) and projects ({len(projects)})" - ) - - issues = 0 - for obs in observable_projects: - try: - if ( - not obs.project.watch_users - or obs.watch_content != obs.project.watch_content - ): - issues += 1 - logger.info( - f"Issue with observable project (id:{obs.id} project_id:{obs.project_id}):\n" - f" obs.project.watch_users:{obs.project.watch_users}\n" - f" obs.project.watch_content:{obs.project.watch_content}\n" - f" obs.project.watch_content:{obs.watch_content}\n" - ) - except Exception: - issues += 1 - logger.exception( - f"Something happened when checking observable project" - f" (id:{obs.id} project_id:{obs.project_id})" - ) - - logger.info( - "\n\n\nDone checking.\n\nNote some discrepancies could occur (i.e. projects are deleted but then deprecated" - " observable project is not deleted) \n\n" - ) - logger.info(f"{issues} issues found.")