Skip to content

Commit

Permalink
Merge pull request #465 from uhh-lt/remove-autologbook
Browse files Browse the repository at this point in the history
Remove autologbook
  • Loading branch information
bigabig authored Nov 12, 2024
2 parents 905cc05 + cdaccb0 commit 7c60060
Show file tree
Hide file tree
Showing 47 changed files with 209 additions and 2,119 deletions.
198 changes: 198 additions & 0 deletions backend/src/alembic/versions/f3108bb5e496_remove_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
"""remove actions
Revision ID: f3108bb5e496
Revises: de0c6bd65d37
Create Date: 2024-11-12 16:42:22.435833
"""

from typing import Sequence, Union

import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "f3108bb5e496"
down_revision: Union[str, None] = "de0c6bd65d37"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
op.drop_index("ix_action_action_type", table_name="action")
op.drop_index("ix_action_executed", table_name="action")
op.drop_index("ix_action_id", table_name="action")
op.drop_index("ix_action_project_id", table_name="action")
op.drop_index("ix_action_target_id", table_name="action")
op.drop_index("ix_action_target_type", table_name="action")
op.drop_index("ix_action_user_id", table_name="action")
op.drop_index("ix_objecthandle_action_id", table_name="objecthandle")
op.drop_constraint(
"UC_only_one_object_handle_per_instance", "objecthandle", type_="unique"
)
op.create_unique_constraint(
"UC_only_one_object_handle_per_instance",
"objecthandle",
[
"user_id",
"project_id",
"code_id",
"source_document_id",
"span_annotation_id",
"span_group_id",
"document_tag_id",
"memo_id",
],
)
op.drop_index("idx_for_uc_work_with_null", table_name="objecthandle")
op.create_index(
"idx_for_uc_work_with_null",
"objecthandle",
[
sa.text("coalesce(user_id, 0)"),
sa.text("coalesce(project_id, 0)"),
sa.text("coalesce(code_id, 0)"),
sa.text("coalesce(source_document_id, 0)"),
sa.text("coalesce(span_annotation_id, 0)"),
sa.text("coalesce(bbox_annotation_id, 0)"),
sa.text("coalesce(span_group_id, 0)"),
sa.text("coalesce(document_tag_id, 0)"),
sa.text("coalesce(memo_id, 0)"),
],
unique=True,
)
op.drop_constraint(
"objecthandle_action_id_fkey", "objecthandle", type_="foreignkey"
)
op.drop_column("objecthandle", "action_id")
op.create_check_constraint(
constraint_name="CC_object_handle_refers_to_exactly_one_instance",
table_name="objecthandle",
condition=sa.text(
"""(
CASE WHEN user_id IS NULL THEN 0 ELSE 1 END
+ CASE WHEN project_id IS NULL THEN 0 ELSE 1 END
+ CASE WHEN code_id IS NULL THEN 0 ELSE 1 END
+ CASE WHEN memo_id IS NULL THEN 0 ELSE 1 END
+ CASE WHEN source_document_id IS NULL THEN 0 ELSE 1 END
+ CASE WHEN span_annotation_id IS NULL THEN 0 ELSE 1 END
+ CASE WHEN bbox_annotation_id IS NULL THEN 0 ELSE 1 END
+ CASE WHEN span_group_id IS NULL THEN 0 ELSE 1 END
+ CASE WHEN document_tag_id IS NULL THEN 0 ELSE 1 END
) = 1"""
),
)
op.drop_table("action")


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"objecthandle",
sa.Column("action_id", sa.INTEGER(), autoincrement=False, nullable=True),
)
op.create_foreign_key(
"objecthandle_action_id_fkey",
"objecthandle",
"action",
["action_id"],
["id"],
ondelete="CASCADE",
)
op.drop_index("idx_for_uc_work_with_null", table_name="objecthandle")
op.create_index(
"idx_for_uc_work_with_null",
"objecthandle",
[
sa.text("COALESCE(user_id, 0)"),
sa.text("COALESCE(project_id, 0)"),
sa.text("COALESCE(code_id, 0)"),
sa.text("COALESCE(source_document_id, 0)"),
sa.text("COALESCE(span_annotation_id, 0)"),
sa.text("COALESCE(bbox_annotation_id, 0)"),
sa.text("COALESCE(span_group_id, 0)"),
sa.text("COALESCE(document_tag_id, 0)"),
sa.text("COALESCE(action_id, 0)"),
sa.text("COALESCE(memo_id, 0)"),
],
unique=False,
)
op.drop_constraint(
"UC_only_one_object_handle_per_instance", "objecthandle", type_="unique"
)
op.create_unique_constraint(
"UC_only_one_object_handle_per_instance",
"objecthandle",
[
"user_id",
"project_id",
"code_id",
"source_document_id",
"span_annotation_id",
"span_group_id",
"document_tag_id",
"action_id",
"memo_id",
],
)
op.create_index(
"ix_objecthandle_action_id", "objecthandle", ["action_id"], unique=False
)
op.create_table(
"action",
sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column(
"executed",
postgresql.TIMESTAMP(),
server_default=sa.text("now()"),
autoincrement=False,
nullable=False,
),
sa.Column("action_type", sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column("target_id", sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column("target_type", sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column("before_state", sa.VARCHAR(), autoincrement=False, nullable=True),
sa.Column("after_state", sa.VARCHAR(), autoincrement=False, nullable=True),
sa.Column("user_id", sa.INTEGER(), autoincrement=False, nullable=True),
sa.Column("project_id", sa.INTEGER(), autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(
["project_id"],
["project.id"],
name="action_project_id_fkey",
ondelete="CASCADE",
),
sa.ForeignKeyConstraint(
["user_id"], ["user.id"], name="action_user_id_fkey", ondelete="CASCADE"
),
sa.PrimaryKeyConstraint("id", name="action_pkey"),
)
op.create_index("ix_action_user_id", "action", ["user_id"], unique=False)
op.create_index("ix_action_target_type", "action", ["target_type"], unique=False)
op.create_index("ix_action_target_id", "action", ["target_id"], unique=False)
op.create_index("ix_action_project_id", "action", ["project_id"], unique=False)
op.create_index("ix_action_id", "action", ["id"], unique=False)
op.create_index("ix_action_executed", "action", ["executed"], unique=False)
op.create_index("ix_action_action_type", "action", ["action_type"], unique=False)
op.drop_constraint(
"CC_object_handle_refers_to_exactly_one_instance", "objecthandle", type_="check"
)
op.create_check_constraint(
constraint_name="CC_object_handle_refers_to_exactly_one_instance",
table_name="objecthandle",
condition=sa.text(
"""(
CASE WHEN user_id IS NULL THEN 0 ELSE 1 END
+ CASE WHEN project_id IS NULL THEN 0 ELSE 1 END
+ CASE WHEN code_id IS NULL THEN 0 ELSE 1 END
+ CASE WHEN memo_id IS NULL THEN 0 ELSE 1 END
+ CASE WHEN source_document_id IS NULL THEN 0 ELSE 1 END
+ CASE WHEN span_annotation_id IS NULL THEN 0 ELSE 1 END
+ CASE WHEN bbox_annotation_id IS NULL THEN 0 ELSE 1 END
+ CASE WHEN span_group_id IS NULL THEN 0 ELSE 1 END
+ CASE WHEN document_tag_id IS NULL THEN 0 ELSE 1 END
+ CASE WHEN action_id IS NULL THEN 0 ELSE 1 END
) = 1"""
),
)
51 changes: 0 additions & 51 deletions backend/src/api/endpoints/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@
from api.util import get_object_memo_for_user, get_object_memos
from app.core.analysis.duplicate_finder_service import DuplicateFinderService
from app.core.authorization.authz_user import AuthzUser
from app.core.data.crud.action import crud_action
from app.core.data.crud.code import crud_code
from app.core.data.crud.crud_base import NoSuchElementError
from app.core.data.crud.document_tag import crud_document_tag
from app.core.data.crud.memo import crud_memo
from app.core.data.crud.project import crud_project
from app.core.data.crud.project_metadata import crud_project_meta
from app.core.data.crud.source_document import crud_sdoc
from app.core.data.dto.action import ActionQueryParameters, ActionRead
from app.core.data.dto.code import CodeRead
from app.core.data.dto.document_tag import DocumentTagRead
from app.core.data.dto.memo import (
Expand Down Expand Up @@ -319,55 +317,6 @@ def get_user_memos_of_project(
]


@router.get(
"/{proj_id}/user/{user_id}/action",
response_model=List[ActionRead],
summary="Returns all Actions of the Project from a User",
)
def get_user_actions_of_project(
*,
proj_id: int,
user_id: int,
db: Session = Depends(get_db_session),
authz_user: AuthzUser = Depends(),
) -> List[ActionRead]:
authz_user.assert_in_project(proj_id)

return [
ActionRead.model_validate(ar)
for ar in crud_action.read_by_user_and_project(
db=db, proj_id=proj_id, user_id=user_id
)
]


@router.post(
"/{proj_id}/actions",
response_model=List[ActionRead],
summary="Returns all Actions of the Project",
)
def query_actions_of_project(
*,
query_params: ActionQueryParameters,
db: Session = Depends(get_db_session),
authz_user: AuthzUser = Depends(),
) -> List[ActionRead]:
authz_user.assert_in_project(query_params.proj_id)

return [
ActionRead.model_validate(action)
for action in crud_action.read_by(
db=db,
proj_id=query_params.proj_id,
user_ids=query_params.user_ids,
action_types=query_params.action_types,
action_targets=query_params.action_targets,
timestamp_from=query_params.timestamp_from,
timestamp_to=query_params.timestamp_to,
)
]


@router.get(
"/{proj_id}/memo",
response_model=List[MemoRead],
Expand Down
2 changes: 0 additions & 2 deletions backend/src/app/core/data/crud/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from enum import Enum

from app.core.data.crud.action import crud_action
from app.core.data.crud.analysis_table import crud_analysis_table
from app.core.data.crud.annotation_document import crud_adoc
from app.core.data.crud.bbox_annotation import crud_bbox_anno
Expand All @@ -26,7 +25,6 @@


class Crud(Enum):
ACTION = crud_action
ANALYSIS_TABLE = crud_analysis_table
ANNOTATION_DOCUMENT = crud_adoc
BBOX_ANNOTATION = crud_bbox_anno
Expand Down
78 changes: 0 additions & 78 deletions backend/src/app/core/data/crud/action.py

This file was deleted.

10 changes: 0 additions & 10 deletions backend/src/app/core/data/crud/annotation_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from sqlalchemy.orm import Session

from app.core.data.crud.crud_base import CRUDBase, NoSuchElementError
from app.core.data.dto.action import ActionType
from app.core.data.dto.annotation_document import (
AnnotationDocumentCreate,
AnnotationDocumentUpdate,
Expand Down Expand Up @@ -68,15 +67,6 @@ def remove_by_sdoc(self, db: Session, *, sdoc_id: int) -> List[int]:
removed_orms = query.all()
ids = [removed_orm.id for removed_orm in removed_orms]

# create actions
for removed_orm in removed_orms:
before_state = self._get_action_state_from_orm(removed_orm)
self._create_action(
db_obj=removed_orm,
action_type=ActionType.DELETE,
before_state=before_state,
)

# delete the adocs
query.delete()
db.commit()
Expand Down
Loading

0 comments on commit 7c60060

Please sign in to comment.