Skip to content

Commit 2d23d44

Browse files
committed
Make migrations are reflected to schema-upstream.sql
1 parent 78451fc commit 2d23d44

File tree

3 files changed

+770
-1
lines changed

3 files changed

+770
-1
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ jobs:
1919
- yarn run lint
2020
- NODE_ENV=test yarn migrate
2121
- yarn run test
22-
- name: Check schema migration is reversable
22+
- name: Check schema migration
2323
before_install:
24+
- apt install pgformatter
2425
- npm install -g yarn
2526
- yarn install
2627
before_script:
2728
- psql postgres -f create_user_and_db.sql
2829
script:
2930
- ./check-schema-migration-reversable.sh
31+
- ./check-schema-up-to-date.sh diff-only
3032
services:
3133
- docker
3234
- postgresql

check-schema-up-to-date.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
set -ex;
3+
4+
export NODE_ENV="test"
5+
DATABASE="codechain-indexer-test"
6+
7+
function mktemp2 {
8+
PREFIX="$1"
9+
POSTFIX="$2"
10+
python -c "import tempfile; print(tempfile.NamedTemporaryFile(prefix='$PREFIX', suffix='$SUFFIX', delete=False).name)"
11+
}
12+
13+
UPSTREAM=schema-upstream.sql
14+
MIGRATE=$(mktemp2 "${DATABASE}." ".schema.migrate.sql")
15+
16+
yarn sequelize db:migrate
17+
pg_dump -s -d "${DATABASE}" > "${MIGRATE}"
18+
19+
# brew install pgFormatter
20+
# apt install pgformatter
21+
pg_format --nocomment -w 120 -o "${MIGRATE}" "${MIGRATE}"
22+
23+
case $1 in
24+
diff-only)
25+
diff "${UPSTREAM}" "${MIGRATE}"
26+
;;
27+
*)
28+
mv "${MIGRATE}" "${UPSTREAM}"
29+
;;
30+
esac

0 commit comments

Comments
 (0)