From 5efd1054f42ddc8b5dbe01883df92ad2bed36883 Mon Sep 17 00:00:00 2001 From: Darko Gjorgjijoski Date: Tue, 7 Apr 2026 02:12:38 +0200 Subject: [PATCH] Add v3.0 upgrade migration Migrates media disk references from the old temp_{driver} naming to the new disk_{id} scheme. System local disks map to 'local', remote disks map to 'disk_{id}'. Structured as the single v3.0 upgrade migration for future additions. --- .../2026_04_07_001104_upgrade_to_v3.php | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 database/migrations/2026_04_07_001104_upgrade_to_v3.php diff --git a/database/migrations/2026_04_07_001104_upgrade_to_v3.php b/database/migrations/2026_04_07_001104_upgrade_to_v3.php new file mode 100644 index 00000000..0915878c --- /dev/null +++ b/database/migrations/2026_04_07_001104_upgrade_to_v3.php @@ -0,0 +1,63 @@ +migrateMediaDiskReferences(); + } + + /** + * v3.0 replaced the temp_{driver} disk naming with disk_{id}. + * Update existing media records so they reference valid disk names. + */ + private function migrateMediaDiskReferences(): void + { + // temp_local was the dynamic name for the default local FileDisk. + // In v3.0, system local disks use the 'local' config entry directly. + DB::table('media') + ->where('disk', 'temp_local') + ->update(['disk' => 'local']); + + // temp_s3, temp_dropbox, etc. for remote disks — map to disk_{id} + $remotePrefixes = ['temp_s3', 'temp_dropbox', 'temp_doSpaces', 'temp_s3compat']; + + foreach ($remotePrefixes as $oldDiskName) { + $driver = str_replace('temp_', '', $oldDiskName); + + $fileDisk = DB::table('file_disks') + ->where('driver', $driver) + ->first(); + + if ($fileDisk) { + DB::table('media') + ->where('disk', $oldDiskName) + ->update(['disk' => 'disk_'.$fileDisk->id]); + } + } + } + + public function down(): void + { + // Reverse: map disk_{id} back to temp_{driver} + $fileDiskIds = DB::table('file_disks') + ->whereNotIn('type', ['SYSTEM']) + ->get(); + + foreach ($fileDiskIds as $disk) { + DB::table('media') + ->where('disk', 'disk_'.$disk->id) + ->update(['disk' => 'temp_'.$disk->driver]); + } + + DB::table('media') + ->where('disk', 'local') + ->update(['disk' => 'temp_local']); + } +};