Skip to content

Data migrations framework + new site-type transfers, Typer CLI, and NMA notes backfill#464

Open
jirhiker wants to merge 4 commits intostagingfrom
feature/structured-data-migrations
Open

Data migrations framework + new site-type transfers, Typer CLI, and NMA notes backfill#464
jirhiker wants to merge 4 commits intostagingfrom
feature/structured-data-migrations

Conversation

@jirhiker
Copy link
Member

@jirhiker jirhiker commented Feb 5, 2026

Summary

  • Added a repeatable data migration framework tied to Alembic revision state with CLI tooling and tests.
  • Added new non‑well site-type transfers and lexicon entries.
  • Migrated CLI from Click to Typer.
  • Added a data migration to move Location.nma_location_notes into the polymorphic Notes table.

Key Changes

  • Data migrations

    • data_migrations/ framework with registry, runner, history table, and Typer CLI.
    • Enforces applied Alembic revision before running a data migration.
    • Added template under data_migrations/migrations/_template.py.
    • New migration: 20260205_0001_move_nma_location_notes.
  • Transfers

    • Added per‑site-type transfer functions for new LU_SiteType entries.
    • Added env toggles for each new transfer.
    • Updated non‑well task selection logic.
  • CLI

    • Switched CLI to Typer.
    • Added data-migrations command group and alembic-upgrade-and-data.
  • Tests

    • Added unit tests for new site-type transfer helpers.
    • Added tests for data migration CLI and the notes backfill.

Behavioral Notes

  • Data migrations now require the referenced Alembic revision to be applied.
  • New note backfill is idempotent (skips duplicates) and clears nma_location_notes.

How to Test

  1. source .venv/bin/activate
  2. pytest tests/test_thing_transfer.py tests/test_data_migrations.py tests/test_data_migrations_cli.py tests/test_cli_commands.py

Follow-ups

  • Decide on a canonical note_type for location legacy notes if “General” isn’t desired.
  • Add additional data migrations to registry as needed.
  • Add future migration to drop Location.nma_location_notes

@jirhiker jirhiker requested review from Copilot, kbighorse and ksmuczynski and removed request for Copilot February 5, 2026 12:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a structured data migrations framework tied to Alembic revisions, migrates the CLI from Click to Typer, and implements a data migration to move Location.nma_location_notes into the polymorphic Notes table. It also adds site-type transfer functions for non-well locations.

Changes:

  • Implemented a repeatable data migration framework with registry, runner, history tracking, and CLI commands
  • Added transfer functions for six new site types (rock sample, diversion, lake/pond, soil gas, outfall, other)
  • Migrated CLI from Click to Typer with new data-migrations command group and alembic-upgrade-and-data command

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_thing_transfer.py Tests for new site-type transfer helper functions
tests/test_data_migrations_cli.py Unit tests for data migration CLI commands (list, run, run-all)
tests/test_data_migrations.py Tests for NMA location notes migration including idempotency checks
tests/test_cli_commands.py Updated import from Click to Typer testing utilities
pyproject.toml Added typer dependency
data_migrations/runner.py Core runner logic with history table, status tracking, and migration execution
data_migrations/registry.py Auto-discovery and registration of data migrations
data_migrations/migrations/_template.py Template for creating new data migrations
data_migrations/migrations/__init__.py Package initialization file
data_migrations/migrations/20260205_0001_move_nma_location_notes.py Migration to backfill legacy location notes
data_migrations/base.py Base DataMigration dataclass definition
data_migrations/__init__.py Package initialization file
cli/cli.py Refactored from Click to Typer with new data migration commands
AGENTS.MD Added documentation on data migration idempotency requirements

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 5, 2026 12:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 15 changed files in this pull request and generated 1 comment.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 060e7d56e9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jirhiker jirhiker changed the title Feature/structured data migrations Data migrations framework + new site-type transfers, Typer CLI, and NMA notes backfill Feb 5, 2026
Comment on lines +31 to +38
MIGRATION = DataMigration(
id="YYYYMMDD_0000",
alembic_revision="REVISION_ID",
name="Short migration name",
description="Why this data migration exists.",
run=run,
is_repeatable=False,
)
Copy link
Contributor

@jacob-a-brown jacob-a-brown Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the template a lot! It'll help moving forward. Is alembic_revision the ID of the alembic head script at the moment the migration is defined? So that we can identify at what stage in the DB's life the migration was made

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep thats it exactly.

Copy link
Contributor

@jacob-a-brown jacob-a-brown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I think it looks good! And like the data migration tracking. If nma_location_notes is being moved to the polymorphic Notes table should that field be removed from the Location table?

@jirhiker
Copy link
Member Author

jirhiker commented Feb 5, 2026

Nma_location_notes will be removed in a subsequent alembic migration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants