agentleFS
KevinArceKevinArce/create-bun-api/skills/add-model/SKILL.md

add-model

Skill11 starsChanged 22 days agoApache-2.0View on GitHub

Add or change a database table in a create-bun-api project (SQLite via bun:sqlite) using an append-only migration and a typed repository. Use when asked to add a model, table, column, index, or relation, or to persist new data.

13 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, 0 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 11 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use COLLATE NOCASE for case-insensitive unique text such as emails.

    line 15

“Common” is measured: kept by at least 6 in 10 of the 11 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 or change a model

  1. Append a migration to src/db/migrations.ts with the next id (000N_<verb>_<table>). Never edit, reorder, or delete a migration that may already have run somewhere.
  2. SQL conventions:

    • Ids are INTEGER PRIMARY KEY AUTOINCREMENT. Columns are snake_case.
    • Timestamps: TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')).
    • Foreign keys are enforced. Write REFERENCES users(id) ON DELETE CASCADE and index every foreign key column.
    • Use COLLATE NOCASE for case-insensitive unique text such as emails.
    • One migration may contain several statements.
    {
      id: "0002_create_notes",
      sql: `
        CREATE TABLE notes (
          id         INTEGER PRIMARY KEY AUTOINCREMENT,
          user_id    INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
          title      TEXT    NOT NULL,
          created_at TEXT    NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
        );
        CREATE INDEX notes_user_id ON notes (user_id);
      `,
    },
  3. Changing an existing table: ALTER TABLE … ADD COLUMN (nullable or with a DEFAULT) and ALTER TABLE … RENAME COLUMN work directly. Dropping a column or changing its type or constraints needs a table rebuild. Follow references/table-rebuild.md exactly: without disableForeignKeys: true, the rebuild silently deletes child rows.
  4. Repository (src/modules/<name>/<name>.repository.ts):
    • Prepare each statement once with db.query<Row, Params>(sql), using $named parameters. Pass the object without the $ ({ userId } for $userId). The database runs in strict mode and throws on a missing parameter.
    • Map snake_case rows to camelCase domain objects in one toX() function. Never return secrets such as password hashes.
    • For unique violations, check error.code === "SQLITE_CONSTRAINT_UNIQUE" and return null; the service then throws conflict().
  5. Test through the HTTP routes with createTestApp(). It gives a fresh in-memory database with every migration applied. Add a direct test in src/db/migrations.test.ts only for migrations that move data.
  6. Run bun run verify.

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.