Skip to content

Commit b55dafb

Browse files
foriequal0remagpie
authored andcommitted
Check schema migration is reversable
1 parent 81135b9 commit b55dafb

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ jobs:
1919
- yarn run lint
2020
- NODE_ENV=test yarn migrate
2121
- yarn run test
22+
- name: Check schema migration is reversable
23+
before_install:
24+
- npm install -g yarn
25+
- yarn install
26+
before_script:
27+
- psql postgres -f create_user_and_db.sql
28+
script:
29+
- ./check-schema-migration-reversable.sh
2230
services:
2331
- docker
2432
- postgresql
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+
BEFORE=$(mktemp2 "${DATABASE}." ".schema.before.sql")
13+
AFTER=$(mktemp2 "${DATABASE}." ".schema.after.sql")
14+
15+
LAST_BEFORE=$(perl -e 'my @files=`ls src/migrations`; print @files[-2]')
16+
if [[ "${LAST_BEFORE}" = "" ]]; then
17+
echo "$0: Can't find a migration file before the last one, exiting..."
18+
exit 1;
19+
fi
20+
21+
yarn sequelize db:migrate --to "${LAST_BEFORE}"
22+
23+
pg_dump -s "${DATABASE}" > "${BEFORE}"
24+
25+
yarn sequelize db:migrate
26+
yarn sequelize db:migrate:undo
27+
28+
pg_dump -s "${DATABASE}" > "${AFTER}"
29+
30+
diff "${BEFORE}" "${AFTER}"

0 commit comments

Comments
 (0)