From 0932d26ca57312b83c4e990e062ba63904fac4c8 Mon Sep 17 00:00:00 2001 From: Stef Piatek Date: Fri, 23 May 2025 17:18:07 +0100 Subject: [PATCH] Change pixl schema so that it makes sense on multi-schema db --- cli/tests/conftest.py | 2 +- pixl_core/src/core/db/models.py | 2 +- pixl_core/tests/conftest.py | 2 +- pixl_dcmd/tests/conftest.py | 2 +- ...83dcb3812628_add_study_uid_column_to_image_table.py | 6 ++++-- .../bcaef54e2bfe_create_extract_and_image_tables.py | 10 +++++----- ...e12a6e20_replace_hashed_id_with_pseudo_study_uid.py | 4 ++-- ...5eb1_add_pseudo_patient_id_column_to_image_table.py | 4 ++-- postgres/pixl-db_init.sh | 2 +- 9 files changed, 18 insertions(+), 16 deletions(-) diff --git a/cli/tests/conftest.py b/cli/tests/conftest.py index 3218387ae..fcac58626 100644 --- a/cli/tests/conftest.py +++ b/cli/tests/conftest.py @@ -93,7 +93,7 @@ def db_engine(monkeymodule) -> Engine: :returns Engine: Engine for use in other setup fixtures """ # SQLite doesnt support schemas, so remove pixl schema from engine options - execution_options = {"schema_translate_map": {"pipeline": None}} + execution_options = {"schema_translate_map": {"pixl_pipeline": None}} engine = create_engine( "sqlite:///:memory:", execution_options=execution_options, diff --git a/pixl_core/src/core/db/models.py b/pixl_core/src/core/db/models.py index e45fc4e53..83b426577 100644 --- a/pixl_core/src/core/db/models.py +++ b/pixl_core/src/core/db/models.py @@ -27,7 +27,7 @@ class Base(DeclarativeBase): """sqlalchemy base class""" - metadata = MetaData(schema="pipeline") + metadata = MetaData(schema="pixl_pipeline") class Extract(Base): diff --git a/pixl_core/tests/conftest.py b/pixl_core/tests/conftest.py index 5bae7029f..c231c8cd7 100644 --- a/pixl_core/tests/conftest.py +++ b/pixl_core/tests/conftest.py @@ -118,7 +118,7 @@ def db_engine(monkeymodule) -> Generator[Engine, None, None]: :returns Engine: Engine for use in other setup fixtures """ # SQLite doesnt support schemas, so remove pixl schema from engine options - execution_options = {"schema_translate_map": {"pipeline": None}} + execution_options = {"schema_translate_map": {"pixl_pipeline": None}} engine = create_engine( "sqlite:///:memory:", execution_options=execution_options, diff --git a/pixl_dcmd/tests/conftest.py b/pixl_dcmd/tests/conftest.py index 35234b899..dda1f01c8 100644 --- a/pixl_dcmd/tests/conftest.py +++ b/pixl_dcmd/tests/conftest.py @@ -153,7 +153,7 @@ def db_engine(monkeymodule) -> Generator[Engine, None, None]: :returns Engine: Engine for use in other setup fixtures """ # SQLite doesnt support schemas, so remove pixl schema from engine options - execution_options = {"schema_translate_map": {"pipeline": None}} + execution_options = {"schema_translate_map": {"pixl_pipeline": None}} engine = create_engine( "sqlite:///:memory:", execution_options=execution_options, diff --git a/pixl_imaging/alembic/versions/83dcb3812628_add_study_uid_column_to_image_table.py b/pixl_imaging/alembic/versions/83dcb3812628_add_study_uid_column_to_image_table.py index 5876f45a1..e227b47d6 100644 --- a/pixl_imaging/alembic/versions/83dcb3812628_add_study_uid_column_to_image_table.py +++ b/pixl_imaging/alembic/versions/83dcb3812628_add_study_uid_column_to_image_table.py @@ -36,11 +36,13 @@ def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### - op.add_column("image", sa.Column("study_uid", sa.String(), nullable=True), schema="pipeline") + op.add_column( + "image", sa.Column("study_uid", sa.String(), nullable=True), schema="pixl_pipeline" + ) # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### - op.drop_column("image", "study_uid", schema="pipeline") + op.drop_column("image", "study_uid", schema="pixl_pipeline") # ### end Alembic commands ### diff --git a/pixl_imaging/alembic/versions/bcaef54e2bfe_create_extract_and_image_tables.py b/pixl_imaging/alembic/versions/bcaef54e2bfe_create_extract_and_image_tables.py index 4d6667f86..6747e261b 100644 --- a/pixl_imaging/alembic/versions/bcaef54e2bfe_create_extract_and_image_tables.py +++ b/pixl_imaging/alembic/versions/bcaef54e2bfe_create_extract_and_image_tables.py @@ -39,7 +39,7 @@ def upgrade() -> None: sa.Column("extract_id", sa.Integer(), nullable=False), sa.Column("slug", sa.String(), nullable=False), sa.PrimaryKeyConstraint("extract_id"), - schema="pipeline", + schema="pixl_pipeline", ) op.create_table( "image", @@ -52,13 +52,13 @@ def upgrade() -> None: sa.Column("extract_id", sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ["extract_id"], - ["pipeline.extract.extract_id"], + ["pixl_pipeline.extract.extract_id"], ), sa.PrimaryKeyConstraint("image_id"), - schema="pipeline", + schema="pixl_pipeline", ) def downgrade() -> None: - op.drop_table("image", schema="pipeline") - op.drop_table("extract", schema="pipeline") + op.drop_table("image", schema="pixl_pipeline") + op.drop_table("extract", schema="pixl_pipeline") diff --git a/pixl_imaging/alembic/versions/cb5ee12a6e20_replace_hashed_id_with_pseudo_study_uid.py b/pixl_imaging/alembic/versions/cb5ee12a6e20_replace_hashed_id_with_pseudo_study_uid.py index eba9fc341..0f3f77544 100644 --- a/pixl_imaging/alembic/versions/cb5ee12a6e20_replace_hashed_id_with_pseudo_study_uid.py +++ b/pixl_imaging/alembic/versions/cb5ee12a6e20_replace_hashed_id_with_pseudo_study_uid.py @@ -33,11 +33,11 @@ def upgrade() -> None: op.alter_column( - "image", "hashed_identifier", new_column_name="pseudo_study_uid", schema="pipeline" + "image", "hashed_identifier", new_column_name="pseudo_study_uid", schema="pixl_pipeline" ) def downgrade() -> None: op.alter_column( - "image", "pseudo_study_uid", new_column_name="hashed_identifier", schema="pipeline" + "image", "pseudo_study_uid", new_column_name="hashed_identifier", schema="pixl_pipeline" ) diff --git a/pixl_imaging/alembic/versions/d947cc715eb1_add_pseudo_patient_id_column_to_image_table.py b/pixl_imaging/alembic/versions/d947cc715eb1_add_pseudo_patient_id_column_to_image_table.py index c75d2b1ac..f32869ded 100644 --- a/pixl_imaging/alembic/versions/d947cc715eb1_add_pseudo_patient_id_column_to_image_table.py +++ b/pixl_imaging/alembic/versions/d947cc715eb1_add_pseudo_patient_id_column_to_image_table.py @@ -39,12 +39,12 @@ def upgrade() -> None: op.add_column( "image", sa.Column("pseudo_patient_id", sa.String(length=255), nullable=True), - schema="pipeline", + schema="pixl_pipeline", ) # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### - op.drop_column("image", "pseudo_patient_id", schema="pipeline") + op.drop_column("image", "pseudo_patient_id", schema="pixl_pipeline") # ### end Alembic commands ### diff --git a/postgres/pixl-db_init.sh b/postgres/pixl-db_init.sh index f23c7b9a8..321205ee2 100644 --- a/postgres/pixl-db_init.sh +++ b/postgres/pixl-db_init.sh @@ -16,4 +16,4 @@ set -euxo pipefail # Create the pipeline schema for keeping track of images and extracts -psql -U "${POSTGRES_USER}" --dbname "${POSTGRES_DB}" -c "CREATE SCHEMA pipeline AUTHORIZATION ${POSTGRES_USER}" \ No newline at end of file +psql -U "${POSTGRES_USER}" --dbname "${POSTGRES_DB}" -c "CREATE SCHEMA pixl_pipeline AUTHORIZATION ${POSTGRES_USER}" \ No newline at end of file