Skip to content

Commit

Permalink
Merge pull request #194 from mgcam/stop_saving_json
Browse files Browse the repository at this point in the history
Made 'properties' column nullable.
  • Loading branch information
nerdstrike authored Feb 12, 2024
2 parents 1f53bdf + aaf8511 commit ec1c362
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 13 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### 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 production code no longer depends on the npg_id_generation
package, therefore this dependency was moved to the dev section
of pyproject.toml. The package is still used by tests and test
fixtures.

## [1.5.1] - 2024-01-25

### Changed
Expand Down
2 changes: 1 addition & 1 deletion alembic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Planned changes should be applied in [lang_qc/db/qc_schema.py](../lang_qc/db/qc_schema.py).
We recommend doing this manually.

Changes to unit test,test fixtures and the source code should be applied as
Changes to unit tests, test fixtures and the source code should be applied as
appropriate.

## Creating migrations for the QC database schema
Expand Down
28 changes: 28 additions & 0 deletions alembic/versions/3814003a709a_make_column_properties_nullable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Make column properties nullable
Revision ID: 3814003a709a
Revises: 36952df5b8ba
Create Date: 2024-02-02 14:30:20.079955
"""
from alembic import op

# revision identifiers, used by Alembic.
revision = "3814003a709a"
down_revision = "36952df5b8ba"
branch_labels = None
depends_on = None


def upgrade() -> None:
sql = """
ALTER TABLE sub_product MODIFY properties JSON DEFAULT NULL
"""
op.execute(sql)


def downgrade() -> None:
sql = """
ALTER TABLE sub_product MODIFY properties JSON NOT NULL
"""
op.execute(sql)
5 changes: 0 additions & 5 deletions lang_qc/db/helper/well.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
for interaction with the LangQC database.
"""

from npg_id_generation.pac_bio import PacBioEntity
from sqlalchemy import select
from sqlalchemy.orm import Session

Expand Down Expand Up @@ -84,9 +83,6 @@ def _create_well(
product_attr_pn = session.execute(
select(SubProductAttr).where(SubProductAttr.attr_name == "plate_number")
).scalar_one()
product_json = PacBioEntity(
run_name=run_name, well_label=well_label, plate_number=plate_number
).model_dump_json()

# TODO: in future for composite products we have to check whether any of
# the `sub_product` table entries we are linking to already exist.
Expand All @@ -103,7 +99,6 @@ def _create_well(
value_attr_three=str(plate_number)
if plate_number is not None
else None,
properties=product_json,
properties_digest=id_product,
)
],
Expand Down
2 changes: 1 addition & 1 deletion lang_qc/db/qc_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ 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=False)
properties = Column(JSON, nullable=True)
properties_digest = Column(CHAR(64), nullable=False, unique=True)
tags = Column(String(255), index=True)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ cryptography = { version = "^40.0.2" }
SQLAlchemy = { version = "^2.0.1", extras = ["pymysql"] }
pydantic = "^2.4"
pydantic-settings = "^2.0"
npg_id_generation = { git = "https://github.com/wtsi-npg/npg_id_generation.git", tag="4.0.1" }

[tool.poetry.dev-dependencies]
npg_id_generation = { git = "https://github.com/wtsi-npg/npg_id_generation.git", tag="4.0.1" }
black = "^22.3.0"
flake8 = "^4.0.1"
pytest = "^7.1.1"
Expand Down
2 changes: 0 additions & 2 deletions tests/fixtures/inbox_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ def setup_data(desired_wells):
mlwhdb_test_session.add(run_metrics)

if state is not None:
json = pbe.model_dump_json()

qc_state = QcState(
created_by="me",
Expand All @@ -186,7 +185,6 @@ def setup_data(desired_wells):
sub_product_attr_=well_label_attr,
value_attr_one=run_name,
value_attr_two=well_label,
properties=json,
properties_digest=id,
),
],
Expand Down
3 changes: 0 additions & 3 deletions tests/fixtures/well_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,6 @@ def load_data4well_retrieval(
run_name=qc_data[0], well_label=qc_data[1], plate_number=qc_data[5]
)
id_product = pbe.hash_product_id()
json = pbe.model_dump_json()
date = datetime.strptime(qc_data[4], DATE_FORMAT)

seq_product = SeqProduct(
Expand All @@ -859,7 +858,6 @@ def load_data4well_retrieval(
value_attr_one=qc_data[0],
value_attr_two=qc_data[1],
value_attr_three=qc_data[5],
properties=json,
properties_digest=id_product,
),
],
Expand Down Expand Up @@ -955,7 +953,6 @@ def load_data4qc_assign(load_dicts_and_users, qcdb_test_session):
value_attr_one="TRACTION_RUN_2",
value_attr_two=label,
value_attr_three="2",
properties=p.model_dump_json(),
properties_digest=id,
),
],
Expand Down

0 comments on commit ec1c362

Please sign in to comment.