Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions database/migrations/2024_09_16_093650_inactive_groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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
Expand All @@ -11,18 +12,25 @@
*/
public function up(): void
{
$groups = \App\Models\Group::join('grouptags_groups', 'groups.idgroups', '=', 'grouptags_groups.group')
// Use query builder instead of Eloquent model to avoid SoftDeletes
// scope referencing a deleted_at column that doesn't exist yet.
$groups = DB::table('groups')
->join('grouptags_groups', 'groups.idgroups', '=', 'grouptags_groups.group')
->join('group_tags', 'grouptags_groups.group_tag', '=', 'group_tags.id')
->where('group_tags.id', \App\Models\GroupTags::INACTIVE)
->select('groups.*')
->get();

foreach ($groups as $group) {
$group->archived_at = $group->updated_at;
$name = str_replace('[INACTIVE] ', '', $group->name);
$name = str_replace('[INACTIVE]', '', $name);

// Remove [INACTIVE] from the group name - this is now indicated via archived_at.
$group->name = str_replace('[INACTIVE] ', '', $group->name);
$group->name = str_replace('[INACTIVE]', '', $group->name);
$group->save();
DB::table('groups')
->where('idgroups', $group->idgroups)
->update([
'archived_at' => $group->updated_at,
'name' => $name,
]);
}
}

Expand All @@ -32,11 +40,12 @@ public function up(): void
public function down(): void
{
// Add [INACTIVE] into all groups with archived_at.
$groups = \App\Models\Group::whereNotNull('archived_at')->get();
$groups = DB::table('groups')->whereNotNull('archived_at')->get();

foreach ($groups as $group) {
$group->name = '[INACTIVE] ' . $group->name;
$group->save();
DB::table('groups')
->where('idgroups', $group->idgroups)
->update(['name' => '[INACTIVE] ' . $group->name]);
}
}
};