Skip to content

Instantly share code, notes, and snippets.

@Fogggy
Last active January 22, 2019 17:20
Show Gist options
  • Save Fogggy/bb49f01870adfdd8df911c0caa77fda8 to your computer and use it in GitHub Desktop.
Save Fogggy/bb49f01870adfdd8df911c0caa77fda8 to your computer and use it in GitHub Desktop.
Artisan::command('drop-tables', function () {
if ($this->confirm("Dude, are you sure that you really want to drop all the tables in the database? All your data will be lost!") &&
$this->ask("Type 'drop tables' to confirm operation") == 'drop tables') {
Schema::dropAllTables();
/**
* Drop Functions
*/
$functions = DB::select(sprintf("SHOW FUNCTION STATUS WHERE Db = '%s';", DB::getDatabaseName()));
foreach ($functions as $function) {
DB::statement(sprintf("DROP FUNCTION %s", $function->name));
}
$tables = DB::connection()->getDoctrineSchemaManager()->listTableNames();
$functions = DB::select(sprintf("SHOW FUNCTION STATUS WHERE Db = '%s';", DB::getDatabaseName()));
$this->info('Done!');
$this->line(str_repeat('-', 30));
$this->comment('Database: '.DB::getDatabaseName());
$this->comment('Count Tables: '.count($tables));
$this->comment('Count Functions: '.count($functions));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment