Litestone guide / Changing a schema
Migrations
A migration is a plain SQL file, generated from the difference between your schema and the history so far. Files are what a deploy replays, so they are the only changes that reach production.
model Post {
id Int
title String
slug String?
}
litestone migrate dev add-posts # create the file and apply it, with a drift check
litestone migrate apply # in production: run every pending file, in order
The same steps are callable from code:
import { parseFile } from '@frontierjs/litestone'
import { create, apply, migrationStatus } from '@frontierjs/litestone/migrations'
const parsed = parseFile('./schema.lite')
const made = create(db, parsed, 'add-posts', './migrations')
await apply(db.$rawDbs.main, './migrations')
const status = migrationStatus(db.$rawDbs.main, './migrations')
if (!made.created || status.length !== 1 || status[0].state !== 'applied') throw new Error('the file should be written and applied')
What else it can do
migrate createwrites a file without applying it, andmigrate statuslists applied, pending and modifiedmigrate checkasks whether the history builds the schema, with no database neededmigrate verifyconfirms the live database matches the schemamigrate apply --backupcopies every database first, and is the only way back- Three schemas are compared: declared (
schema.lite), shadow (the files replayed) and live migrate baselinerecords files as applied without running them, for a database you already pushedmigrate accept <file>lets a database start without a file recorded- Files run in filename order, a 14-digit timestamp then a
snake_caselabel - A modified applied file blocks
apply - There is no
down; rolling back means restoring the copy--backuptook - A destructive file carries a
DESTRUCTIVEbanner you must accept before it applies - One folder per database in a multi-database schema
In depth: Migrations § File migrations, § The three schemas, § There is no down