Skip to content

Commit

Permalink
New table for wrokflow_tag and topic join
Browse files Browse the repository at this point in the history
  • Loading branch information
ianlongden committed Mar 7, 2025
1 parent 7060441 commit 73f87ac
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 7 deletions.
1 change: 1 addition & 0 deletions agr_literature_service/api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from agr_literature_service.api.models.user_model import UserModel
from agr_literature_service.api.models.obsolete_model import ObsoleteReferenceModel
from agr_literature_service.api.models.workflow_tag_model import WorkflowTagModel
from agr_literature_service.api.models.workflow_tag_topic_model import WorkflowTagTopicModel
from agr_literature_service.api.models.workflow_transition_model import WorkflowTransitionModel
from agr_literature_service.api.models.topic_entity_tag_model import TopicEntityTagModel, TopicEntityTagSourceModel
from agr_literature_service.api.models.reference_mod_md5sum_model import ReferenceModMd5sumModel
Expand Down
29 changes: 29 additions & 0 deletions agr_literature_service/api/models/workflow_tag_topic_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from typing import Dict
from agr_literature_service.api.database.base import Base
from agr_literature_service.api.database.versioning import enable_versioning
from agr_literature_service.api.models.audited_model import AuditedModel
from sqlalchemy import (Column, ForeignKey, Integer, String)
from sqlalchemy.orm import relationship

class WorkflowTagTopicModel(AuditedModel, Base):
__tablename__ = "workflow_tag_topic"

workflow_tag_topic_id = Column(
Integer,
primary_key=True,
autoincrement=True
)

workflow_tag = Column(
String(),
index=True,
unique=True,
nullable=False
)

# Obtained from A-Team ontology node term-id
topic = Column(
String(),
unique=False,
nullable=False
)
Original file line number Diff line number Diff line change
Expand Up @@ -316,31 +316,31 @@ def add_sequence_data(db_subset_session):
if max_val:
print(f"setting max value to {max_val + 1} for {x[2]}")
com = f"ALTER SEQUENCE {x[2]} RESTART WITH {max_val+1}"
db_subset_session.execute(com)
db_subset_session.execute(text(com))
else:
print(f"setting max value to 0 for {x[2]} as none found")
com = f"ALTER SEQUENCE {x[2]} RESTART WITH 1"
db_subset_session.execute(com)
db_subset_session.execute(text(com))


def add_alembic(db_orig_session, db_subset_session):
# Add alembic_version
alembic_rows = db_orig_session.execute("SELECT version_num from alembic_version")
alembic_rows = db_orig_session.execute(text("SELECT version_num from alembic_version"))
version = ''
for alembic_row in alembic_rows:
version = alembic_row[0]
if not version:
print("ERROR: Could not find version_num for alembic_version table")
else:
db_subset_session.execute(f"INSERT into alembic_version (version_num) VALUES ('{version}');")
db_subset_session.execute(text(f"INSERT into alembic_version (version_num) VALUES ('{version}');"))
db_subset_session.commit()
db_subset_session.close()


def trigger_settings(db_session, state="DISABLE"):
global trigger_list
for table in trigger_list:
db_session.execute(f'ALTER TABLE {table} {state} TRIGGER all;')
db_session.execute(text(f'ALTER TABLE {table} {state} TRIGGER all;'))
db_session.commit()


Expand Down Expand Up @@ -423,7 +423,7 @@ def start():
okay = True
tables = ['reference', 'citation'] # add other tables?
for table_name in tables:
count_rows = db_subset_session.execute(f"SELECT count(1) from {table_name}")
count_rows = db_subset_session.execute(text(f"SELECT count(1) from {table_name}"))
count = 0
for count_row in count_rows:
count = count_row[0]
Expand All @@ -442,7 +442,7 @@ def start():
add_sequence_data(db_subset_session)

# for what ever reason need this:
db_subset_session.execute("REFRESH MATERIALIZED VIEW _view")
db_subset_session.execute(text("REFRESH MATERIALIZED VIEW _view"))
db_subset_session.commit()
if subset_dump:
dump_subset()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""workflow_tag_topic addition
Revision ID: bf8c336530f9
Revises: a286f0a59a44
Create Date: 2025-03-07 17:00:28.761932
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'bf8c336530f9'
down_revision = 'a286f0a59a44'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('workflow_tag_topic',
sa.Column('workflow_tag_topic_id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('workflow_tag', sa.String(), nullable=False),
sa.Column('topic', sa.String(), nullable=False),
sa.Column('date_created', sa.DateTime(), nullable=False),
sa.Column('date_updated', sa.DateTime(), nullable=True),
sa.Column('created_by', sa.String(), nullable=True),
sa.Column('updated_by', sa.String(), nullable=True),
sa.ForeignKeyConstraint(['created_by'], ['users.id'], ),
sa.ForeignKeyConstraint(['updated_by'], ['users.id'], ),
sa.PrimaryKeyConstraint('workflow_tag_topic_id')
)
op.create_index(op.f('ix_workflow_tag_topic_date_created'), 'workflow_tag_topic', ['date_created'], unique=False)
op.create_index(op.f('ix_workflow_tag_topic_date_updated'), 'workflow_tag_topic', ['date_updated'], unique=False)
op.create_index(op.f('ix_workflow_tag_topic_workflow_tag'), 'workflow_tag_topic', ['workflow_tag'], unique=True)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_workflow_tag_topic_workflow_tag'), table_name='workflow_tag_topic')
op.drop_index(op.f('ix_workflow_tag_topic_date_updated'), table_name='workflow_tag_topic')
op.drop_index(op.f('ix_workflow_tag_topic_date_created'), table_name='workflow_tag_topic')
op.drop_table('workflow_tag_topic')
# ### end Alembic commands ###

0 comments on commit 73f87ac

Please sign in to comment.