Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: add alembic migration #777

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ target/
.DS_Store
*~

#alembic
alembic.ini

#vim
*.swp
*.swo
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Write the date in place of the "Unreleased" in the case a new version is release
### Added
- Add method to `TableAdapter` which accepts a Python dictionary.
- Added an `Arrow` adapter which supports reading/writing arrow tables via `RecordBatchFileReader`/`RecordBatchFileWriter`.
- Add an alembic catalog migration script to rename `path` parameters of HDF5 nodes to `dataset`.

### Changed
- Make `tiled.client` accept a Python dictionary when fed to `write_dataframe()`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Change 'path' to 'dataset' in HDF5 assets

Revision ID: 562203c724c7
Revises: ed3a4223a600
Create Date: 2024-08-09 10:13:36.384838

"""
import sqlalchemy as sa
from alembic import op

from tiled.catalog.orm import JSONVariant

# revision identifiers, used by Alembic.
revision = "562203c724c7"
down_revision = "ed3a4223a600"
branch_labels = None
depends_on = None


def upgrade():
connection = op.get_bind()
nodes = sa.Table(
"nodes",
sa.MetaData(),
sa.Column("id", sa.Integer),
sa.Column("metadata", JSONVariant),
)

# Loop over all nodes that have 'parameters' field, choose and update those related to hdf5 files
cursor = connection.execute(
sa.select(nodes.c.id, nodes.c.metadata).select_from(nodes)
)
for _id, _md in cursor:
if "hdf5" in (_md.get("mimetype", "") + _md.get("spec", "")).lower():
if isinstance(_md.get("parameters"), dict) and (
"path" in _md["parameters"].keys()
):
_md["parameters"]["dataset"] = _md["parameters"].pop("path")
connection.execute(
nodes.update().where(nodes.c.id == _id).values(metadata=_md)
)


def downgrade():
# This _could_ be implemented but we will wait for a need since we are
# still in alpha releases.
raise NotImplementedError
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def upgrade():
connection = op.get_bind()

if connection.engine.dialect.name == "postgresql":
# This change must be committed befor ethe new 'table' enum value can be used.
# This change must be committed before the new 'table' enum value can be used.
with op.get_context().autocommit_block():
op.execute(
sa.text(
Expand Down
Loading