Hi everyone, I’m new to adonis. I’ve been searching about this question for a while but had no luck finding answers. I’m wondering if I can get any help here.
adonis migrate:refresh always returns a code 0 no matter whether it encounters an SQL error or not. I wonder if there’s a way to catch this error other than testing if there’s the word ‘Error’ in the output?
Here’s some background information:
I have a script to run a database
seeding together on my server automatically. But sometimes, if someone manually modified my database schema(e.g. deleted a table), the
migration:refresh will encounter SQL error and rollback all the operations. But since I couldn’t detect this (migration:refresh exited with code 0), the seeding part of my script will still run, which leads to duplicated seeding in my database.
I have a sample bash script to detect the SQL failure but I don’t think it is a good solution.
#/usr/bin/env bash adonis migration:refresh | grep 'Error' if [ $? -eq 1 ] then echo "Success, can start seeding" else echo "Failed, do not run seeding" fi
I’ve also set up a repo for reproducing the migration SQL error by modifying one of the migration files in the sample boilerplate. To use it, simple clone it and run the followings:
npm install adonis migration:run adonis migration:refresh
TL;DR: Any good way to detect the SQL error when using
adonis migration:refresh in a script other than “grep” the word “Error” in the command output?