Skip to content

Commit 924d367

Browse files
committed
Improve dimesions 6.0.2 migration script.
It will replace NULL filter values with the values provided via command line option.
1 parent a0ae2d5 commit 924d367

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

migrations/dimensions/035dcf13ef18.py

+35
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def upgrade() -> None:
3535
6.0.1 is still validating checksums so we keep checksum from 6.0.1 in the
3636
database.
3737
"""
38+
_check_visit_null_filter()
3839
_do_migration(nullable=False, manager_version="6.0.2")
3940

4041

@@ -85,3 +86,37 @@ def _do_migration(nullable: bool, manager_version: str) -> None:
8586

8687
count = attributes.update(f"version:{MANAGER}", manager_version)
8788
assert count == 1, "expected to update single row"
89+
90+
91+
def _check_visit_null_filter():
92+
"""In some cases we saw that visit.physical_filter column contains NULLs,
93+
and we need to replace that with some non-NULL values.
94+
"""
95+
mig_context = context.get_context()
96+
bind = mig_context.bind
97+
schema = mig_context.version_table_schema
98+
metadata = sa.schema.MetaData(bind, schema=schema)
99+
100+
visit = sa.schema.Table("visit", metadata, autoload_with=bind, schema=schema)
101+
sql = (
102+
sa.select(sa.func.count())
103+
.select_from(visit)
104+
.where(visit.columns["physical_filter"] == None) # noqa: E711
105+
)
106+
num_nulls = bind.execute(sql).scalar()
107+
if num_nulls > 0:
108+
109+
# User needs to pass special argument.
110+
config = context.config
111+
null_filter_value = config.get_section_option("daf_butler_migrate_options", "null_filter_value")
112+
if null_filter_value is None:
113+
raise ValueError(
114+
"NULL values were found for visit.physical_filter. They need to be replaced with"
115+
" non-NULL values. Please use `--options null_filter_value=<value>` command line option."
116+
)
117+
else:
118+
op.execute(
119+
visit.update()
120+
.where(visit.columns["physical_filter"] == None) # noqa: E711
121+
.values(physical_filter=null_filter_value)
122+
)

requirements.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
click >7.0
22
sqlalchemy >= 1.3
33
alembic
4-
git+https://github.com/lsst/daf_butler@main#egg=daf_butler
5-
git+https://github.com/lsst/utils@main#egg=lsst_utils
6-
git+https://github.com/lsst/resources@main#egg=lsst_resources
4+
lsst-daf-butler
5+
lsst-utils
6+
lsst-resources

setup.cfg

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ install_requires =
2222
click >7.0
2323
sqlalchemy >= 1.3
2424
alembic >= 1.7
25-
daf_butler @ git+https://github.com/lsst/daf_butler@main
26-
lsst_utils @ git+https://github.com/lsst/utils@main
27-
lsst_resources @ git+https://github.com/lsst/resources@main
25+
lsst-resources
26+
lsst-utils
27+
lsst-daf-butler
2828
tests_require =
2929
pytest >= 3.2
3030
flake8 >= 3.7.5

0 commit comments

Comments
 (0)