-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #465 from uhh-lt/remove-autologbook
Remove autologbook
- Loading branch information
Showing
47 changed files
with
209 additions
and
2,119 deletions.
There are no files selected for viewing
198 changes: 198 additions & 0 deletions
198
backend/src/alembic/versions/f3108bb5e496_remove_actions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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""" | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.