Skip to content

Commit 95474f3

Browse files
authored
Fix storage prefix migration for database compatibility (#93)
1 parent 530884b commit 95474f3

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

‎database/migrations/2026_08_01_175119_remove_storage_prefix_from_resource_file_paths.php‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,34 @@ public function up(): void
99
{
1010
DB::table('resources')
1111
->whereNotNull('file_path')
12-
->update([
13-
'file_path' => DB::raw("LTRIM(REPLACE(file_path, '/storage/', ''), '/')"),
14-
]);
12+
->orderBy('id')
13+
->chunkById(100, function ($resources) {
14+
foreach ($resources as $resource) {
15+
DB::table('resources')
16+
->where('id', $resource->id)
17+
->update([
18+
'file_path' => ltrim(
19+
str_replace('/storage/', '', $resource->file_path),
20+
'/'
21+
),
22+
]);
23+
}
24+
});
1525
}
1626

1727
public function down(): void
1828
{
1929
DB::table('resources')
2030
->whereNotNull('file_path')
21-
->update([
22-
'file_path' => DB::raw("'storage/' || file_path"),
23-
]);
31+
->orderBy('id')
32+
->chunkById(100, function ($resources) {
33+
foreach ($resources as $resource) {
34+
DB::table('resources')
35+
->where('id', $resource->id)
36+
->update([
37+
'file_path' => 'storage/' . ltrim($resource->file_path, '/'),
38+
]);
39+
}
40+
});
2441
}
2542
};

0 commit comments

Comments
 (0)