Files
laraundfelix/database/migrations/2026_11_16_140000_editorial_dimensions.php
T
LarsandCursor 5e763d15ec
Deploy Test / test (push) Successful in 17s
Deploy Test / deploy (push) Successful in 25s
Ergaenze Stammdaten, Suche, Dimensionen, Abdeckung und Ausgabenachweis
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-16 08:24:23 +01:00

76 lines
2.8 KiB
PHP

<?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
{
public function up(): void
{
Schema::create('editorial_dimensions', function (Blueprint $table) {
$table->id();
$table->string('slug')->unique();
$table->string('label');
$table->timestamps();
});
Schema::create('editorial_dimension_values', function (Blueprint $table) {
$table->id();
$table->foreignId('editorial_dimension_id')->constrained()->cascadeOnDelete();
$table->string('slug');
$table->string('label');
$table->timestamps();
$table->unique(['editorial_dimension_id', 'slug']);
});
Schema::create('identity_dimension_values', function (Blueprint $table) {
$table->id();
$table->string('subject_type');
$table->unsignedBigInteger('subject_id');
$table->foreignId('editorial_dimension_value_id')->constrained()->cascadeOnDelete();
$table->string('origin');
$table->timestamps();
$table->unique(['subject_type', 'subject_id', 'editorial_dimension_value_id'], 'identity_dimension_unique');
});
$now = now();
$dimensionId = DB::table('editorial_dimensions')->insertGetId([
'slug' => 'saeule',
'label' => 'Fachliche Säule',
'created_at' => $now,
'updated_at' => $now,
]);
foreach (DB::table('pillars')->orderBy('id')->get() as $pillar) {
$slug = 'pfeiler-'.$pillar->id;
$valueId = DB::table('editorial_dimension_values')->insertGetId([
'editorial_dimension_id' => $dimensionId,
'slug' => $slug,
'label' => $pillar->name,
'created_at' => $now,
'updated_at' => $now,
]);
foreach (DB::table('content_element_pillar')->where('pillar_id', $pillar->id)->get() as $link) {
DB::table('identity_dimension_values')->insert([
'subject_type' => 'App\\Domain\\Catalog\\ContentElement',
'subject_id' => $link->content_element_id,
'editorial_dimension_value_id' => $valueId,
'origin' => 'direkt',
'created_at' => $now,
'updated_at' => $now,
]);
}
}
}
public function down(): void
{
Schema::dropIfExists('identity_dimension_values');
Schema::dropIfExists('editorial_dimension_values');
Schema::dropIfExists('editorial_dimensions');
}
};