Created
December 11, 2021 21:15
-
-
Save batosai/3970e1c031879deed1a9905792ae03d3 to your computer and use it in GitHub Desktop.
Creat db reset command for Adonis 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
node ace generate:manifest
node ace db:reset