I searched related issues but it couldn't find a solution that works for me.
The migration command node ace migration:run --force is a part of our CI pipeline.
The command isn't terminating if there is 'Nothing to migrate'. Is there a simple solution for this?
Thanks!
Commands will not terminate when your app creates a long lived connection to some database or 3rd party service.
Just make sure that your hooks files are not creating any long lived connections and if they are, then you can wrap them inside a conditional to only create the connection when not executing the ace command
Thanks for the quick reply. Actually I don't have any hooks 🤷🏻♂️
Is it possible for you to share your project with me? If not,
Please share server.js file and structure of the start folder
Server.js
'use strict';
const { Ignitor } = require('@adonisjs/ignitor');
new Ignitor(require('@adonisjs/fold'))
.appRoot(__dirname)
.fireHttpServer()
.catch(console.error);
Start folder:
app.js
'use strict'
const providers = [
'@adonisjs/auth/providers/AuthProvider',
'@adonisjs/bodyparser/providers/BodyParserProvider',
'@adonisjs/cors/providers/CorsProvider',
'@adonisjs/drive/providers/DriveProvider',
'@adonisjs/framework/providers/AppProvider',
'@adonisjs/lucid/providers/LucidProvider',
'@adonisjs/mail/providers/MailProvider',
'@adonisjs/validator/providers/ValidatorProvider',
'adonis-nextjs/providers/NextProvider',
'@adonisjs/framework/providers/ViewProvider',
'adonis-scheduler/providers/SchedulerProvider'
]
const aceProviders = [
'@adonisjs/lucid/providers/MigrationsProvider',
'adonis-scheduler/providers/CommandsProvider'
]
const aliases = {
Scheduler: 'Adonis/Addons/Scheduler'
}
const commands = []
module.exports = { providers, aceProviders, aliases, commands }
routes.js
const Route = use('Route')
const Next = use('Adonis/Addons/Next')
const handler = Next.getRequestHandler()
Route.group(() => {
// Users:
Route.get('users', 'UserController.index')
Route.get('user', 'UserController.auth')
Route.get('users/:id', 'UserController.show').middleware(['findUser'])
Route.post('users', 'UserController.store')
Route.patch('users/:id', 'UserController.update').middleware(['findUser'])
Route.delete('users/:id', 'UserController.destroy').middleware(['findUser'])
//Pdf
Route.post('pdf', 'PdfController.createPDF')
}).prefix('api')
// Next.js Routes:
Route.get(
'*',
({ request, response }) =>
new Promise((resolve, reject) => {
handler(request.request, response.response, promise => {
promise.then(resolve).catch(reject)
})
})
)
What Next.getRequestHandler does?
It's for the routing within next.js: https://github.com/omarkhatibco/adonis-nextjs/blob/master/providers/NextProvider/index.js
It has no effect on the migration when I remove it.
It's weird. Ideally the command should terminate. Can you also share the @adonisjs/lucid version of your app?
It's 6.1.3.
All adonis modules are up-to-date.
Hey @pawelsas! 👋
Could you also share your migrations?
In fact, the best would be to have a repository with the minimum amount of code to reproduce the issue.
Generally the command doesn't end when there's a connection opened (Database, Redis, etc.).
@pawelsas did you tried adonis migration:refresh coz i think you made a migration for an empty migration file,i had same problem when i created lots of migrations together than i left one without setup until i moved all the migrations and i tried couple times then i knew the reason of the bug, hopfully this can help you
@annymosse I have just two migration files. So unfortunately the refresh has no effect.
@RomainLanz my migrations look like this:
'use strict';
const Schema = use('Schema');
class UserSchema extends Schema {
up() {
this.create('users', (table) => {
table.increments();
table.string('email').notNullable().unique();
table.string('token');
table.boolean('is_admin').defaultTo(false);
table.timestamps();
});
}
down() {
this.drop('users');
}
}
module.exports = UserSchema;
'use strict';
const Schema = use('Schema');
class UsersSchema extends Schema {
up() {
this.table('users', (table) => {
table.boolean('share');
});
}
down() {
this.table('users', (table) => {
// reverse alternations
});
}
}
module.exports = UsersSchema;
If still needed, I can provide a test repo for that.
Thanks!
Same problem, that's pretty annoying - I have only a single migration doing nothing. When all migrations are finished, it should force terminate the process and succeed from my opinion.
hi @pawelsas and @martinlevesque can you upload the test into a free github/gitlab repo to get a look and try it ?
Same problem with default migrations. Any temporary solution to force stop it after it runs the migrations?
This is kinda weird, since it works fine for me. Can you please share the output of node ace migration:run --help command?
I am running my command inside docker-compose.yml file like this
command: node --harmony ace migration:run --help
This is the output:
web_1 | Usage:
web_1 | migration:run [options]
web_1 |
web_1 | Options:
web_1 | -f, --force Forcefully run migrations in production
web_1 | -s, --silent Silent the migrations output
web_1 | --seed Seed the database after migration finished
web_1 | --log Log SQL queries instead of executing them
web_1 | -a, --keep-alive Do not close the database connection
web_1 |
web_1 | About:
web_1 | Run all pending migrations
Do you face the same issue, when it's not inside the docker container? Maybe test it with a sqlite connection if you don't have mysql or pg on your host machine
I'll provide the output also soon (tomorrow). In my case it's also in a docker environment, and I am using lucid-mongo with mongodb so for me it's not possible to use sqlite.
No, this happens only when using docker. I'll try with sqlite.
Okay, that helps narrow it down. Lemme try with docker and see how it goes
Works fine for me using the following Dockerfile and docker-compose.yml.
FROM node:10.15.3-alpine
RUN apk update && apk upgrade && \
apk add --update git && \
apk add --update openssh && \
apk add --update bash && \
apk add --update wget
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
version: '3.4'
services:
migrate:
build:
context: .
command: ["node", "ace", "migration:run"]
and this is how the output looks like

Can confirm that this works. Thank you.
My docker-compose service is a bit different:
migrate:
build: .
command: ["node", "ace", "migration:run"]
depends_on:
- mysql
networks:
- chat
Could you please add your solution to docs when v5 gets released?
I'm not convinced that the problem is really related to docker - I had this problem in a non docker environment, and it was working fine in containers.
What we should do (I think):
Will need the code that can help reproduce the issue
Closing since no answer from issue reporter.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.