Support oft parent groups
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
<?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 {
|
||||
/**
|
||||
* Übergeordnete Gruppen (Parent Groups, im UI z. B. „Bund"): jeder Mandant (Local Group) gehört zu genau einer.
|
||||
* Eine Veranstaltung fragt bei der Anmeldung entweder nach der Local Group oder nach der Parent Group.
|
||||
*
|
||||
* Die Vorbelegung steht hier und nicht im Seeder: der Fremdschlüssel am Tenant ist Pflicht, bestehende
|
||||
* Installationen brauchen die Fallback-Gruppe also schon beim Migrieren.
|
||||
*
|
||||
* Dazu die globalen Einstellungen mit den Bezeichnungen der beiden Ebenen -- aus demselben Grund vorbelegt.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('parent_groups', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
// Die Gruppe für Mandanten ohne Zuordnung; sie ist umbenennbar, aber nie löschbar.
|
||||
$table->boolean('is_fallback')->default(false);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
$now = now();
|
||||
$fallbackId = DB::table('parent_groups')->insertGetId([
|
||||
'name' => 'Ohne Zuordnung',
|
||||
'is_fallback' => true,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
|
||||
foreach (['BdP', 'DPV', 'DPSG', 'VCP'] as $name) {
|
||||
DB::table('parent_groups')->insert([
|
||||
'name' => $name,
|
||||
'is_fallback' => false,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
}
|
||||
|
||||
Schema::table('tenants', function (Blueprint $table) {
|
||||
$table->foreignId('parent_group_id')->nullable()->constrained('parent_groups')->restrictOnDelete();
|
||||
});
|
||||
|
||||
DB::table('tenants')->update(['parent_group_id' => $fallbackId]);
|
||||
|
||||
Schema::table('tenants', function (Blueprint $table) {
|
||||
$table->foreignId('parent_group_id')->nullable(false)->change();
|
||||
});
|
||||
|
||||
Schema::table('events', function (Blueprint $table) {
|
||||
$table->string('participant_group_type')->default('local_group');
|
||||
});
|
||||
|
||||
Schema::table('event_participants', function (Blueprint $table) {
|
||||
$table->foreignId('parent_group_id')->nullable()->constrained('parent_groups')->restrictOnDelete();
|
||||
});
|
||||
|
||||
Schema::create('global_settings', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->text('value');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
foreach ([
|
||||
'local_group_label' => 'Stamm',
|
||||
'local_group_label_plural' => 'Stämme',
|
||||
'parent_group_label' => 'Bund',
|
||||
'parent_group_label_plural' => 'Bünde',
|
||||
] as $key => $value) {
|
||||
DB::table('global_settings')->insert([
|
||||
'key' => $key,
|
||||
'value' => $value,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('global_settings');
|
||||
|
||||
Schema::table('event_participants', function (Blueprint $table) {
|
||||
$table->dropConstrainedForeignId('parent_group_id');
|
||||
});
|
||||
|
||||
Schema::table('events', function (Blueprint $table) {
|
||||
$table->dropColumn('participant_group_type');
|
||||
});
|
||||
|
||||
Schema::table('tenants', function (Blueprint $table) {
|
||||
$table->dropConstrainedForeignId('parent_group_id');
|
||||
});
|
||||
|
||||
Schema::dropIfExists('parent_groups');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user