From 5a3b99df55a342153e3af330025582408a9330c9 Mon Sep 17 00:00:00 2001 From: mgcam Date: Tue, 20 Feb 2024 13:13:53 +0000 Subject: [PATCH] Dropped column 'properties' from sub_product db table. Ths column is no longer populated. Updated ORM for LangQC database. Updated instructions for creating alembic migration script. --- CHANGELOG.md | 8 +++-- alembic/README.md | 24 +++++++++++---- .../2.0.0_drop_json_properties_column.py | 29 +++++++++++++++++++ lang_qc/db/qc_schema.py | 1 - 4 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 alembic/versions/2.0.0_drop_json_properties_column.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 86e4780..e4c446e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed -* The properties column of the LangQC sub_product database table - is made nullable. The correctness of data in this column is no - longer guaranteed, the column will be dropped in future. +* The correctness of data in the 'properties' column of the + LangQC 'sub_product' database table is no longer guaranteed + because of the changes introduced in v. 5.0.0 of https://github.com/wtsi-npg/npg_id_generation + The column is made nullable and then dropped. The ORM for + the LangQC database is updated accordingly. * The production code no longer depends on the npg_id_generation package, therefore this dependency was moved to the dev section diff --git a/alembic/README.md b/alembic/README.md index e70d896..8c43f01 100644 --- a/alembic/README.md +++ b/alembic/README.md @@ -19,13 +19,27 @@ Set `ALEMBIC_DB_URL` env. variable to the SQLAlchemy URL for the database you want to operate on. The format is `driver://user:pass@host:port/dbname`, where for MySQL and our software stack the driver is `mysql+pymysql`. -Ensure `alembic` in on your PATH. Create a revision: +Ensure `alembic` is on your PATH. Run all commands from the root of the +repository, where the configuration for alembic `alembic.ini` resides. -```alembic revision -m 'This is a revision description'``` +Create a revision: -Define explicitly SQL statements that have to be executed both for the -`upgrade` and `downgrade` function definitions in the generated script. -Call execution of these statements, one at a time. Executing multiple +``` + # This example command generates alembic/versions/2.0.0_drop_json_properties_column.py + # python script, which contains an empty template for defining the migration. + alembic revision -m 'drop_json_properties_column' --rev-id 2.0.0 --head 3814003a709a +``` + +If `--rev_id` is not specified, `alembic` generates a random id for the migration, +which does not present the problem immideately, but makes it difficult long term to +understand the order of migrations and identify the latest migration. Set `--rev_id` +to the next release version. + +The value of the `--head` argument is the version of the previous migration. + +Edit the newly generated script. Define explicitly SQL statements that have to be +executed both for the `upgrade` and `downgrade` function definitions in the +script. Call execution of these statements, one at a time. Executing multiple statements in one go does not work. See examples in the [versions](./versions) directory. diff --git a/alembic/versions/2.0.0_drop_json_properties_column.py b/alembic/versions/2.0.0_drop_json_properties_column.py new file mode 100644 index 0000000..741e246 --- /dev/null +++ b/alembic/versions/2.0.0_drop_json_properties_column.py @@ -0,0 +1,29 @@ +"""drop_json_properties_column + +Revision ID: 2.0.0 +Revises: 3814003a709a +Create Date: 2024-02-20 10:51:40.326882 + +""" +from alembic import op + +# revision identifiers, used by Alembic. +revision = "2.0.0" +down_revision = "3814003a709a" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + sql = """ + ALTER TABLE sub_product DROP COLUMN properties + """ + op.execute(sql) + + +def downgrade() -> None: + sql = """ + ALTER TABLE sub_product ADD COLUMN properties JSON DEFAULT NULL AFTER value_attr_three + """ + op.execute(sql) + pass diff --git a/lang_qc/db/qc_schema.py b/lang_qc/db/qc_schema.py index 75bb5d2..4d6b6d7 100644 --- a/lang_qc/db/qc_schema.py +++ b/lang_qc/db/qc_schema.py @@ -180,7 +180,6 @@ class SubProduct(Base): value_attr_two = Column(String(20), nullable=False, index=True) id_attr_three = Column(INTEGER, nullable=True, index=True) value_attr_three = Column(String(20), nullable=True, index=True) - properties = Column(JSON, nullable=True) properties_digest = Column(CHAR(64), nullable=False, unique=True) tags = Column(String(255), index=True)