Skip to content

A free open source IT asset/license management system

Scary scary migration

snipea159c3b84e96
diff --git a/database/migrations/2026_05_19_000001_create_company_user_table.php b/database/migrations/2026_05_19_000001_create_company_user_table.php
new file mode 100644
index 0000000000..6c07afc876
--- /dev/null
+++ b/database/migrations/2026_05_19_000001_create_company_user_table.php
@@ -0,0 +1,38 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ public function up(): void
+ {
+ Schema::create('company_user', function (Blueprint $table) {
+ $table->id();
+ $table->unsignedInteger('company_id')->index();
+ $table->unsignedInteger('user_id')->index();
+ $table->timestamps();
+ $table->unique(['company_id', 'user_id']);
+ });
+
+ // Seed pivot from existing users.company_id values
+ DB::table('users')
+ ->whereNotNull('company_id')
+ ->orderBy('id')
+ ->each(function ($user) {
+ DB::table('company_user')->insertOrIgnore([
+ 'company_id' => $user->company_id,
+ 'user_id' => $user->id,
+ 'created_at' => now(),
+ 'updated_at' => now(),
+ ]);
+ });
+ }
+
+ public function down(): void
+ {
+ Schema::dropIfExists('company_user');
+ }
+};