feat: data migration to retype doc notes to new NoteType values #230

Merged
forgejo_admin merged 1 commit from 224-data-migration-retype-notes into main 2026-03-28 04:02:06 +00:00

Summary

  • Alembic data migration that retypes existing notes to use the new NoteType values added in #223
  • Promotes doc notes to specific types based on tag/slug patterns (review, architecture, validation, board)
  • Consolidates deprecated types (reference, journal, incident, post, issue) back to doc

Changes

  • alembic/versions/s9n0o1p2q3r4_data_migration_retype_notes.py: New data-only migration with 9 retype steps -- review (tag-based JOIN on note_tags/tags), architecture/validation/board (slug LIKE patterns), and 5 deprecated type consolidations. All steps idempotent via WHERE guards. Downgrade reverses slug/tag-based retypes (steps 1-4).
  • tests/test_retype_migration.py: 9 tests covering each retype category, unrelated note preservation, already-migrated note safety, idempotency (double upgrade), and downgrade reversal.

Test Plan

  • pytest tests/test_retype_migration.py -v -- 9/9 pass
  • pytest tests/ -v -- 668 pass, 12 fail (pre-existing failures in test_board_sync.py, confirmed identical on main)
  • ruff format and ruff check clean
  • Run alembic upgrade head against staging/prod database after merge

Review Checklist

  • Passed automated review-fix loop
  • No secrets committed
  • No unnecessary file changes
  • Commit messages are descriptive
  • Closes #224
  • pal-e-docs -- the project this work belongs to
  • Depends on PR #226 (NoteType enum expansion, already merged to main)
## Summary - Alembic data migration that retypes existing notes to use the new NoteType values added in #223 - Promotes doc notes to specific types based on tag/slug patterns (review, architecture, validation, board) - Consolidates deprecated types (reference, journal, incident, post, issue) back to doc ## Changes - `alembic/versions/s9n0o1p2q3r4_data_migration_retype_notes.py`: New data-only migration with 9 retype steps -- review (tag-based JOIN on note_tags/tags), architecture/validation/board (slug LIKE patterns), and 5 deprecated type consolidations. All steps idempotent via WHERE guards. Downgrade reverses slug/tag-based retypes (steps 1-4). - `tests/test_retype_migration.py`: 9 tests covering each retype category, unrelated note preservation, already-migrated note safety, idempotency (double upgrade), and downgrade reversal. ## Test Plan - [x] `pytest tests/test_retype_migration.py -v` -- 9/9 pass - [x] `pytest tests/ -v` -- 668 pass, 12 fail (pre-existing failures in test_board_sync.py, confirmed identical on main) - [x] `ruff format` and `ruff check` clean - [ ] Run `alembic upgrade head` against staging/prod database after merge ## Review Checklist - [x] Passed automated review-fix loop - [x] No secrets committed - [x] No unnecessary file changes - [x] Commit messages are descriptive ## Related Notes - Closes #224 - `pal-e-docs` -- the project this work belongs to - Depends on PR #226 (NoteType enum expansion, already merged to main)
feat: data migration to retype doc notes to new NoteType values
Some checks failed
ci/woodpecker/pr/woodpecker Pipeline failed
9f1d904924
Retypes notes based on tag/slug patterns (doc->review, doc->architecture,
doc->validation, doc->board) and consolidates deprecated types (reference,
journal, incident, post, issue) back to doc. All steps are idempotent.

Closes #224

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Author
Owner

QA Review -- PR #230

Migration (s9n0o1p2q3r4_data_migration_retype_notes.py)

  • Revision chain correct: r8m9n0o1p2q3 -> s9n0o1p2q3r4
  • All 9 retype steps match issue #224 spec exactly
  • Step 1 (review): Proper JOIN on note_tags/tags tables with note_type = 'doc' guard
  • Steps 2-4 (arch/validation/board): Slug LIKE patterns with note_type = 'doc' guard
  • Steps 5-9 (consolidation): Loop over deprecated types, clean and correct
  • Idempotency: All WHERE clauses only match pre-migration state, safe to run twice
  • Downgrade: Correctly reverses steps 1-4 (deterministic); steps 5-9 acknowledged as irreversible with clear comments

Note: Steps 5-9 use f-string SQL (f"...'{old_type}'..."). The values are hardcoded string constants, not user input, so no injection risk. Acceptable for Alembic data migrations.

Tests (test_retype_migration.py)

  • 9 tests covering all categories: review, architecture, validation, board, deprecated consolidation, unrelated preservation, already-migrated safety, idempotency, downgrade
  • Seed data includes edge cases (already-typed review/architecture notes)
  • Clean importlib.util approach for loading migration module from file path
  • Proper MigrationContext binding and session cleanup

Test Results

  • 9/9 new tests pass
  • 668/680 full suite pass (12 failures in test_board_sync.py are pre-existing on main)
  • ruff format/check clean

Nits

None found.

VERDICT: APPROVE

## QA Review -- PR #230 ### Migration (`s9n0o1p2q3r4_data_migration_retype_notes.py`) - Revision chain correct: `r8m9n0o1p2q3` -> `s9n0o1p2q3r4` - All 9 retype steps match issue #224 spec exactly - Step 1 (review): Proper JOIN on `note_tags`/`tags` tables with `note_type = 'doc'` guard - Steps 2-4 (arch/validation/board): Slug LIKE patterns with `note_type = 'doc'` guard - Steps 5-9 (consolidation): Loop over deprecated types, clean and correct - Idempotency: All WHERE clauses only match pre-migration state, safe to run twice - Downgrade: Correctly reverses steps 1-4 (deterministic); steps 5-9 acknowledged as irreversible with clear comments **Note:** Steps 5-9 use f-string SQL (`f"...'{old_type}'..."`). The values are hardcoded string constants, not user input, so no injection risk. Acceptable for Alembic data migrations. ### Tests (`test_retype_migration.py`) - 9 tests covering all categories: review, architecture, validation, board, deprecated consolidation, unrelated preservation, already-migrated safety, idempotency, downgrade - Seed data includes edge cases (already-typed review/architecture notes) - Clean `importlib.util` approach for loading migration module from file path - Proper MigrationContext binding and session cleanup ### Test Results - 9/9 new tests pass - 668/680 full suite pass (12 failures in `test_board_sync.py` are pre-existing on main) - ruff format/check clean ### Nits None found. **VERDICT: APPROVE**
forgejo_admin deleted branch 224-data-migration-retype-notes 2026-03-28 04:02:06 +00:00
Sign in to join this conversation.
No description provided.