fix(scripts): correct autotag rule direction in legacy migration
The old autotags worked child -> parent (adding child_id pulled in parent_id, per tfm__add_file_to_tag_recursive). The new tag_rules model is "when_tag applied -> then_tag follows", so child must map to when_tag and parent to then_tag. The transform had it reversed, so migrated rules never fired — adding a tag added only itself. Map child_id -> when_tag_id, parent_id -> then_tag_id. Verified on a scratch DB. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -56,7 +56,7 @@ psql "$NEW_DSN" -v ON_ERROR_STOP=1 -f transform.sql
|
|||||||
| `mime` | `core.mime_types` | id **uuid → smallint** (remapped by `name`); types not already seeded are added |
|
| `mime` | `core.mime_types` | id **uuid → smallint** (remapped by `name`); types not already seeded are added |
|
||||||
| `categories` | `data.categories` | id kept; `is_private` → **`is_public`** (inverted) |
|
| `categories` | `data.categories` | id kept; `is_private` → **`is_public`** (inverted) |
|
||||||
| `tags` | `data.tags` | id + `category_id` kept; inverted privacy |
|
| `tags` | `data.tags` | id + `category_id` kept; inverted privacy |
|
||||||
| `autotags` | `data.tag_rules` | `parent_id` → `when_tag_id`, `child_id` → `then_tag_id` |
|
| `autotags` | `data.tag_rules` | `child_id` → `when_tag_id`, `parent_id` → `then_tag_id` (old: adding the child pulled in the parent) |
|
||||||
| `files` | `data.files` | id kept; `datetime` → `content_datetime`; `orig_name` → `original_name`; **EXIF** lifted from `metadata->'exif'` into the `exif` column, the rest stays as user `metadata` |
|
| `files` | `data.files` | id kept; `datetime` → `content_datetime`; `orig_name` → `original_name`; **EXIF** lifted from `metadata->'exif'` into the `exif` column, the rest stays as user `metadata` |
|
||||||
| `file_tag` | `data.file_tag` | orphan rows skipped |
|
| `file_tag` | `data.file_tag` | orphan rows skipped |
|
||||||
| `pools` | `data.pools` | id kept; `parent_id` + `created` preserved under `metadata` (see below) |
|
| `pools` | `data.pools` | id kept; `parent_id` + `created` preserved under `metadata` (see below) |
|
||||||
|
|||||||
@@ -92,14 +92,17 @@ JOIN user_id_map um ON um.old_id = t.creator_id
|
|||||||
ON CONFLICT (id) DO NOTHING;
|
ON CONFLICT (id) DO NOTHING;
|
||||||
|
|
||||||
-- ---------------------------------------------------------------------------
|
-- ---------------------------------------------------------------------------
|
||||||
-- 5. Tag rules (old `autotags`): parent -> when_tag, child -> then_tag.
|
-- 5. Tag rules (old `autotags`). In the old schema adding the child tag pulled
|
||||||
|
-- in its parent (tfm__add_file_to_tag_recursive: for child_id = t_id it adds
|
||||||
|
-- parent_id). The new model is "when_tag applied -> then_tag follows", so the
|
||||||
|
-- trigger child becomes when_tag and the auto-applied parent becomes then_tag.
|
||||||
-- Skip rules whose tags didn't migrate.
|
-- Skip rules whose tags didn't migrate.
|
||||||
-- ---------------------------------------------------------------------------
|
-- ---------------------------------------------------------------------------
|
||||||
INSERT INTO data.tag_rules (when_tag_id, then_tag_id, is_active)
|
INSERT INTO data.tag_rules (when_tag_id, then_tag_id, is_active)
|
||||||
SELECT a.parent_id, a.child_id, a.is_active
|
SELECT a.child_id, a.parent_id, a.is_active
|
||||||
FROM legacy.autotags a
|
FROM legacy.autotags a
|
||||||
WHERE EXISTS (SELECT 1 FROM data.tags t WHERE t.id = a.parent_id)
|
WHERE EXISTS (SELECT 1 FROM data.tags t WHERE t.id = a.child_id)
|
||||||
AND EXISTS (SELECT 1 FROM data.tags t WHERE t.id = a.child_id)
|
AND EXISTS (SELECT 1 FROM data.tags t WHERE t.id = a.parent_id)
|
||||||
ON CONFLICT (when_tag_id, then_tag_id) DO NOTHING;
|
ON CONFLICT (when_tag_id, then_tag_id) DO NOTHING;
|
||||||
|
|
||||||
-- ---------------------------------------------------------------------------
|
-- ---------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user