2

Laravel has a command php artisan migrate:fresh, that "drop all tables from the database and then execute the migrate command".

While coding some new migration, sometimes we need to migrate the database from scratch.

Running refresh and reset depends on that all down methods are ok, but while developing, sometimes it's not ready to downgrade.

So, having a migration:fresh, would be good to really recreate the schema.

Tiago Gouvêa
  • 15,036
  • 4
  • 75
  • 81

2 Answers2

2

I've created a command MigrationFresh.js that will work like that for mysql and pg for now.

After installed, you must call this to recreate the database from scratch and migrate:

adonis migration:fresh

If you want to seed after migrate, run:

adonis migration:fresh --seed
Tiago Gouvêa
  • 15,036
  • 4
  • 75
  • 81
0

To do it easier now in adonis 5 we could create a new command by node ace make:command MigrationFresh

then add the code

public async run() {
    await execa.node('ace',['migration:rollback'])
    console.log('Rollback all tables')
    await execa.node('ace',['migration:run'])
    console.log('Migrated all tables')
}
Edward Chew
  • 492
  • 3
  • 12