22
33use Illuminate \Database \Migrations \Migration ;
44use Illuminate \Database \Schema \Blueprint ;
5+ use Illuminate \Support \Facades \DB ;
56use Illuminate \Support \Facades \Schema ;
67
78return new class extends Migration
1112 */
1213 public function up (): void
1314 {
14- $ groups = \App \Models \Group::join ('grouptags_groups ' , 'groups.idgroups ' , '= ' , 'grouptags_groups.group ' )
15+ // Use query builder instead of Eloquent model to avoid SoftDeletes
16+ // scope referencing a deleted_at column that doesn't exist yet.
17+ $ groups = DB ::table ('groups ' )
18+ ->join ('grouptags_groups ' , 'groups.idgroups ' , '= ' , 'grouptags_groups.group ' )
1519 ->join ('group_tags ' , 'grouptags_groups.group_tag ' , '= ' , 'group_tags.id ' )
1620 ->where ('group_tags.id ' , \App \Models \GroupTags::INACTIVE )
21+ ->select ('groups.* ' )
1722 ->get ();
1823
1924 foreach ($ groups as $ group ) {
20- $ group ->archived_at = $ group ->updated_at ;
25+ $ name = str_replace ('[INACTIVE] ' , '' , $ group ->name );
26+ $ name = str_replace ('[INACTIVE] ' , '' , $ name );
2127
22- // Remove [INACTIVE] from the group name - this is now indicated via archived_at.
23- $ group ->name = str_replace ('[INACTIVE] ' , '' , $ group ->name );
24- $ group ->name = str_replace ('[INACTIVE] ' , '' , $ group ->name );
25- $ group ->save ();
28+ DB ::table ('groups ' )
29+ ->where ('idgroups ' , $ group ->idgroups )
30+ ->update ([
31+ 'archived_at ' => $ group ->updated_at ,
32+ 'name ' => $ name ,
33+ ]);
2634 }
2735 }
2836
@@ -32,11 +40,12 @@ public function up(): void
3240 public function down (): void
3341 {
3442 // Add [INACTIVE] into all groups with archived_at.
35- $ groups = \ App \ Models \Group:: whereNotNull ('archived_at ' )->get ();
43+ $ groups = DB :: table ( ' groups ' )-> whereNotNull ('archived_at ' )->get ();
3644
3745 foreach ($ groups as $ group ) {
38- $ group ->name = '[INACTIVE] ' . $ group ->name ;
39- $ group ->save ();
46+ DB ::table ('groups ' )
47+ ->where ('idgroups ' , $ group ->idgroups )
48+ ->update (['name ' => '[INACTIVE] ' . $ group ->name ]);
4049 }
4150 }
4251};
0 commit comments