mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 07:34:06 -08:00
934afa036f
Shift automatically applies the Laravel coding style - which uses the PSR-2 coding style as a base with some minor additions. You may customize the adopted coding style by adding your own [PHP CS Fixer][1] `.php_cs` config file to your project root. Feel free to use [Shift's Laravel ruleset][2] to help you get started. [1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer [2]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200
61 lines
2 KiB
PHP
61 lines
2 KiB
PHP
<?php
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
|
|
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');
|
|
});
|
|
DB::statement('ALTER TABLE assets CHANGE _snipeit_mac_address mac_address varchar(255)');
|
|
}
|
|
}
|