Skip to content

A free open source IT asset/license management system

Migration to add supplier ID to components and consumables

snipe45142c688897
diff --git a/database/migrations/2023_04_12_135822_add_supplier_to_components.php b/database/migrations/2023_04_12_135822_add_supplier_to_components.php
new file mode 100644
index 0000000000..447c7850a9
--- /dev/null
+++ b/database/migrations/2023_04_12_135822_add_supplier_to_components.php
@@ -0,0 +1,48 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddSupplierToComponents extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table('components', function (Blueprint $table) {
+ if (!Schema::hasColumn('components', 'supplier_id')) {
+ $table->integer('supplier_id')->after('user_id')->nullable()->default(null);
+ }
+ });
+
+ Schema::table('consumables', function (Blueprint $table) {
+ if (!Schema::hasColumn('consumables', 'supplier_id')) {
+ $table->integer('supplier_id')->after('user_id')->nullable()->default(null);
+ }
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('components', function (Blueprint $table) {
+ if (Schema::hasColumn('components', 'supplier_id')) {
+ $table->dropColumn('supplier_id');
+ }
+ });
+
+ Schema::table('consumables', function (Blueprint $table) {
+ if (Schema::hasColumn('consumables', 'supplier_id')) {
+ $table->dropColumn('supplier_id');
+ }
+ });
+ }
+}