Create a new database migration. Scaffold — edit the 'Your migration system' section after install to describe your project's specific workflow. Invoke via /migration.
Generate a safe, idempotent migration for the schema change the user describes.
The user should describe the schema change they want (e.g., "add column foo to bar", "create table baz", "add index on created_at").
DROP TABLE, DROP COLUMN, TRUNCATE, or DELETE without WHERE in a migration. If the user asks for a destructive change, warn them and suggest a standalone script instead.IF NOT EXISTS, ADD COLUMN IF NOT EXISTS, CREATE INDEX IF NOT EXISTS, etc.SET lock_timeout = '5s' before DDL to fail fast rather than blocking production indefinitely.Add column:
ALTER TABLE table_name ADD COLUMN IF NOT EXISTS column_name TYPE DEFAULT value;
Create table:
CREATE TABLE IF NOT EXISTS table_name (
id BIGINT PRIMARY KEY,
...
);
Create index:
CREATE INDEX IF NOT EXISTS idx_name ON table_name(column1, column2);
Complex / multi-statement — wrap in a DO $$ ... END $$ block:
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_name = 'foo' AND column_name = 'bar'
) THEN
ALTER TABLE foo ADD COLUMN bar TEXT;
END IF;
END $$;
With lock timeout:
SET lock_timeout = '5s';
ALTER TABLE foo ADD COLUMN IF NOT EXISTS bar TEXT;
# TODO: Fill in your project's migration workflow.
#
# Examples:
# - Alembic: `alembic revision -m "<description>" --autogenerate`
# - Django migrations: `python manage.py makemigrations && python manage.py migrate`
# - Raw SQL files: put the SQL in migrations/<timestamp>-<description>.sql
# - golang-migrate: `migrate create -ext sql -dir db/migrations <name>`
# - Python MIGRATIONS list: append the SQL to MIGRATIONS in your schema module
After generating the migration, show the user: