Skip to content

A free open source IT asset/license management system

Squish migrations into one

snipe9cb7fbcad8cc
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.php
deleted file mode 100644
index 381fea7604..0000000000
--- a/database/migrations/2026_09_01_212858_create_asset_external_sources_table.php
+++ /dev/null
@@ -1,46 +0,0 @@
-<?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 indexed
- // but not unique so the same physical device can be linked
- // across multiple adapters without a schema migration (an
- // admin running Fleet AND Kandji sees the same MacBook in
- // both).
- 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();
- $table->unsignedBigInteger('created_by')->nullable()->index();
- $table->timestamps();
- $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.php
deleted file mode 100644
index 47100b03a6..0000000000
--- a/database/migrations/2026_09_02_135643_create_sync_adapter_settings_table.php
+++ /dev/null
@@ -1,26 +0,0 @@
-<?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.php
deleted file mode 100644
index 2b8d768d06..0000000000
--- a/database/migrations/2026_09_02_151539_create_sync_adapter_instances_table.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?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',
- 'ninjaone' => 'NinjaOne',
- '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');
- }
-};
diff --git a/database/migrations/2026_09_09_120000_seed_kaseya_vsa10_adapter_instance.php b/database/migrations/2026_09_09_120000_seed_kaseya_vsa10_adapter_instance.php
deleted file mode 100644
index 2c8ab2849d..0000000000
--- a/database/migrations/2026_09_09_120000_seed_kaseya_vsa10_adapter_instance.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-
-use Illuminate\Database\Migrations\Migration;
-use Illuminate\Support\Facades\DB;
-
-return new class extends Migration
-{
- public function up(): void
- {
- if (DB::table('sync_adapter_instances')->where('slug', 'kaseya_vsa10')->exists()) {
- return;
- }
-
- $now = now();
- DB::table('sync_adapter_instances')->insert([
- 'slug' => 'kaseya_vsa10',
- 'adapter_type' => 'kaseya_vsa10',
- 'label' => 'Kaseya VSA 10',
- 'active' => false,
- 'built_in' => true,
- 'created_at' => $now,
- 'updated_at' => $now,
- ]);
- }
-
- public function down(): void
- {
- DB::table('sync_adapter_instances')
- ->where('slug', 'kaseya_vsa10')
- ->where('built_in', true)
- ->delete();
- }
-};
diff --git a/database/migrations/2026_09_09_130000_seed_apple_business_manager_adapter_instance.php b/database/migrations/2026_09_09_130000_seed_apple_business_manager_adapter_instance.php
deleted file mode 100644
index 7d566ce608..0000000000
--- a/database/migrations/2026_09_09_130000_seed_apple_business_manager_adapter_instance.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-
-use Illuminate\Database\Migrations\Migration;
-use Illuminate\Support\Facades\DB;
-
-return new class extends Migration
-{
- public function up(): void
- {
- if (DB::table('sync_adapter_instances')->where('slug', 'abm')->exists()) {
- return;
- }
-
- $now = now();
- DB::table('sync_adapter_instances')->insert([
- 'slug' => 'abm',
- 'adapter_type' => 'abm',
- 'label' => 'Apple Business Manager',
- 'active' => false,
- 'built_in' => true,
- 'created_at' => $now,
- 'updated_at' => $now,
- ]);
- }
-
- public function down(): void
- {
- DB::table('sync_adapter_instances')
- ->where('slug', 'abm')
- ->where('built_in', true)
- ->delete();
- }
-};
diff --git a/database/migrations/2026_09_11_120000_rename_apple_business_manager_adapter_slug_to_abm.php b/database/migrations/2026_09_11_120000_rename_apple_business_manager_adapter_slug_to_abm.php
deleted file mode 100644
index 44c7b8d0b0..0000000000
--- a/database/migrations/2026_09_11_120000_rename_apple_business_manager_adapter_slug_to_abm.php
+++ /dev/null
@@ -1,29 +0,0 @@
-<?php
-
-use Illuminate\Database\Migrations\Migration;
-use Illuminate\Support\Facades\DB;
-
-return new class extends Migration
-{
- public function up(): void
- {
- DB::table('sync_adapter_instances')
- ->where('slug', 'apple_business_manager')
- ->update([
- 'slug' => 'abm',
- 'adapter_type' => 'abm',
- 'updated_at' => now(),
- ]);
- }
-
- public function down(): void
- {
- DB::table('sync_adapter_instances')
- ->where('slug', 'abm')
- ->update([
- 'slug' => 'apple_business_manager',
- 'adapter_type' => 'apple_business_manager',
- 'updated_at' => now(),
- ]);
- }
-};
diff --git a/database/migrations/2026_09_16_120000_add_source_asset_id_unique_to_asset_external_sources.php b/database/migrations/2026_09_16_120000_add_source_asset_id_unique_to_asset_external_sources.php
deleted file mode 100644
index f9b56b47cc..0000000000
--- a/database/migrations/2026_09_16_120000_add_source_asset_id_unique_to_asset_external_sources.php
+++ /dev/null
@@ -1,22 +0,0 @@
-<?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::table('asset_external_sources', function (Blueprint $table) {
- $table->unique(['source', 'asset_id'], 'aes_source_asset_id_unique');
- });
- }
-
- public function down(): void
- {
- Schema::table('asset_external_sources', function (Blueprint $table) {
- $table->dropUnique('aes_source_asset_id_unique');
- });
- }
-};
diff --git a/database/migrations/2026_09_16_163131_remove_built_in_from_sync_adapter_instances.php b/database/migrations/2026_09_16_163131_remove_built_in_from_sync_adapter_instances.php
deleted file mode 100644
index eda04a9ea6..0000000000
--- a/database/migrations/2026_09_16_163131_remove_built_in_from_sync_adapter_instances.php
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-
-use Illuminate\Database\Migrations\Migration;
-use Illuminate\Database\Schema\Blueprint;
-use Illuminate\Support\Facades\DB;
-use Illuminate\Support\Facades\Schema;
-
-/**
- * Adapter TYPE discovery moved to the glob-based
- * SyncAdapter::allTypes() at runtime, so we no longer pre-populate a
- * sync_adapter_instances row per shipped adapter. This migration clears
- * out the untouched seed rows left by the earlier seed migrations and
- * drops the now-vestigial built_in column. Configured rows (any row
- * with associated sync_adapter_settings) are preserved and become
- * normal admin-owned instances.
- */
-return new class extends Migration
-{
- public function up(): void
- {
- DB::table('sync_adapter_instances')
- ->where('built_in', true)
- ->whereNotExists(function ($query) {
- $query->select(DB::raw(1))
- ->from('sync_adapter_settings')
- ->whereColumn('sync_adapter_settings.sync_adapter_instance_id', 'sync_adapter_instances.id');
- })
- ->delete();
-
- Schema::table('sync_adapter_instances', function (Blueprint $table) {
- $table->dropColumn('built_in');
- });
- }
-
- public function down(): void
- {
- Schema::table('sync_adapter_instances', function (Blueprint $table) {
- $table->boolean('built_in')->default(false)->after('active');
- });
- }
-};
diff --git a/database/migrations/2026_09_16_183827_create_sync_adapter_tables.php b/database/migrations/2026_09_16_183827_create_sync_adapter_tables.php
new file mode 100644
index 0000000000..8ef878a9c8
--- /dev/null
+++ b/database/migrations/2026_09_16_183827_create_sync_adapter_tables.php
@@ -0,0 +1,90 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+/**
+ * Create every table the sync-adapter feature needs, in one migration.
+ * Historically this landed as eight incremental migrations that
+ * seeded per-adapter rows and toggled a built_in column. Adapter
+ * TYPE discovery moved to runtime via SyncAdapter::allTypes(),
+ * so per-adapter row seeding is gone and the built_in column
+ * with it. Consolidating pre-release keeps the ship-out shape flat.
+ */
+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.
+ //
+ // Two unique indexes.
+ // - (source, external_id) so one row per vendor-device pair.
+ // - (source, asset_id) so one asset can only be linked to
+ // each vendor once (prevents duplicate side-table rows
+ // when a device gets re-enrolled with a new external id).
+ 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();
+ $table->unsignedBigInteger('created_by')->nullable()->index();
+ $table->timestamps();
+ $table->unique(['source', 'external_id']);
+ $table->unique(['source', 'asset_id'], 'aes_source_asset_id_unique');
+ });
+
+ // Per-instance key/value config for each adapter instance
+ // (URL, encrypted credentials, mapping.{field} targets,
+ // direction.{field}, group_mapping.{group_id}, cached
+ // vendor metadata, etc). Every config lookup + write goes
+ // through SyncAdapterConfig::get/put/forget, which enforces
+ // the (instance_id, config_key) uniqueness.
+ 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']);
+ });
+
+ // One row per configured adapter instance. Adapter TYPES live
+ // in the codebase and are discovered at runtime, so nothing
+ // gets pre-seeded here. Admins add instances via the settings
+ // page. The slug is auto-generated from the label on create
+ // and is immutable after (asset_external_sources.source
+ // references it, reassigning slugs would orphan assets).
+ 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->timestamp('last_synced_at')->nullable()->index();
+ $table->text('last_sync_result')->nullable();
+ $table->unsignedBigInteger('created_by')->nullable()->index();
+ $table->timestamps();
+ });
+ }
+
+ public function down(): void
+ {
+ Schema::dropIfExists('sync_adapter_instances');
+ Schema::dropIfExists('sync_adapter_settings');
+ Schema::dropIfExists('asset_external_sources');
+ }
+};