Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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