2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
2021-06-10 13:15:52 -07:00
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
class MigrateMacAddress extends Migration
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Run the migrations.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function up()
|
|
|
|
{
|
|
|
|
DB::getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
|
|
|
|
|
|
|
|
$f2 = new \App\Models\CustomFieldset(['name' => 'Asset with MAC Address']);
|
|
|
|
$f2->timestamps = false; //when this model was first created, it had no timestamps. But later on it gets them.
|
|
|
|
if (! $f2->save()) {
|
|
|
|
throw new Exception("couldn't save customfieldset");
|
|
|
|
}
|
|
|
|
$macid = DB::table('custom_fields')->insertGetId([
|
|
|
|
'name' => 'MAC Address',
|
|
|
|
'format' => \App\Models\CustomField::PREDEFINED_FORMATS['MAC'],
|
|
|
|
'element'=>'text', ]);
|
|
|
|
if (! $macid) {
|
|
|
|
throw new Exception("Can't save MAC Custom field: $macid");
|
|
|
|
}
|
|
|
|
|
|
|
|
$f2->fields()->attach($macid, ['required' => false, 'order' => 1]);
|
|
|
|
\App\Models\AssetModel::where(['show_mac_address' => true])->update(['fieldset_id'=>$f2->id]);
|
|
|
|
|
|
|
|
Schema::table('assets', function (Blueprint $table) {
|
|
|
|
$table->renameColumn('mac_address', '_snipeit_mac_address');
|
|
|
|
});
|
|
|
|
|
|
|
|
// DB::statement("ALTER TABLE assets CHANGE mac_address _snipeit_mac_address varchar(255)");
|
|
|
|
|
|
|
|
$ans = Schema::table('models', function (Blueprint $table) {
|
|
|
|
$table->renameColumn('show_mac_address', 'deprecated_mac_address');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reverse the migrations.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function down()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
$f = \App\Models\CustomFieldset::where(['name' => 'Asset with MAC Address'])->first();
|
|
|
|
$f->fields()->delete();
|
|
|
|
$f->delete();
|
|
|
|
Schema::table('models', function (Blueprint $table) {
|
|
|
|
$table->renameColumn('deprecated_mac_address', 'show_mac_address');
|
|
|
|
});
|
2023-01-10 17:08:28 -08:00
|
|
|
DB::statement('ALTER TABLE assets CHANGE _snipeit_mac_address_1 mac_address varchar(255)');
|
2021-06-10 13:15:52 -07:00
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|