Skip to content

Instantly share code, notes, and snippets.

@batosai
Created December 11, 2021 21:15
Show Gist options
  • Save batosai/3970e1c031879deed1a9905792ae03d3 to your computer and use it in GitHub Desktop.
Save batosai/3970e1c031879deed1a9905792ae03d3 to your computer and use it in GitHub Desktop.
Creat db reset command for Adonis 5
import execa from 'execa'
import { BaseCommand } from '@adonisjs/core/build/standalone'
import Application from '@ioc:Adonis/Core/Application'
export default class DbReset extends BaseCommand {
/**
* Command name is used to run the command
*/
public static commandName = 'db:reset'
/**
* Command description is displayed in the "help" output
*/
public static description = 'Drop databe and execute seed'
public static settings = {
/**
* Set the following value to true, if you want to load the application
* before running the command
*/
loadApp: false,
/**
* Set the following value to true, if you want this command to keep running until
* you manually decide to exit the process
*/
stayAlive: false,
}
public async run() {
this.logger.info('Remove tmp/uploads')
console.log('')
await execa('rm', ['-rf', Application.tmpPath('uploads')], {
stdio: 'inherit',
})
await execa.node('ace', ['migration:rollback'], {
stdio: 'inherit',
})
await execa.node('ace', ['migration:run'], {
stdio: 'inherit',
})
await execa.node('ace', ['db:seed'], {
stdio: 'inherit',
})
}
}
@batosai
Copy link
Author

batosai commented Dec 11, 2021

node ace generate:manifest

node ace db:reset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment