Is there a way to reset my database without rolling back all migrations? Ie do "php artisan migrate:refresh" but not rolling back, just "drop table" on all existing tables, then migrate forward?
The reason for this is that rolling back migrations is not really implemented in our firm, because a) nobody needs that really, b) you can't always fully roll back because sometimes in going forward you delete data, so it's a fake idea anyway.
I haven't found an option for what I want, is there a way?
I don't want to manually delete them every time I run the test suite on the testing database, so if it could be automated (or exists somewhere as a command), that would be a lot easier :-)
I've no problem with the solution of creating my own command, I was just wondering if it was needed, or if someone knew of something that would be faster than me writing and debugging it :-)
@bashy "The reason for this is that rolling back migrations is not really implemented in our firm" We have migrations, just not the down() functionality
public function handle()
{
foreach(\DB::select('SHOW TABLES') as $table) {
$table_array = get_object_vars($table);
\Schema::drop($table_array[key($table_array)]);
}
}
I ran into a problem with using the $column variable to access the property dynamically in the londoh best answer script above? I am running php 7.3. After doing a little more searching, I found and tested this code in the db:drop command script. Worked for me using the array_map line below.
public function handle()
{
//
if (!$this->option('force')) {
if (!$this->confirm('CONFIRM DROP AL TABLES IN THE CURRENT DATABASE? [y|N]')) {
exit('Drop Tables command aborted');
}
}
$tables = array_map('reset', \DB::select('SHOW TABLES'));
$droplist = implode(',', $tables);
DB::beginTransaction();
//turn off referential integrity
DB::statement('SET FOREIGN_KEY_CHECKS = 0');
DB::statement("DROP TABLE $droplist");
//turn referential integrity back on
DB::statement('SET FOREIGN_KEY_CHECKS = 1');
DB::commit();
$this->comment(PHP_EOL . "If no errors showed up, all tables were dropped" . PHP_EOL);
}
@no4ch Careful with db:wipe - it wipes only the default DB on that connection. It's by design of course, but i need to drop all tables in all DBs on connection, writing my own command for this.