netgescon-day0/database/migrations/2025_07_05_120000_create_documenti_table.php

38 lines
1.7 KiB
PHP
Executable File

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::create('documenti', function (Blueprint $table) {
$table->id();
$table->string('protocollo')->nullable()->unique(); // es. 2025-0001
$table->date('data_protocollo')->nullable();
$table->string('tipo_documento')->nullable(); // Fattura, Contratto, Verbale, ecc.
$table->unsignedBigInteger('stabile_id')->nullable();
$table->unsignedBigInteger('fornitore_id')->nullable();
$table->unsignedBigInteger('esercizio_contabile_id')->nullable();
$table->text('descrizione')->nullable();
$table->decimal('importo', 12, 2)->nullable();
$table->date('data_documento')->nullable();
$table->string('nome_file');
$table->string('path_file');
$table->text('testo_estratto_ocr')->nullable();
// Polimorfismo
$table->unsignedBigInteger('documentable_id')->nullable()->index();
$table->string('documentable_type')->nullable()->index();
$table->timestamps();
// FK opzionali
$table->foreign('stabile_id')->references('id')->on('stabili')->onDelete('set null');
$table->foreign('fornitore_id')->references('id')->on('fornitori')->onDelete('set null');
// $table->foreign('esercizio_contabile_id')->references('id')->on('esercizi_contabili')->onDelete('set null'); // FK disabilitata: tabella non ancora presente
});
}
public function down(): void
{
Schema::dropIfExists('documenti');
}
};