A free open source IT asset/license management system
Added migrations
snipeb2fe614bcb30
diff --git a/database/migrations/2026_09_01_212858_create_asset_external_sources_table.php b/database/migrations/2026_09_01_212858_create_asset_external_sources_table.phpnew file mode 100644index 0000000000..c92ead51d2--- /dev/null+++ b/database/migrations/2026_09_01_212858_create_asset_external_sources_table.php@@ -0,0 +1,57 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration+{+ public function up(): void+ {+ // Combined identity + inventory table for sync-adapter data+ // about an asset. Carries which adapter created it+ // (source + external_id) plus the last-known network / OS+ // inventory (primary_mac / primary_ip / os / os_version /+ // last_seen). Kept separate from the assets table so+ // vendor-populated data can grow without widening the row+ // and eating custom-field headroom.+ //+ // Cardinality: one row per (source, external_id) pair+ // enforced by the unique index below. asset_id is only+ // indexed, not unique, so future adoption / multi-source+ // features (linking one physical device across two adapters,+ // migrating an existing Snipe-IT asset into a new MDM+ // without losing history) can add rows without a schema+ // migration. The Asset::externalSource() relation stays+ // hasOne while the sync path only writes one row per asset.+ // It flips to hasMany when we add the adoption UI.+ Schema::create('asset_external_sources', function (Blueprint $table) {+ $table->id();+ $table->unsignedBigInteger('company_id')->nullable()->index();+ $table->unsignedBigInteger('asset_id')->index();+ $table->string('source', 191);+ $table->string('external_id', 191);+ $table->string('primary_mac', 191)->nullable()->index();+ $table->string('primary_ip', 191)->nullable()->index();+ $table->string('os', 191)->nullable();+ $table->string('os_version', 191)->nullable();+ $table->timestamp('last_seen')->nullable()->index();+ // Who created this source row. NULL for CLI-triggered+ // sync runs (no auth context) and for background /+ // scheduled runs. Populated with auth()->id() when the+ // sync fires from the interactive Sync Now button.+ $table->unsignedBigInteger('created_by')->nullable()->index();+ $table->timestamps();+ // Prevents duplicate sync rows from re-syncing the same+ // vendor-side device. The (source, external_id) pair is+ // the identity key SyncHostFromAdapter uses to decide+ // upsert vs create.+ $table->unique(['source', 'external_id']);+ });+ }++ public function down(): void+ {+ Schema::dropIfExists('asset_external_sources');+ }+};diff --git a/database/migrations/2026_09_02_135643_create_sync_adapter_settings_table.php b/database/migrations/2026_09_02_135643_create_sync_adapter_settings_table.phpnew file mode 100644index 0000000000..47100b03a6--- /dev/null+++ b/database/migrations/2026_09_02_135643_create_sync_adapter_settings_table.php@@ -0,0 +1,26 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration+{+ public function up(): void+ {+ Schema::create('sync_adapter_settings', function (Blueprint $table) {+ $table->id();+ $table->unsignedBigInteger('sync_adapter_instance_id')->index();+ $table->string('config_key', 191);+ $table->text('value')->nullable();+ $table->timestamps();++ $table->unique(['sync_adapter_instance_id', 'config_key']);+ });+ }++ public function down(): void+ {+ Schema::dropIfExists('sync_adapter_settings');+ }+};diff --git a/database/migrations/2026_09_02_151539_create_sync_adapter_instances_table.php b/database/migrations/2026_09_02_151539_create_sync_adapter_instances_table.phpnew file mode 100644index 0000000000..955151a522--- /dev/null+++ b/database/migrations/2026_09_02_151539_create_sync_adapter_instances_table.php@@ -0,0 +1,57 @@+<?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('sync_adapter_instances', function (Blueprint $table) {+ $table->id();+ $table->unsignedBigInteger('company_id')->nullable()->index();+ $table->string('slug', 191)->unique();+ $table->string('adapter_type', 191)->index();+ $table->string('label', 191);+ $table->boolean('active')->default(true);+ $table->boolean('built_in')->default(false);+ $table->timestamp('last_synced_at')->nullable()->index();+ $table->text('last_sync_result')->nullable();+ $table->unsignedBigInteger('created_by')->nullable()->index();+ $table->timestamps();+ });++ // Seed the well-known adapter.+ $now = now();+ DB::table('sync_adapter_instances')->insert(collect([+ 'fleet' => 'Fleet',+ 'addigy' => 'Addigy',+ 'intune' => 'Microsoft Intune',+ 'jamf' => 'Jamf Pro',+ 'jamf_school' => 'Jamf School',+ 'kandji' => 'Kandji',+ 'unifi' => 'UniFi',+ 'meraki_sm' => 'Meraki Systems Manager',+ 'mosyle' => 'Mosyle',+ 'osctrl' => 'osctrl',+ 'workspace_one' => 'Omnissa Workspace ONE',+ 'zentral' => 'Zentral',+ 'jumpcloud' => 'JumpCloud',+ ])->map(fn ($label, $type) => [+ 'slug' => $type,+ 'adapter_type' => $type,+ 'label' => $label,+ 'active' => false,+ 'built_in' => true,+ 'created_at' => $now,+ 'updated_at' => $now,+ ])->values()->all());+ }++ public function down(): void+ {+ Schema::dropIfExists('sync_adapter_instances');+ }+};