I am processing .sql files with bash automatically in my CI solution in a for loop, to catch faulty migrations before deployment.
MIGS is a bash array containing in time order the .sql in a folder
for sqlfile in ${MIGS[@]};
do
psql myproject_unit < $sqlfile
done
Is there a way to terminate processing of the .sql if a condition is met?
So what I do now:
file sql20180515n.sql
CREATE TABLE IF NOT EXISTS something (
...
/* imagine here other 400 lines of SQL */
What I am looking for (please replace the first two lines to the correct syntax if applicable or tell me if it is not possible)
IF TABLE_EXISTS(something) /* we already ran, no need */
EXIT;
CREATE TABLE something (
...
/* imagine here other 400 lines of SQL */
So to confirm: if condition is met (table/col/trigger/index already exists), I would like to jump to the next .sql source in my for loop, so do not quit the whole shell, just the psql processor as defined in the .sql file when to terminate it.