Skip to content

Commit

Permalink
Dropped column 'properties' from sub_product db table.
Browse files Browse the repository at this point in the history
Ths column is no longer populated.
Updated ORM for LangQC database.
Updated instructions for creating alembic migration
script.
  • Loading branch information
mgcam committed Feb 20, 2024
1 parent a61b76a commit 5a3b99d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 9 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 19 additions & 5 deletions alembic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
29 changes: 29 additions & 0 deletions alembic/versions/2.0.0_drop_json_properties_column.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion lang_qc/db/qc_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 5a3b99d

Please sign in to comment.