engine/migrations/v1_to_v2.py: option sub_category->sub_categories[]; sub-category name slugify (whitespace/grammar chars->_, reserved suffixed, de-duped) cascaded to options + tag_groups; instance category_filter list->boolean-expr string + exclude_null flag; nested @{uuid:a,b,null} refs->@{uuid:a or b!null}. Idempotent. Two entry points share one core: envelope migrate_v1_to_v2 (import/export, registered in _CHAIN) + per-row migrate_module/bundle_v1_to_v2 (lazy/bulk DB path).
Register _CHAIN[1] + bump engine CURRENT_SCHEMA_VERSION 1->2. New SQL migration 016 marches stale DB rows 1->2 at boot via run_bulk_lazy + the per-row migrators (014's documented bump pattern). TS mirror (migrations.ts) + client CURRENT bump follow next (no cross-language version assertion couples them). Update version/entity-count assertions in payload-migration, migration-runner, and export-build tests.
29 lines
1.2 KiB
Python
29 lines
1.2 KiB
Python
"""Envelope migration chain walks v1 -> CURRENT (2)."""
|
|
from engine.migrations import CURRENT_SCHEMA_VERSION, migrate_payload
|
|
|
|
|
|
def test_current_schema_version_is_2():
|
|
assert CURRENT_SCHEMA_VERSION == 2
|
|
|
|
|
|
def test_chain_v1_to_current():
|
|
out = migrate_payload({"schema_version": 1, "wildcards": [
|
|
{"id": "w", "payload": {"sub_categories": ["warm"], "options": [
|
|
{"id": "o", "value": "x", "weight": 1, "sub_category": "warm"}]}}]})
|
|
assert out["ok"] is True
|
|
assert out["migrated"]["schema_version"] == 2
|
|
opt = out["migrated"]["wildcards"][0]["payload"]["options"][0]
|
|
assert opt["sub_categories"] == ["warm"]
|
|
|
|
|
|
def test_chain_v0_to_current_walks_both_steps():
|
|
out = migrate_payload({"schema_version": 0, "wildcards": [
|
|
{"id": "w", "payload": {"sub_categories": ["warm"], "options": [
|
|
{"id": "o", "value": "x", "weight": 1, "sub_category": "warm"}]}}]})
|
|
assert out["ok"] is True
|
|
assert out["migrated"]["schema_version"] == 2
|
|
# v0->v1 tags migrated_from; v1->v2 converts the option tag.
|
|
w = out["migrated"]["wildcards"][0]
|
|
assert w["migrated_from"] == 0
|
|
assert w["payload"]["options"][0]["sub_categories"] == ["warm"]
|