Configurations for payment modules
This commit is contained in:
+23
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('available_payment_methods', function (Blueprint $table) {
|
||||
$table->json('configuration')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('available_payment_methods', function (Blueprint $table) {
|
||||
$table->dropColumn('configuration');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('event_payment_methods', function (Blueprint $table) {
|
||||
$table->json('configuration')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('event_payment_methods', function (Blueprint $table) {
|
||||
$table->dropColumn('configuration');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* Reparatur-Migration für eine Drift in event_payment_methods:
|
||||
*
|
||||
* Eine frühere Version von 2026_07_28_140020_create_event_payment_methods hatte die Verknüpfung
|
||||
* über available_payment_method_id (FK auf available_payment_methods.id) modelliert. Die Migration
|
||||
* wurde später in-place auf slug (FK auf payment_methods.slug) umgestellt -- Systeme, die noch die
|
||||
* alte Version ausgeführt haben, tragen daher available_payment_method_id statt slug.
|
||||
*
|
||||
* Diese Migration konvertiert solche Systeme verlustfrei auf slug. Auf Systemen, die bereits die
|
||||
* korrekte slug-Struktur haben (frische Installationen), ist sie ein No-Op.
|
||||
*/
|
||||
return new class extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
// Frisch / bereits korrekt -> nichts zu tun.
|
||||
if (!Schema::hasColumn('event_payment_methods', 'available_payment_method_id')
|
||||
|| Schema::hasColumn('event_payment_methods', 'slug')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. slug zunächst nullable anlegen (für den Backfill).
|
||||
Schema::table('event_payment_methods', function (Blueprint $table) {
|
||||
$table->string('slug')->nullable()->after('event_id');
|
||||
});
|
||||
|
||||
// 2. slug aus der verknüpften available_payment_methods-Zeile übernehmen.
|
||||
DB::statement('
|
||||
UPDATE event_payment_methods epm
|
||||
JOIN available_payment_methods apm ON apm.id = epm.available_payment_method_id
|
||||
SET epm.slug = apm.slug
|
||||
');
|
||||
|
||||
// 3. Alte Spalte samt FK entfernen.
|
||||
Schema::table('event_payment_methods', function (Blueprint $table) {
|
||||
$table->dropForeign(['available_payment_method_id']);
|
||||
$table->dropColumn('available_payment_method_id');
|
||||
});
|
||||
|
||||
// 4. slug final absichern: NOT NULL, Unique (event_id, slug), FK auf payment_methods.slug.
|
||||
Schema::table('event_payment_methods', function (Blueprint $table) {
|
||||
$table->string('slug')->nullable(false)->change();
|
||||
$table->unique(['event_id', 'slug']);
|
||||
$table->foreign('slug')->references('slug')->on('payment_methods')->restrictOnDelete()->cascadeOnUpdate();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
// Nur umkehren, wenn tatsächlich die slug-Struktur vorliegt.
|
||||
if (!Schema::hasColumn('event_payment_methods', 'slug')
|
||||
|| Schema::hasColumn('event_payment_methods', 'available_payment_method_id')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('event_payment_methods', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('available_payment_method_id')->nullable()->after('event_id');
|
||||
});
|
||||
|
||||
// Backfill über den Tenant des Events, da available_payment_methods pro (tenant, slug) eindeutig ist.
|
||||
DB::statement('
|
||||
UPDATE event_payment_methods epm
|
||||
JOIN events e ON e.id = epm.event_id
|
||||
JOIN available_payment_methods apm ON apm.slug = epm.slug AND apm.tenant = e.tenant
|
||||
SET epm.available_payment_method_id = apm.id
|
||||
');
|
||||
|
||||
Schema::table('event_payment_methods', function (Blueprint $table) {
|
||||
$table->dropForeign(['slug']);
|
||||
$table->dropUnique(['event_id', 'slug']);
|
||||
$table->dropColumn('slug');
|
||||
});
|
||||
|
||||
Schema::table('event_payment_methods', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('available_payment_method_id')->nullable(false)->change();
|
||||
$table->foreign('available_payment_method_id')->references('id')->on('available_payment_methods')->cascadeOnUpdate();
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user