Schema migrations
A migration is a recorded change to a database schema or its data. It should be reviewed and tested on the previous schema before it is applied to an approved environment. For a compatible change, add a column with a clear default or nullable transition, backfill in a controlled way when needed, then update application reads and writes. The fixture starts with a populated SQLite table, adds a non-null edition with default 1, checks the old row and reverses the change in memory. In production, dropping a column loses its data, so reversibility of a toy schema is not proof of recoverability. Drizzle Kit offers generated SQL workflows; Prisma and TypeORM also have versioned migration workflows with different commands. Review the SQL, backup/restore plan, locks, data size and compatibility with old app replicas. Avoid automatic destructive sync at startup. A schema file changing in Git does not change a running database. A migration record and actual verification of the database state are necessary. Evidence: Actual local SQLite 3.49.1 via experimental node:sqlite. Source: https://orm.drizzle.team/docs/migrations
Formal Syntax & Structure
See example for the scoped contractWorking Example
import {DatabaseSync} from 'node:sqlite';const db=new DatabaseSync(':memory:');try { db.exec("CREATE TABLE book(id INTEGER PRIMARY KEY,title TEXT); INSERT INTO book VALUES(1,'Rivers')"); db.exec('ALTER TABLE book ADD COLUMN edition INTEGER NOT NULL DEFAULT 1'); console.log(JSON.stringify(db.prepare('SELECT * FROM book').get())); db.exec('ALTER TABLE book DROP COLUMN edition'); console.log(JSON.stringify(db.prepare('SELECT * FROM book').get()));}finally{db.close();}