Skip to content
Skills Library
Programming · Building & coding

conventions-db

/conventions-db

Apply when writing or modifying database schema, queries, migrations, transactions, or tenant-scoped persistence.

Repository
stella ↗
Licence
Apache-2.0
Last repository change
13.11.2026

Assessment and security

90/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content25 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 13.11.2026, without references to retired models or APIs.

Licence

Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.

What it does and when to use it

Apply when writing or modifying database schema, queries, migrations, transactions, or tenant-scoped persistence.

Original author description

Apply when writing or modifying database schema, queries, migrations, transactions, or tenant-scoped persistence.

How it works

  1. Schema
  2. Migrations
  3. Tenant Scope and Queries
  4. Concurrency and Transactions
  5. Verification
Original SKILL.md headings · 107 lines, 693 words
SKILL.md preview
---
name: conventions-db
description: "Apply when writing or modifying database schema, queries, migrations, transactions, or tenant-scoped persistence."
---

# Database Conventions

Apply when writing or modifying database schema, queries, migrations,
transactions, or tenant-scoped persistence.

## Schema

Schema lives under `apps/api/src/db/schema/`; read the owning slice and related
foreign keys before editing. To learn whether something is stored and where,
search the generated index first: `rg <word> apps/api/src/db/schema-index` gives
one line per column with its builder, flags, `file:line` and the first sentence
of its comment, so lead a column's comment with what the column means.

- Reserve `.$type<T>()` for branded or structured types. Use a native
  PostgreSQL enum only when the value set is genuinely permanent. [review]
- Use cascade deletes for workspace-owned dependants and restrict deletes for
  shared file references. Trace the full FK graph before multi-resource
  deletion. [review]
- Add indexes for columns used in `WHERE`, `ORDER BY`, or `JOIN`; lead
  composite indexes with the tenant-scoping columns. Treat changes to large
  tables as lock-sensitive. [review]

## Migrations

### Expand-only pre-deploy phase

SQL migrations are a blocking pre-deploy phase, so keep them expand-only: add
tables or columns, add constraints as `NOT VALID`, and use only short-lock DDL.
Never put data backfills, `CREATE [UNIQUE] INDEX CONCURRENTLY`, or
`ALTER TABLE ... VALIDATE CONSTRAINT` in a migration. Governed, bounded
backfills belong to `apps/api/src/db/backfill-runtime.ts` and registered online
repairs and concurrent index builds (`ONLINE_MIGRATION_INDEXES`) in
`apps/api/src/db/online-migrations.ts`.
[check: scripts/check-migration-safety.ts, .github/workflows/ci.yml]

- `bun --filter @stll/api db:migrate` is the shipped migration path used by CI
  and deployment. `db:push` is a local declarative schema-diff tool; it does
  not replace committed migrations and must not be described as the deployment
  path. [check: .github/workflows/ci.yml]

- Schema changes remain additive across a rollout: add, deploy compatible
  reads/writes, backfill in bounded batches, switch, then remove the old shape
  in a later release. [check: scripts/check-migration-safety.ts]
- Migrations run before new API tasks finish rolling out. Old tasks must remain
  compatible with the migrated schema, and a failed rollout must have a safe
  forward-fix path. [review]
- Keep irreversible schema operations out of the same release as risky
  application changes. Destructive and access-control SQL requires a
  statement-scoped acknowledgement enforced by
  `scripts/check-migration-safety.ts`, placed in the comment block directly
  above the statement:
  `-- stella-migration-safety: reviewed <rule-id> - <why this is safe>`.
  An acknowledgement that clears nothing is an error. Every migration sets
  `lock_timeout` and `statement_timeout` first.
  [check: scripts/check-migration-safety.ts, scripts/check-migration-locks.ts]
- Keep repairable work in `online-migrations.ts`. Long backfills stay outside
  schema migrations and checkpoint durably.
  [test: apps/api/src/db/online-migrations.test.ts]
- A migration directory's name is its identity: the migrator applies every
  directory whose name the database has not recorded, in name order. Never
  rename or delete a merged migration; add a new one instead.
  [check: scripts/check-migration-order.ts]
- New timestamps sort after the newest migration on the base branch. [review]

- Validate migration history two ways: apply every committed migration to a
  fresh database, then confirm
  `bun --filter @stll/api db:push -- --explain` reports no schema drift. Do not
  repair drift by resetting a shared database.
  [check: .github/workflows/ci.yml]

## Tenant Scope and Queries

Prefer Drizzle's relational query API for ordinary relation reads, and SQL-like
syntax where it states the invariant more directly (cross-table filters,
aggregation, locking, unions, mutations).

- Workspace data uses the authorized `scopedDb` supplied by safe handlers so
  PostgreSQL RLS and query-level scope reinforce each other. Raw/root database
  access needs a demonstrated system-level reason and a deny-by-default RLS
  posture. [check: ratchet:direct-root-connection-imports]
- Do not filter unindexed JSONB in request paths. Fetch through indexed tenant
  columns, then narrow structured content with a type guard rather than a cast.
  [review]

## Concurrency and Transactions

- Keep transactions short; perform S3, network, conversion, and other external
  I/O outside them. [review]
- Close every read-decide-write race. Lock the decisive row with
  `SELECT ... FOR UPDATE`, or encode the expected state/version in the
  mutation `WHERE` clause and check the affected-row count. [review]

- Make retries converge. Stable identities, unique constraints, conditional
  transitions, and idempotency keys are stronger than read-before-insert
  checks. [review]
- Preserve lock order across call sites. When multiple resources must be
  locked, define and reuse a deterministic ordering to avoid deadlocks.
  [review]

## Verification

Test behavior that schema inference cannot prove: cross-tenant denial,
concurrent transitions, replay/idempotence, migration parity, destructive
delete ordering, and cursor stability under inserts. Prefer invariant or
integration tests over mocked query-shape tests.

Versions

RepositoryScoreLicence
This page · stella/stella90Apache-2.0
stella/stella90Apache-2.0

Database snapshot: 13.11.2026 · package version f8e992b7eb87 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100database-postgresql
    Apply PostgreSQL standards for migrations, indexing, transactions, and ORM boundaries. Use when editing entities, Prisma schema, migrations, RLS, or query-performance work for PostgreSQL.
  • 100database
    Database guidance for schema naming, safe migrations, indexing, N+1 detection, transaction scope, and soft-delete versus hard-delete tradeoffs. Use when designing schemas, writing migrations, or tuning persistence behavior.
  • 100database-testing
    Database schema validation, data integrity testing, migration testing, transaction isolation, and query performance. Use when testing data persistence, ensuring referential integrity, or validating database migrations.
  • 100qe-database-testing
    Database schema validation, data integrity testing, migration testing, transaction isolation, and query performance. Use when testing data persistence, ensuring referential integrity, or validating database migrations.
  • 90conventions-i18n
    Internationalization conventions for Stella. Apply when adding or modifying user-facing strings.
  • 100database-engineering
    End-to-end database engineering workflow for designing relational data models, writing schemas and migrations, reviewing constraints, creating indexes, optimizing queries, and hardening persistence behavior. Use when the user asks to design a database, create or change tables,…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.