Skip to content

Commit

Permalink
Make migrations are reflected to schema-upstream.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
foriequal0 committed Nov 14, 2019
1 parent 78451fc commit 2d23d44
Show file tree
Hide file tree
Showing 3 changed files with 770 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ jobs:
- yarn run lint
- NODE_ENV=test yarn migrate
- yarn run test
- name: Check schema migration is reversable
- name: Check schema migration
before_install:
- apt install pgformatter
- npm install -g yarn
- yarn install
before_script:
- psql postgres -f create_user_and_db.sql
script:
- ./check-schema-migration-reversable.sh
- ./check-schema-up-to-date.sh diff-only
services:
- docker
- postgresql
Expand Down
30 changes: 30 additions & 0 deletions check-schema-up-to-date.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -ex;

export NODE_ENV="test"
DATABASE="codechain-indexer-test"

function mktemp2 {
PREFIX="$1"
POSTFIX="$2"
python -c "import tempfile; print(tempfile.NamedTemporaryFile(prefix='$PREFIX', suffix='$SUFFIX', delete=False).name)"
}

UPSTREAM=schema-upstream.sql
MIGRATE=$(mktemp2 "${DATABASE}." ".schema.migrate.sql")

yarn sequelize db:migrate
pg_dump -s -d "${DATABASE}" > "${MIGRATE}"

# brew install pgFormatter
# apt install pgformatter
pg_format --nocomment -w 120 -o "${MIGRATE}" "${MIGRATE}"

case $1 in
diff-only)
diff "${UPSTREAM}" "${MIGRATE}"
;;
*)
mv "${MIGRATE}" "${UPSTREAM}"
;;
esac
Loading

0 comments on commit 2d23d44

Please sign in to comment.