Skip to content

A free open source IT asset/license management system

Add migration

Daniel Meltzer165487ac929b
diff --git a/database/migrations/2016_12_27_212631_make_asset_assigned_to_polymorphic.php b/database/migrations/2016_12_27_212631_make_asset_assigned_to_polymorphic.php
new file mode 100644
index 0000000000..a00692c7b1
--- /dev/null
+++ b/database/migrations/2016_12_27_212631_make_asset_assigned_to_polymorphic.php
@@ -0,0 +1,39 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+use App\Models\Asset;
+use App\Models\User;
+
+class MakeAssetAssignedToPolymorphic extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table('assets', function (Blueprint $table) {
+ //
+ $table->string('assigned_type')->nullable();
+ });
+
+ // Prior to this migration, asset's could only be assigned to users.
+ Asset::whereNotNull('assigned_to')->orWhere('assigned_to', '')->update(['assigned_type' => User::class]);
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('assets', function (Blueprint $table) {
+ //
+ $table->dropColumn('assigned_type');
+ });
+ }
+}