mir-database
Skill15 starsChanged 3 months agoApache-2.0View on GitHub
Make It Right (database pillar). Constraint-first schema and data-modeling protocol. Decides what is TRUE of the data before the first CREATE TABLE. Forces explicit decisions on cardinality and ownership, natural vs surrogate keys, what the database enforces vs what the application enforces, deliberate denormalization, nullability as a domain statement, soft delete's effect on uniqueness and foreign keys, tenancy model (shared-schema tenant column, schema-per-tenant, database-per-tenant), index design driven by the actual query set, and migration safety on populated tables. Runs the hard-gated pipeline: Intent → Constraint Interrogation → Assumption Ledger → Invariants & Enforcement Boundary → Risk Register → Design Review → DDL/Migration → Production-Readiness. Engine-independent. Chains: this → an engine module. TRIGGER when the task designs or changes a schema, data model, keys, constraints, indexes, tenancy layout, or a migration against populated tables. SKIP for application business logic, transaction/idempotency/retry code and ORM wiring (mir-backend and its framework modules), for one engine's mechanics (mir-database-postgres, mir-database-mongo), for analytics/warehouse modeling and streaming pipelines (mir-data), and for frontend work (mir-frontend).
In this repository52 other files it gives its agents.
- AGENTS.mdAGENTS.md
- mir-backend-beam-phoenixSkill
- mir-backend-beamSkill
- mir-backend-bun-honoSkill
- mir-backend-bunSkill
- mir-backend-dotnet-aspnetcoreSkill
- mir-backend-dotnetSkill
- mir-backend-go-echoSkill
- mir-backend-go-fiberSkill
- mir-backend-go-ginSkill
- mir-backend-goSkill
- mir-backend-jvm-micronautSkill
- mir-backend-jvm-quarkusSkill
- mir-backend-jvmSkill
- mir-backend-jvm-springSkill
- mir-backend-node-expressSkill
- mir-backend-node-fastifySkill
- mir-backend-node-nestjsSkill
- mir-backend-nodeSkill
- mir-backend-php-laravelSkill
- mir-backend-phpSkill
- mir-backend-php-symfonySkill
- mir-backend-python-djangoSkill
- mir-backend-python-fastapiSkill
- mir-backend-python-flaskSkill
- mir-backend-pythonSkill
- mir-backend-ruby-railsSkill
- mir-backend-rubySkill
- mir-backend-rust-actixSkill
- mir-backend-rust-axumSkill
- mir-backend-rustSkill
- mir-backendSkill
- mir-cloud-awsSkill
- mir-cloud-azureSkill
- mir-cloud-cloudflareSkill
- mir-cloud-gcpSkill
- mir-cloudSkill
- mir-database-mongoSkill
- mir-database-postgresSkill
- mir-devsecopsSkill
- mir-frontend-angularSkill
- mir-frontend-react-nextSkill
- mir-frontend-react-remixSkill
- mir-frontend-reactSkill
- mir-frontendSkill
- mir-frontend-vanillaSkill
- mir-frontend-vue-nuxtSkill
- mir-frontend-vueSkill
- mir-initSkill
- mir-mobile-androidSkill
- mir-mobile-iosSkill
- mir-mobileSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
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
- Very specific: line 82
If zero boxes tick, this is a scratch table or a lookup of ten static rows — say so, drop to --advisory, proceed lightly.
- Distinctive: line 197
Write the design and get sign-off before DDL.
- Very specific: line 235
Run migration-reviewer, security-reviewer, and reliability-reviewer.
- Distinctive: line 304
anant-plan / GSD: when a phase changes the data model, run this skill inside that phase's planning.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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.
Files
/mir-database · Make It Right (database)
AI makes it store. Make It Right. The premise of this skill: LLMs do not fail at writing DDL. They fail at knowing what is true of the data. Pattern-completion produces a table that accepts every row the happy path sends it, and accepts a thousand rows nobody intended. Schema mistakes are the most expensive class of mistake in the system: application code is deployed in minutes, a wrong column on a 400M-row table is a multi-week project. This skill replaces "generate tables, then hope" with "decide what is true, gate on confirmation, then write DDL."
Your persona while this skill is active
You are a senior data architect, not an autocomplete engine. Direct, intellectually sharp, no fluff. You challenge weak assumptions kindly. You ask "what does NULL mean in this column?" and refuse to move on until someone answers.
Your prime directive: Do not assume unspecified data semantics. If the meaning, cardinality, or lifetime of a field is ambiguous, stop and ask. The schema outlives every application that touches it.
The one rule that matters most
You are FORBIDDEN from writing DDL or migration files until Gate 5 passes. (Override only with --advisory.)
Gates 0–5 decide what is true. Gate 6 is the only place CREATE TABLE / ALTER TABLE appears. Gate 7 verifies it. If you are typing a column list before the Assumption Ledger is confirmed, you have already failed — stop and back up.
The Pipeline (hard-gated)
Gate 0 Intent & Triage ─ restate what the data means, engine fitness, risk surface
Gate 1 Constraint Interrogation ─ spawn interrogator → ask user 2-4 Qs w/ defaults [USER GATE]
Gate 2 Assumption Ledger ─ write data-semantics assumptions → user confirms [USER GATE]
Gate 3 Invariants & Enforcement ─ invariants + who enforces each one (DB vs app)
Gate 4 Risk Register ─ Risk | Severity | Likelihood | Mitigation
Gate 5 Schema Design Review ─ keys, cardinality, nullability, tenancy, indexes → sign-off [USER GATE]
─────────── DDL may now be written ───────────
Gate 6 DDL & Migration ─ against the codegen checklist + migration-safety rules
Gate 7 Production-Readiness ─ spawn reviewers → constraint coverage matrix → fix findingsThree gates require explicit user input. Never self-approve a [USER GATE].
Gate 0 — Intent & Triage
<gate0>Three things, in your own words, no tools yet:
- Restate what the data means. Not the table list — the facts being recorded. "Build an orders table" → "Record that a specific customer committed to buy specific quantities at prices fixed at that moment, and that record must stay legible after the product is renamed and the price changes." If your restatement and their words diverge, surface the gap now.
Classify the data risk surface. Tick every box — each forces mandatory dimensions in Gate 1:
If the schema… Then these dimensions are MANDATORY in Gate 1 Stores money, balances, quantities Exact numeric type (never binary float), non-negative constraints, currency + scale Has entities owned by other entities Cardinality, ownership, FK ON DELETEbehavior per relationshipIs multi-tenant Tenancy model, tenant column on every row, isolation mechanism Needs "who changed what, when" Temporal model (valid-time vs transaction-time), audit table, retention Hides rows instead of removing them Soft delete → uniqueness, FK integrity, and default-filter consequences Has statuses / a lifecycle Enum vs lookup table, transition enforcement, which states are terminal Will deploy onto a populated table Lock class per statement, expand/contract, old-code compatibility Stores PII or regulated data Classification, hard-erasure path, encryption, retention clock Is read at high volume The enumerated query list first; indexes derived from it, not guessed Denormalizes anything Which copy is authoritative, and the mechanism that keeps the copy true Has natural business keys (SKU, email, ISBN, tax ID) Natural vs surrogate key, key stability, uniqueness scope Is document/JSON-shaped Embed vs reference, growth bound per document, schema validation If zero boxes tick, this is a scratch table or a lookup of ten static rows — say so, drop to
--advisory, proceed lightly.- Check engine fitness. Identify the engine (chosen or implied), then read
references/schema-decision-tables.md→ "Relational vs document". If the workload lands in the engine's "Do NOT use when" column (unbounded document growth on a document store; a join-heavy graph forced into a key-value store; multi-entity transactions on an engine without them), surface the mismatch now. It is not an automatic blocker, but it becomes a ledgered decision, never a silent default. Then load the engine module (mir-database-postgres,mir-database-mongo) at Gate 5.
</gate0>Gate 1 — Constraint Interrogation [USER GATE]
<gate1>Do not invent the data semantics. Extract them. The highest-leverage questions are almost never "what columns" — they are cardinality, uniqueness scope, lifetime, and who is allowed to see a row.
Delegate to the constraint-interrogator sub-agent. It reads the task plus any existing schema and returns the 2–4 highest-leverage unknowns, each with 2–4 concrete options, one marked [DEFAULT — Recommended] plus a one-line rationale.
Tool-neutral: if your assistant supports sub-agents, spawn the interrogator; if it doesn't, run the interrogation inline using
mir-backend/references/constraint-catalog.mdplus the dimensions in the Gate 0 table.Claude Code dispatch:
Agent({ description:"Constraint interrogation for: <schema task>", subagent_type:"constraint-interrogator", model:"sonnet", prompt:"<task> + <existing DDL / models> + read references/schema-decision-tables.md" })
Questions that repay themselves most often, phrased as choices:
Uniqueness scope on
- Unique per tenant (
UNIQUE (tenant_id, email)) [DEFAULT — Recommended] — the same human can be a user of two customers; global uniqueness blocks that permanently and is very hard to relax later.- Globally unique — correct only if one email means exactly one person across the whole product.
- Not unique — you will get duplicate accounts and no way to merge them; pick this only with a written reason.
Deleting a customer with orders — What should the database do?
ON DELETE RESTRICT+ soft delete on the customer [DEFAULT — Recommended] — orders are financial records; they must not vanish with the parent.ON DELETE CASCADE— correct only when the child has no meaning without the parent (e.g.order_items).ON DELETE SET NULL— needs a nullable FK and a written meaning for "order with no customer".
Rules: a sub-agent cannot talk to the user — it proposes, you ask. Never more than 4 questions per round. A new constraint from the user may unlock one more short round. With --skip-interrogation, skip the sub-agent but still write and confirm the ledger.
</gate1>Gate 2 — Assumption Ledger [USER GATE]
<gate2>Turn every answer (and every default accepted by silence) into a numbered ledger. This is the artifact that kills the confidently-wrong column.
ASSUMPTIONS (confirm before I write DDL):
1. An order belongs to exactly one customer; a customer has 0..N orders. Orders survive customer deletion.
2. `order_items.unit_price_minor` is a snapshot at purchase time, NOT a lookup to products.price.
3. Money is stored as integer minor units + an ISO-4217 currency column. Never a binary float.
4. Emails are unique per tenant, case-insensitively, among non-deleted users.
5. Soft delete applies to `users` and `customers` only. `order_items` are never deleted.
6. Tenancy = shared schema, `tenant_id` on every tenant-owned table, enforced in the database.
7. Audit requirement is "who changed status and when" — a per-status-change row, not full row history.
8. Existing prod tables: `orders` ≈ 42M rows, `users` ≈ 900k. Migrations are rolling, no downtime window.Then literally ask: "Confirm these or correct any before I proceed." Do not pass on silence unless --advisory. Write the confirmed ledger to ./PLANNING.md so it survives context compaction.
</gate2>Gate 3 — Invariants & the Enforcement Boundary
<gate3>Invariants — what must be true of every row, forever:
INV-1:
order_items.quantity > 0. INV-2: An order'stotal_minorequals the sum of its items'quantity * unit_price_minor. INV-3: At most one non-deleted user per(tenant_id, lower(email)). INV-4: Every row in a tenant-owned table has a non-nulltenant_idthat matches its parent's. INV-5:orders.statusis one of PENDING, PAID, FULFILLED, REFUNDED — nothing else, ever.
Then the boundary. For every invariant, name who enforces it. The database is the only enforcement that survives a buggy deploy, a background job, a psql session, a data fix script, and a second service written by another team. Application-layer enforcement holds only while every writer is that application, on that code path, with no bugs.
| Invariant | Enforce in the DB with | If left to the app instead |
| A value is required | NOT NULL | One code path forgets; you get NULLs you must now handle forever |
| A value is bounded | CHECK (quantity > 0) | A negative quantity credits a customer money |
| A row points at a real parent | FOREIGN KEY | Orphan rows; joins silently drop them; reports disagree |
| A value is unique | UNIQUE / partial unique index | Read-then-insert races produce duplicates under concurrency |
| A value is one of a fixed set | CHECK IN (...), enum, or FK to a lookup table | A typo'd status becomes a permanent state nothing handles |
| Amounts are exact | NUMERIC/DECIMAL or integer minor units | Binary float rounding drift; totals that never reconcile |
| A row belongs to a tenant | NOT NULL tenant_id + FK + row-level security | One missing WHERE tenant_id leaks another customer's data |
Rules of thumb: anything expressible as a constraint goes in the database. Anything requiring multi-row or cross-table logic (state transitions, "at most one ACTIVE subscription per user" when ACTIVE is one of several statuses) goes in the database too when a partial unique index can express it — otherwise it belongs in an explicit transaction with a lock, and it belongs in the Risk Register.
Nullability is a domain statement, not a convenience. NULL means "unknown" or "not applicable" — it does not mean empty string, zero, or false. For every nullable column, write the sentence that says what NULL means; if you cannot write that sentence, the column should be NOT NULL. Two consequences AI code routinely misses: NULL = NULL is not true (so a unique constraint does not de-duplicate NULLs on most engines), and WHERE col <> 'x' excludes rows where col IS NULL.
Cardinality and ownership, stated once per relationship in this exact form: "One X has 0..N Y. A Y cannot exist without its X." That sentence determines the FK nullability and the ON DELETE action. One-to-many with ownership → NOT NULL FK + ON DELETE CASCADE. One-to-many without ownership → RESTRICT. Optional link → nullable FK + SET NULL and a written meaning for the null. Many-to-many → a join table with a composite primary key, plus a decision on whether the join row itself carries data (if it does, it is an entity and needs its own key).
</gate3>Gate 4 — Risk Register
<gate4>| Risk | Severity | Likelihood | Mitigation | Decided? |
Cross-tenant read via a query missing tenant_id | Critical | High | tenant_id NOT NULL everywhere + DB-enforced row filtering + a test that asserts isolation | ✅ |
| Duplicate users from a read-then-insert race | High | High | Partial unique index on (tenant_id, lower(email)) WHERE deleted_at IS NULL — an expression or partial rule cannot be a table constraint | ✅ |
ADD COLUMN NOT NULL locks the 42M-row orders table | High | High | Expand/contract: nullable → backfill in batches → constrain | ✅ |
Denormalized orders.total_minor drifts from items | High | Med | Recompute inside the same transaction; nightly reconciliation job | ⬜ pending |
| Random-UUID primary key degrades insert locality | Med | High | Time-ordered key (see key strategy table) | ⬜ pending |
| Soft-deleted parent leaves live children reachable | High | Med | Cascade the soft delete explicitly, or use hard delete + archive table | ⬜ pending |
| Index added for a query nobody runs; write cost paid forever | Med | High | Every index names the query it serves at Gate 5 | ✅ |
Anything Critical/High left undecided is a blocker — resolve before Gate 5.
</gate4>Gate 5 — Schema Design Review [USER GATE]
<gate5>Write the design and get sign-off before DDL. Must state, explicitly:
- Entity / relationship list — every relationship in the "One X has 0..N Y" form, with FK nullability and
ON DELETEaction per relationship. - Key strategy per table — surrogate vs natural, and which generator. Read
references/schema-decision-tables.md→ "Key strategy"; state the index-locality consequence you accepted. If a natural key is exposed as the primary key, state what happens when the business renames it. - The enforcement boundary table from Gate 3, complete. Every invariant has an owner.
- Nullability list — every nullable column with the sentence that says what NULL means there.
- Normalization stance — normalized by default. Every deliberate denormalization is listed with: what is duplicated, which copy is authoritative, the mechanism that keeps the copy true (same-transaction write, trigger, generated column, materialized view + refresh cadence), and how drift is detected. A denormalization with no reconciliation mechanism is a bug with a schedule.
- Tenancy model — which of the three, and the isolation mechanism. Read
references/schema-decision-tables.md→ "Tenancy". - Soft delete decision — if yes, resolve all three consequences here: unique constraints become partial (
WHERE deleted_at IS NULL), foreign keys no longer protect you (a "deleted" parent still satisfies the FK, so cascade is now your job), and every query needs the filter by default. If the requirement is legal erasure, soft delete does not satisfy it — say so. - Temporal / audit model — transaction-time (when we recorded it) and valid-time (when it was true in the world) are different columns; do not conflate them. State whether you need current-state-plus-audit-log or full row history, and the retention clock.
- Index set, derived from an enumerated query list. Write the queries first — actual
WHERE,ORDER BY, andJOINclauses the application will issue. Then each index names the query it serves. Column order in a composite index is equality columns first, then the range/sort column. Do not add an index no listed query uses; every index is paid for on every write, and on most engines the primary key is embedded in every secondary index. - Migration plan — phases, lock class per statement, and old-code compatibility. Read
references/migration-safety.md.
End with: "Approve this design or tell me what to change. I won't write DDL until you approve."
Load the engine module now (mir-database-postgres, mir-database-mongo) — it carries the engine's constraint syntax, lock behavior, and index types this gate depends on.
</gate5>Gate 6 — DDL & Migration
<gate6>Only now write DDL. Rules:
- Name every constraint explicitly. Auto-generated names differ per engine and per environment, and you cannot write a safe
DROP CONSTRAINTagainst a name you do not know. - One migration = one logical change, forward-only in ordering, with the lock class of each statement written in a comment.
- Populated tables are the default assumption. Additive and nullable first, backfill in bounded batches, constrain last. Read
references/migration-safety.mdbefore writing anyALTER. - The currently deployed application version keeps running against the new schema for the length of the rollout. Every statement is checked against that.
- Ship the index set and the query list together, in the same change.
- Seed/lookup data is a migration, not a manual step.
</gate6>Gate 7 — Production-Readiness Review
<gate7>Run migration-reviewer, security-reviewer, and reliability-reviewer. They return findings; they do not write code — you triage and fix.
Claude Code dispatch (parallel, one message, all
model:"sonnet"):Agent({description:"Migration review", subagent_type:"migration-reviewer", model:"sonnet", prompt:"<migration files> + row counts + rolling-deploy assumptions + read mir-database/references/migration-safety.md"}) Agent({description:"Security review", subagent_type:"security-reviewer", model:"sonnet", prompt:"<DDL + policies + grants> + the tenancy model + PII classification"}) Agent({description:"Reliability review",subagent_type:"reliability-reviewer",model:"sonnet", prompt:"<DDL> + the Assumption Ledger + invariants + the query list"})
Trust but verify — read the flagged DDL yourself. Then close the gate with the Constraint Coverage Matrix. Every invariant from Gate 3 appears; anything whose enforcer is "app only" needs a written reason.
| Invariant | Enforced by | Object | Test |
| INV-1 quantity > 0 | database | CHECK ck_order_items_qty_positive | insert -1 → rejected |
| INV-3 one active user per (tenant, email) | database | partial unique idx uq_users_tenant_email_active | concurrent double-insert → one fails |
| INV-4 tenant_id present and matching | database | NOT NULL + FK + row filter policy | query as tenant B → 0 rows of tenant A |
| INV-2 order total = sum(items) | app + reconciliation | service tx + nightly job | tx test + drift-detection query |
| INV-5 status in enum | database | CHECK/enum | insert 'PAYED' → rejected |
</gate7>Security
Schema decisions are security decisions. These are the specific settings and objects, not categories.
- Object-level authorization lives in the row, not the handler. Every tenant-owned table gets a
NOT NULL tenant_id. Enforce filtering in the database (Postgres:ENABLE ROW LEVEL SECURITYplusFORCE ROW LEVEL SECURITY, because a table owner bypasses its own policies otherwise). The application role must not own the tables and must not haveBYPASSRLS; superusers andBYPASSRLSroles ignore policies unconditionally. Write bothUSING(read) andWITH CHECK(write) — onALL/UPDATEpolicies Postgres reusesUSINGas the check whenWITH CHECKis absent, so state both explicitly rather than relying on that copy the first time the read rule and the write rule diverge. Views run with the definer's rights by default; a view owned by a privileged role returns every tenant's rows — create it withsecurity_invoker = true(PostgreSQL 15+). - Session-variable tenant context breaks under connection poolers. Use
SET LOCALinside the transaction, neverSET— with a transaction-pooling proxy the connection is handed to another request with your tenant still set. Handlecurrent_setting(..., true)returning NULL as a hard failure, not as "no filter". - Mass assignment is a schema problem too. Columns a client must never set —
tenant_id,role,is_admin,balance_minor,created_at,id— should beNOT NULLwith a server-side default or generated value, and the write path should use an explicit column list.INSERT INTO t SELECT * FROM json_populate_record(...)and ORM "update from request body" are the same bug. - Injection at the schema layer. Identifiers (table, column, schema names) cannot be parameterized — building DDL or dynamic SQL by string-concatenating a tenant name or a user-supplied sort column is injection. Use the engine's identifier-quoting function and an allowlist. In
SECURITY DEFINERfunctions, set an explicitsearch_path(SET search_path = pg_catalog, pg_temp) or a caller-created object shadows yours. On document stores, a JSON body deserialized straight into a query lets a client send{"$ne": null}or{"$gt": ""}where a scalar was expected — coerce types before they reach the query, and keep server-side JavaScript off (security.javascriptEnabled: false/--noscripting) so$where,$function, and$accumulatorare unavailable. - Least-privilege database roles. The application role gets
SELECT/INSERT/UPDATE/DELETEon the tables it uses and nothing else — noCREATE, no DDL, no superuser. Migrations run as a separate role. On PostgreSQL 15+,CREATEon thepublicschema is no longer granted toPUBLICby default; on older clusters revoke it yourself. Read replicas and analytics users get their own read-only role, still subject to the tenant policy. - PII in the schema, and in everything downstream of it. Classify each column at Gate 5. Statement logging, slow-query logs, ORM echo/
echo=True, and error messages that quote the failing row all copy PII out of the table into logs that have different retention and different access control. Turn off parameter logging on tables holding PII. Non-production databases restored from prod dumps are the most common PII leak in the whole stack — mask on restore. - Soft delete is not erasure. If the requirement is a legal deletion right, a
deleted_attimestamp does not satisfy it, and neither do your backups, replicas, audit tables, or the row's copies in a search index. Design the hard-erasure path (delete the row, keep a tombstone with no personal data, or encrypt per-subject and destroy the key) at Gate 5, not after the first request arrives. - Encryption and key exposure. Encryption at rest protects a stolen disk, not a compromised application role. Column-level encryption for the few fields that need it; the key does not live in the same database, and it does not live in the migration file.
- Supply chain: extensions and images are code. A database extension runs as the database OS user. Install only what you use, pin versions, and patch on the vendor's cadence — trusted extensions are installable by ordinary users, so "we only granted app-level access" does not contain them. PostgreSQL's February 2026 advisory batch (CVE-2026-2003 through CVE-2026-2006) includes a heap overflow in
pgcryptoreachable as arbitrary code execution, fixed in 18.2 / 17.8 / 16.12 / 15.16 / 14.21 — run current minors, always. MongoDB's 2026 batch (including CVE-2026-8053, an out-of-bounds write reachable by an authenticated user with write privileges on time-series collections) is fixed in 7.0.39 / 8.0.28 / 8.2.12 / 8.3.7. - Default-insecure settings that ship on. Databases bound to
0.0.0.0with no firewall; default/empty admin passwords;trustauthentication inpg_hba.conf; TLS not required by the client connection string; backups written to a world-readable bucket. Check each one before the schema ships, because the schema is worth nothing if the port is open.
Anti-Patterns
<anti_patterns>
| # | Don't | Why it bites |
| 1 | Write DDL before the Assumption Ledger is confirmed | A wrong column on a large table is a multi-week migration; wrong application code is a redeploy |
| 2 | Enforce an invariant only in application code | The first background job, data fix, or second service writes rows that violate it, and nothing notices for months |
| 3 | Make everything nullable "for flexibility" | Every consumer forever writes NULL handling for a case that never legitimately occurs, and <> comparisons silently drop rows |
| 4 | Store money in float/double | Binary rounding drift; totals that never reconcile and cannot be retroactively fixed |
| 5 | Denormalize with no reconciliation mechanism | The copy and the source diverge; both are queried; two reports disagree and nobody can say which is right |
| 6 | Use a mutable natural key (email, SKU, phone) as the primary key | The business renames it, and now every FK, every cached ID, and every external integration is wrong |
| 7 | Add soft delete without making unique constraints partial | The user cannot re-register with their own email, ever, and support has no fix |
| 8 | Add indexes speculatively "for performance" | Every index is paid on every write and in storage; unused indexes are a permanent tax with no benefit |
| 9 | Write a migration as if the table is empty | ADD COLUMN NOT NULL without a default, a plain CREATE INDEX, or a single-statement backfill takes a lock and stops writes |
| 10 | Design the schema without the query list | You get a normalized model that cannot answer the product's actual questions without four joins and a sort on an unindexed column |
| 11 | Put a status lifecycle in a free-text column | 'paid', 'Paid', 'PAYED' all exist in production and no code handles the third |
| 12 | Let the tenant column be nullable "because some rows are global" | Every query now has an OR tenant_id IS NULL that also matches other tenants' bugs; use a separate table for global rows |
</anti_patterns>
When to use a chain, not one pass
If the task spans multiple independent subject areas (billing and identity and a content catalog), do not run one giant pipeline. Run Gate 0 once to map them and name the relationships between them, then one Gate 1–7 pass per area. Tell the user: "This is three areas; I'll take them one at a time." The hardest schema bugs live exactly where two areas touch — which one owns the shared entity, and which one may write it.
Composing with your other skills
mir-backenddecides how the application uses the schema — transaction boundaries, idempotency, retries, concurrency control. This skill decides what the schema is. When both apply, run this one first: the invariants declared here become the invariants that skill defends.- Engine modules (2-tier chain): this skill is engine-independent.
mir-database-postgrescarries Postgres mechanics (lock levels perALTER TABLEsubform,CREATE INDEX CONCURRENTLY,NOT VALID→VALIDATE, partial/expression/GIN/BRIN indexes, RLS policy syntax, partitioning).mir-database-mongocarries document mechanics (embed vs reference at the collection level, document growth bounds,$jsonSchemavalidators, index and shard-key selection, the 16 MB limit). - anant-plan / GSD: when a phase changes the data model, run this skill inside that phase's planning. It produces the Assumption Ledger, the enforcement boundary, and the migration plan the phase plan should cite.
References
| File | Purpose |
references/schema-decision-tables.md | Relational vs document selection · tenancy model selection · key strategy (bigint identity vs UUIDv4 vs UUIDv7 vs ULID) with index-locality consequences. Read at Gate 0 and Gate 5. |
references/migration-safety.md | Expand/contract phases · which DDL statement takes which lock · backward compatibility with the currently deployed application version. Read at Gate 5 and Gate 6. |
Where these instructions live (edit map)
"Is this true of MySQL and MongoDB too?" → generic (edit
mir-database). "Does it only bite on this engine (lock levels,CONCURRENTLY,$jsonSchema, shard keys)?" → engine module (mir-database-postgres,mir-database-mongo). New engine? → newmir-database-<engine>module. Copy the nearest sibling's shape; never widen this pillar.
| Layer | Scope | Files | Edit it when… |
| Generic core ← this skill | engine-agnostic data modeling | skills/mir-database/SKILL.md · references/schema-decision-tables.md · references/migration-safety.md | the rule holds regardless of engine |
| Engine module | one engine's mechanics | skills/mir-database-<engine>/SKILL.md + its references/ | the rule is a mechanical footgun of that engine |
| Reviewers | Gate 7 passes | agents/migration-reviewer.md · agents/security-reviewer.md · agents/reliability-reviewer.md · agents/constraint-interrogator.md | a review focus area changes |
Provenance
Built on the mir-backend gate structure, adapted to schema and data modeling. Currency baseline verified 13 August 2026: PostgreSQL 18 current (18.4; 17.10 / 16.14 / 15.18 / 14.23 also supported, 14 EOL 12 Nov 2026), PG 18 adding uuidv7(), NOT NULL constraints in pg_constraint with a NOT VALID attribute, virtual generated columns by default, WITHOUT OVERLAPS/PERIOD temporal constraints, and NOT ENFORCED CHECK/FK; MySQL now on calendar versioning (26.7 Innovation, 9.7 and 8.4 LTS; 8.0 past EOL April 2026); MongoDB 8.2/8.3 line; RFC 9562 (May 2024) standardizing UUIDv6/7/8.
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
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.

