mbucc / shmig

Database migration tool written in BASH.
BSD 3-Clause "New" or "Revised" License
461 stars 50 forks source link

If DB up-to-date, exit status is 1 #24

Closed mbucc closed 7 years ago

mbucc commented 7 years ago
bbox:/service/elmarelli-api$ shmig -c db/shmig.conf up
shmig: creating migrations table: shmig_version
shmig: applying  'venue_events' (1485620534)... done
shmig: applying  'fan'  (1488727517)... done
bbox:/service/elmarelli-api$ echo $?
0
bbox:/service/elmarelli-api$ shmig -c db/shmig.conf up
bbox:/service/elmarelli-api$ echo $?
1
mbucc commented 7 years ago

Output from set -x:

+ ACTION=up
+ shift
++ type -t sqlite3_check
+ [[ function = \f\u\n\c\t\i\o\n ]]
+ sqlite3_check
+ __generic_checker /usr/bin/sqlite3 'select name from sqlite_master where type = '\''table'\'';' 'create table `shmig_version`(version int not null primary key, migrated_at timestamp not null default (datetime(current_timestamp)));'
+ local exe=/usr/bin/sqlite3
+ local 'show=select name from sqlite_master where type = '\''table'\'';'
+ local 'create=create table `shmig_version`(version int not null primary key, migrated_at timestamp not null default (datetime(current_timestamp)));'
+ [[ -x /usr/bin/sqlite3 ]]
+ grep -F -qx shmig_version
+ sqlite3_cli 'select name from sqlite_master where type = '\''table'\'';'
+ local 'args=-bail -batch  elmarelli-api.db'
+ [[ 1 -ne 0 ]]
+ /usr/bin/sqlite3 -bail -batch elmarelli-api.db
+ status=("${PIPESTATUS[@]}")
+ local status
+ [[ 141 -ne 0 ]]
+ return 1
+ exit 1

But this worked fine:

$ bash
$ sqlite3 -bail -batch  elmarelli-api.db <<< 'select name from sqlite_master where type = '\''table'\'';'
shmig_version
venue
venue_event
fan
fan_event
$

Somehow, this code:

  local status=("${PIPESTATUS[@]}")

  [[ ${status[0]} -ne 0 ]] && return 1

(ref: https://github.com/mbucc/shmig/blob/e4c58f90d5e8b54dcdb52b32bd696683f542da76/shmig#L169-L171)

produces this output

+ local status
+ [[ 141 -ne 0 ]]
+ return 1