> Source: https://vitna.ai/docs/cli/database > Raw Markdown: https://vitna.ai/docs/cli/database.md > Corpus index: https://vitna.ai/llms.txt # npm run db:generate, npm run db:migrate Generating a migration from the schema and applying it, forward only, with the grants that carry the record's rules kept narrow. ```bash npm run db:generate npm run db:migrate ``` | Command | What it does | |---|---| | `db:generate` | Generate a migration from `platform/db/schema.ts` | | `db:migrate` | Apply `drizzle/` to `DATABASE_MIGRATE_URL`, forward only | ## Forward only There are no down migrations. Rolling back a schema change means writing the next migration, and recovery from a bad one is a restore. That is a deliberate trade: a down migration is code that runs once, under pressure, having never been rehearsed against production data. ## Hand-written migrations are normal here Several migrations are written by hand rather than generated, because the constraints and grants that carry the record's rules do not come out of a schema diff. The check constraint on a workload's [delivery target](../routing/delivery.md) is one example, and the comments explaining why are part of the migration. ## Roles Migrations run as the owning role. Application roles are granted narrowly, and the shape of the narrowness is that **every `UPDATE` in this database is column-level**. There is not one grant on a whole table anywhere. Two of them are in `aperture` (the collector marking a trigger fired, the console recording a ruling), five are the collector's in `witness`, and two are the auth role's in `site`. There is no `DELETE` in `witness` or `aperture` at all. A migration that widens any of that is a decision, and the tests enumerate the grant lists so widening one is visible in a diff.