agentleFS
allswebtechallswebtech/trouteai/.claude/skills/add-migration/SKILL.md

add-migration

Skill36 starsChanged 19 days agoMITView on GitHub

Add a database change to TRouteAI the safe way (an additive SQL migration and its database module). Use when a change needs a new table, column or index, or new stored data.

17 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

1 rule. 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 15 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Check it on a copy, never on real data:

    line 33

“Common” is measured: kept by at least 6 in 10 of the 15 edited versions of this file we could read. “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

Add a database change

Change wanted: $ARGUMENTS

The one rule: migrations only add. New tables, new columns, new indexes. Never DROP, never rename a table or a column, never change what an existing column means. During an update the old and the new version share one SQLite file for a moment, and a rollback runs old code on the new schema. If the change seems to need a rename or a removal, stop and propose an additive design (a new column, the old one left in place).

  1. Find the next number: ls src/lib/db/migrations | tail -3. Files are named NNN_short_name.sql and run in name order, so keep three digits. Two files with the same number stop the app at start.
  2. Write the migration as plain SQL that can run twice without harm: CREATE TABLE IF NOT EXISTS …, CREATE INDEX IF NOT EXISTS …, ALTER TABLE … ADD COLUMN … with a default so existing rows stay valid. Copy the style of the newest file in the folder.
  3. Use SQL every driver runs. The app works on better-sqlite3, on Node's built-in node:sqlite and on sql.js. No extension functions, no driver-specific syntax.
  4. Database code goes in src/lib/db/<module>.ts (copy a small one such as featureFlags.ts): import getDbInstance from ./core, export small functions, and add export * from "./db/<module>" to src/lib/localDb.ts. Routes never contain SQL.
  5. Secrets stored in the database go through encryptConnectionFields() (src/lib/db/encryption.ts) or the secrets module. Never store a credential in plain text and never log one.

Check it on a copy, never on real data:

  • Fresh database: start the app with DATA_DIR=$(mktemp -d) and a spare port; it must start without a migration error.
  • Existing database: start the previous build once in a temporary data folder, then start the new build on the same folder. The migration must apply, and a backup must appear in db_backups/ inside that folder.
  • Then the old build must still start on the migrated folder (the rollback case).

Finish with the verify skill and say which of the three starts you ran.

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.