Skip to content

Instantly share code, notes, and snippets.

@docteurklein

docteurklein/0_setup.sql

Last active Jan 14, 2020
Embed
What would you like to do?
psql -v ON_ERROR_STOP=1 -c begin $(find . -name '*.sql' -printf ' -f %f\n' | sort -V | xargs) -c commit
create table if not exists migration (
id bigint primary key,
at timestamptz not null default clock_timestamp()
);
select not exists(select true from migration where id = 1) as should_v1 \gset
\if :should_v1
create table test (id int);
insert into migration (id) values (1);
\endif
select not exists(select true from migration where id = 2) as should_v2 \gset
\if :should_v2
alter table test add col2 text;
insert into migration (id) values (2);
\endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.