mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Clean up, find custom fields and drop those columns
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
4d30edd535
commit
f35208d58d
|
@ -2,23 +2,9 @@
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Models\Accessory;
|
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\AssetModel;
|
use App\Models\CustomField;
|
||||||
use App\Models\Category;
|
use Schema;
|
||||||
use App\Models\Company;
|
|
||||||
use App\Models\Component;
|
|
||||||
use App\Models\Consumable;
|
|
||||||
use App\Models\Department;
|
|
||||||
use App\Models\Depreciation;
|
|
||||||
use App\Models\Group;
|
|
||||||
use App\Models\Import;
|
|
||||||
use App\Models\License;
|
|
||||||
use App\Models\LicenseSeat;
|
|
||||||
use App\Models\Location;
|
|
||||||
use App\Models\Manufacturer;
|
|
||||||
use App\Models\Statuslabel;
|
|
||||||
use App\Models\Supplier;
|
|
||||||
use DB;
|
use DB;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
@ -57,32 +43,43 @@ class PaveIt extends Command
|
||||||
{
|
{
|
||||||
if ($this->confirm("\n****************************************************\nTHIS WILL DELETE ALL OF THE DATA IN YOUR DATABASE. \nThere is NO undo. This WILL destroy ALL of your data. \n****************************************************\n\nDo you wish to continue? No backsies! [y|N]")) {
|
if ($this->confirm("\n****************************************************\nTHIS WILL DELETE ALL OF THE DATA IN YOUR DATABASE. \nThere is NO undo. This WILL destroy ALL of your data. \n****************************************************\n\nDo you wish to continue? No backsies! [y|N]")) {
|
||||||
|
|
||||||
|
// List all the tables in the database so we don't have to worry about missing some as the app grows
|
||||||
$tables = DB::connection()->getDoctrineSchemaManager()->listTableNames();
|
$tables = DB::connection()->getDoctrineSchemaManager()->listTableNames();
|
||||||
|
|
||||||
$except_tables = [
|
$except_tables = [
|
||||||
'oauth_access_tokens',
|
'oauth_access_tokens',
|
||||||
'oauth_clients',
|
'oauth_clients',
|
||||||
'oauth_personal_access_clients',
|
'oauth_personal_access_clients',
|
||||||
'migrations',
|
'migrations',
|
||||||
'settings',
|
'settings',
|
||||||
'users',
|
'users',
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($tables as $table) {
|
// We only need to find out what these are so we can nuke these columns on the assets table.
|
||||||
|
$custom_fields = CustomField::get();
|
||||||
|
foreach ($custom_fields as $custom_field) {
|
||||||
|
$this->info('Drop the '.$custom_field->db_column.' column from assets as well.');
|
||||||
|
|
||||||
$this->info($table);
|
if (\Schema::hasColumn('assets', $custom_field->db_column)) {
|
||||||
|
\Schema::table('assets', function ($table) use ($custom_field) {
|
||||||
if (in_array($table, $except_tables)) {
|
$table->dropColumn($custom_field->db_column);
|
||||||
$this->info('Table '. $table. ' will be skipped');
|
});
|
||||||
} else {
|
}
|
||||||
\DB::statement('delete from '.$table);
|
}
|
||||||
}
|
|
||||||
|
foreach ($tables as $table) {
|
||||||
}
|
if (in_array($table, $except_tables)) {
|
||||||
\DB::statement('delete from users WHERE id > 2');
|
$this->info('Table '. $table. ' is skipped');
|
||||||
\DB::statement('delete from oauth_clients WHERE id > 2');
|
} else {
|
||||||
\DB::statement('delete from oauth_access_tokens WHERE id > 2');
|
\DB::statement('truncate '.$table);
|
||||||
|
$this->info('Table '. $table. ' is truncated');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Leave in the demo oauth keys so we don't have to reset them every day in the demos
|
||||||
|
//\DB::statement('delete from users WHERE id > 2');
|
||||||
|
\DB::statement('delete from oauth_clients WHERE id > 2');
|
||||||
|
\DB::statement('delete from oauth_access_tokens WHERE id > 2');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue