agentleFS
J3d1-fmJ3d1-fm/Personal-Task-Assistant/.claude/skills/db-schema-change/SKILL.md

db-schema-change

Skill0 starsChanged 3 months agoMITView on GitHub

How to change the task database schema in this repository — Alembic revisions, the legacy-database stamping heuristic, dual-store (SQLite + Firestore) updates, and the required migration tests. Use this BEFORE adding, renaming, or removing any column or table, changing an enum, or touching app/models.py, app/migrate.py, or migrations/ — even for a "trivial" new field.

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. hiroppy/mf-dashboard★ 426same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository6 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    add the new column to the expected-columns assertions.

    line 42
  2. Very specific:

    keep the legacy-upgrade test honest: its LEGACY_TASKS_TABLE SQL reproduces the 0.3.x schema and must NOT gain your new column — the test …

    line 43
  3. Very specific:

    run the full suite (.venv/bin/pytest -q) — conftest exercises the stamping path on every run.

    line 46

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Changing the schema

Schema changes here must work for three kinds of databases at once: fresh installs, databases created by pre-0.4.0 releases via create_all (no alembic_version table), and Firestore documents that never migrate. A change that only works for your local fresh DB will corrupt or crash real user installs on their next git pull, which is why create_all is never the answer.

Steps

  1. New Alembic revision in migrations/versions/, numbered sequentially (0003_...py), using migrations/versions/0002_add_task_external_id.py as the template. Hardcode enum value lists in the migration — do not import app models into migration files; migrations must stay frozen while models evolve.
  2. Update the model and schemas together: app/models.py (column), app/schemas.py (TaskBase/TaskUpdate/TaskRead fields with validation constraints). New fields must be optional or have defaults — old rows and old Firestore documents will not have them.
  3. Update the stamping heuristic in app/migrate.py. It detects databases without alembic_version and decides which revision they match by inspecting the tasks columns (currently: external_id present → head, absent → 0001). When your revision adds a column, make that column the new marker and bump HEAD_REVISION; otherwise a fresh create_all-shaped database (the test suite creates these) gets stamped too low and the upgrade fails on an already-existing column.
  4. Both stores: SqliteTaskStore usually needs nothing beyond the model; FirestoreTaskStore is schemaless but needs the field handled in encode_task_data (enums → values) and must tolerate documents missing the field (defaults in TaskRead cover this).
  5. Tests — extend tests/test_migrations.py:
    • add the new column to the expected-columns assertions;
    • keep the legacy-upgrade test honest: its LEGACY_TASKS_TABLE SQL reproduces the 0.3.x schema and must NOT gain your new column — the test proves old databases upgrade cleanly with data intact;
    • run the full suite (.venv/bin/pytest -q) — conftest exercises the stamping path on every run.

Gotchas learned the hard way

  • SQLite ignores timezone info: DateTime(timezone=True) columns come back naive. Application code normalizes naive datetimes as UTC (_normalized_datetime in app/main.py); keep that assumption.
  • SQLite ALTER is limited — plain ADD COLUMN is fine; anything structural (drop/rename/constraint change) needs batch mode, which migrations/env.py already enables via render_as_batch for SQLite.
  • Unique + nullable works on SQLite (multiple NULLs allowed) — that is why external_id can be both optional and unique.

Ship the change via the ship-release skill; schema releases are minor version bumps.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.