diff --git a/scripts/migrate-legacy/README.md b/scripts/migrate-legacy/README.md index dc59ae5..bce89e7 100644 --- a/scripts/migrate-legacy/README.md +++ b/scripts/migrate-legacy/README.md @@ -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 | | `categories` | `data.categories` | id kept; `is_private` → **`is_public`** (inverted) | | `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` | | `file_tag` | `data.file_tag` | orphan rows skipped | | `pools` | `data.pools` | id kept; `parent_id` + `created` preserved under `metadata` (see below) | diff --git a/scripts/migrate-legacy/transform.sql b/scripts/migrate-legacy/transform.sql index d66206d..b1dcdcd 100644 --- a/scripts/migrate-legacy/transform.sql +++ b/scripts/migrate-legacy/transform.sql @@ -92,14 +92,17 @@ JOIN user_id_map um ON um.old_id = t.creator_id 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. -- --------------------------------------------------------------------------- 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 -WHERE EXISTS (SELECT 1 FROM data.tags t WHERE t.id = a.parent_id) - AND EXISTS (SELECT 1 FROM data.tags t WHERE t.id = a.child_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.parent_id) ON CONFLICT (when_tag_id, then_tag_id) DO NOTHING; -- ---------------------------------------------------------------------------