Stampede is a PostgreSQL database migration utility.
- Write migrations in SQL: no special language needed.
- Atomic execution: on failure or cancel, the entire transaction is rolled back.
- Unapply migrations: optionally, if you add unapply statements to your migrations, you can tell Stampede to unapply migrations.
PGUSER environment variables, then execute
src/stampede migrate. You'll probably want to wrap this in a shell script or a Makefile.
Stampede will look for migrations in
./migrations/, in files ending with
select stampede.define_migration( id := 42, name := 'Add customer_id foreign key' apply := ' alter table orders add constraint orders_customer_fk foreign key (customer_id) references customers (id) ', unapply := 'drop constraint orders_customer_fk' );
unapply can contain any number of statements.
name are optional.
Migrations are executed in ascending order of
id. Each migration must have a unique
- Show usage:
- List migrations and status:
- Apply all unapplied migrations:
- Apply the first unapplied migration:
- Unapply the last applied migration:
The following commands are destructive, but very useful when writing and testing your migrations. Don't use these on a production database.
- Unapply all applied migrations:
- Unapply all applied migrations, then apply all migrations:
- Unapply last applied migration, then apply all migrations:
- Drop schema
- Drop schema
public, then apply all migrations:
- Clone target database, then apply all migrations:
stampede clone targetdb