PostgreSQL migrations
Use the schema from the deployed revision, including the files it imports. From experiments/06-native-schema, generate a SQL diff against your current schema.
bun run migration:diff /path/to/deployed/kinetic/schema.kinetic > migration.sqlReview the diff, especially renames that appear as drops and adds. Put the reviewed SQL in kinetic/migrations/ with the next ordered filename and keep it with the release.
Apply a release
Section titled “Apply a release”Set KINETIC_DATABASE_URL to the target database. Run this from the same directory before starting the new application.
bun run migrateThe runner takes a PostgreSQL lock, checks the recorded checksums, and applies pending migrations in one transaction. Leave transaction boundaries to the runner and preserve applied SQL files.
Use bun run migrate --bootstrap once for a fresh database with an empty public schema. It applies the generated schema and records the migrations as covered by the baseline. Verify separately that any effects from hand-written SQL are present in that baseline.
For an existing installation with no Kinetic migration history, verify the migrations it already contains before using bun run migrate --baseline-through <migration.sql> to record the corresponding prefix without replaying it.
Singleton tables
Section titled “Singleton tables”Adding @@kinetic.singleton creates a unique index that permits at most one row. The migration fails if the table already has duplicates. Resolve those rows before applying the migration. Removing the directive drops the index and keeps the existing row.