we are using an entryfile.sh that runs our migrations before the application starts as stated here: How to run commands before the application starts | Qovery However, we are now running into ActiveRecord::ConcurrentMigrationError as the script in entrypoint is called from all running (or starting) web processes.
When setting up Qovery at Tint, we faced the exact same problem.
We are using knex to run database migrations when starting the instance.
Our problem was that the first instance that is starting is locking the migration table, and the other instances are trying to do the same, but were just failing because of the lock.
Usually, a well-suited ORM or a web framework would handle that for us, but we have a pretty manual setup.
So we choose to wrap the migration script with a loop that just waits for the lock to be release before starting the app.
# 1. Run the migration script, which is supposed to either run the migrations or wait for the lock to be released
# 2. Run the app
CMD ./scripts/migrate.sh && node index.js
while [[ $attempts -le $MAX_RETRY_ATTEMPTS ]]; do
if [[ $attempts -gt 0 ]]; then
echo "Failed to run DB migrations. Retrying ... ($attempts)"
yarn migrate:latest # This line is running the migrations, and fails if the migration table is locked
if [[ $exit_code == 0 ]]; then
# Notify engineers that something did go wrong (we're using Slack webhooks)
We had no issue with that script for a few months now.
Let me know if I can help you further!