Last active
January 14, 2020 12:34
-
-
Save docteurklein/27decb80abdeefe13f76a47564d0cb29 to your computer and use it in GitHub Desktop.
psql -v ON_ERROR_STOP=1 -c begin $(find . -name '*.sql' -printf ' -f %f\n' | sort -V | xargs) -c commit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table if not exists migration ( | |
id bigint primary key, | |
at timestamptz not null default clock_timestamp() | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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