mein-sterntours/database/migrations/2026_04_17_100001_create_offers_table.php

72 lines
2.6 KiB
PHP

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Modul 6 — Angebote: Ticket A1 / Migration 1 von 7.
*
* Erstellt die Haupttabelle `offers`. Jeder Datensatz hier ist ein
* logisches Angebot (eine Angebotsnummer). Die tatsächlichen Inhalte
* (Texte, Positionen, Preise, PDF, Dokumente) liegen versionsweise in
* `offer_versions`. Ab dem ersten Versand erzeugt jede Änderung eine
* neue Version (Entscheidung 17.1 des Entwicklungsplans).
*
* VORBEDINGUNG:
* - Modul 3 Phase 2 (Tabellen `contacts` + `inquiries`) muss
* eingespielt sein. Siehe dev/customer-bookings/umsetzung.md.
*
* Tabelle `offers.current_version_id` wird als FK erst in der Migration
* 2026_04_17_100007 gesetzt (zyklische Abhängigkeit zu `offer_versions`).
*/
return new class extends Migration
{
public function up(): void
{
Schema::create('offers', function (Blueprint $t) {
$t->id();
$t->string('offer_number', 32)->unique();
// FK-Typen MÜSSEN exakt zur Referenz passen.
// Die Legacy-Tabellen contacts/inquiries/booking sind aus dem
// alten Sequel-Pro-Export mit `bigint` (SIGNED) angelegt; die
// users-Tabelle nutzt `int unsigned`. Daher hier explizit
// typisieren statt foreignId() (das würde bigint UNSIGNED erzeugen).
$t->bigInteger('contact_id');
$t->bigInteger('inquiry_id')->nullable();
$t->bigInteger('booking_id')->nullable();
$t->enum('status', [
'draft',
'sent',
'accepted',
'declined',
'expired',
'withdrawn',
])->default('draft');
// FK wird in 2026_04_17_100007 nachträglich gesetzt
$t->unsignedBigInteger('current_version_id')->nullable();
// users.id ist int unsigned (Legacy)
$t->unsignedInteger('created_by');
$t->timestamps();
$t->softDeletes();
$t->foreign('contact_id')->references('id')->on('contacts')->restrictOnDelete();
$t->foreign('inquiry_id')->references('id')->on('inquiries')->nullOnDelete();
$t->foreign('booking_id')->references('id')->on('booking')->nullOnDelete();
$t->foreign('created_by')->references('id')->on('users');
$t->index(['status', 'contact_id']);
$t->index('inquiry_id');
});
}
public function down(): void
{
Schema::dropIfExists('offers');
}
};