Skip to content

Instantly share code, notes, and snippets.

@duwaljyoti
Created May 16, 2019 09:36
Show Gist options
  • Save duwaljyoti/621d81477ba13c8bc110062a2edcf09f to your computer and use it in GitHub Desktop.
Save duwaljyoti/621d81477ba13c8bc110062a2edcf09f to your computer and use it in GitHub Desktop.
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Builder;
class DeleteUnnecessaryTablesFromDatabase extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('database', function () {
$schema = resolve(Builder::class);
DB::statement("set sql_mode=ALLOW_INVALID_DATES");
if (Schema::hasColumn('users', 'shift')) {
Schema::table('users', function (Blueprint $table) {
$table->dropForeign('users_shift_foreign');
$table->dropColumn('shift');
});
}
DB::statement("set sql_mode='NO_ZERO_IN_DATE,NO_ZERO_DATE'");
$tables = [
'granted_users',
'group_user',
'inbox_folder_labels',
'inbox_folders',
'inbox_labels',
'inbox_message_labels',
'inbox_messages',
'inventory_items',
'inventory_categories',
'inventories',
'newsfeed_posts',
'preference_user',
'preferences',
'shifts',
'shopping_list_items',
'task_priorities',
'task_categories',
'task_types',
'user_widget',
'tasks',
'widgets',
'inboxes',
'groups',
];
array_map(function ($singleTable) use ($schema) {
$schema->dropIfExists($singleTable);
}, $tables);
});
Schema::enableForeignKeyConstraints();
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('database', function (Blueprint $table) {
//
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment