++ Primo Caricamento
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Migration: crea la tabella customers
|
||||
//
|
||||
// Cos'è una migration?
|
||||
// È un file PHP che descrive modifiche al database in forma di codice.
|
||||
// Invece di scrivere SQL manualmente, usi il fluent Schema Builder di Laravel.
|
||||
//
|
||||
// Vantaggi:
|
||||
// - Versioning: le migration sono versionabili su Git come il codice
|
||||
// - Reversibilità: ogni migration ha un metodo down() per annullare
|
||||
// - Collaborazione: tutti i dev usano lo stesso DB schema
|
||||
//
|
||||
// Esecuzione:
|
||||
// php artisan migrate → esegue up() delle migration non ancora eseguite
|
||||
// php artisan migrate:rollback → esegue down() dell'ultima batch
|
||||
// php artisan migrate:fresh → CANCELLA tutto e ricrea (solo in development!)
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
// up(): eseguita da "php artisan migrate" → crea/modifica strutture
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('customers', function (Blueprint $table) {
|
||||
// id(): crea colonna "id" bigint UNSIGNED AUTO_INCREMENT PRIMARY KEY
|
||||
$table->id();
|
||||
|
||||
// Dati anagrafici
|
||||
$table->string('name'); // Ragione sociale / nome
|
||||
$table->string('email')->unique(); // Email (univoca)
|
||||
$table->string('phone', 50)->nullable(); // Telefono
|
||||
$table->string('city', 100)->nullable(); // Città
|
||||
$table->string('address')->nullable(); // Indirizzo completo
|
||||
$table->string('vat_number', 20)->nullable(); // Partita IVA
|
||||
$table->string('fiscal_code', 20)->nullable(); // Codice fiscale
|
||||
|
||||
// Tipo cliente: "privato" o "azienda"
|
||||
// enum() limita i valori accettati a livello DB
|
||||
$table->enum('type', ['privato', 'azienda'])->default('azienda');
|
||||
|
||||
// Stato nel ciclo di vita commerciale
|
||||
$table->enum('status', ['attivo', 'inattivo', 'prospect'])->default('prospect');
|
||||
|
||||
// Dati commerciali
|
||||
$table->decimal('contract_value', 10, 2)->default(0); // Valore contratto annuo
|
||||
$table->text('notes')->nullable(); // Note libere
|
||||
|
||||
// timestamps(): crea created_at e updated_at (gestiti automaticamente da Eloquent)
|
||||
$table->timestamps();
|
||||
|
||||
// softDeletes(): aggiunge colonna deleted_at per il Soft Delete
|
||||
// I clienti "eliminati" hanno deleted_at valorizzato, non sono rimossi dal DB
|
||||
$table->softDeletes();
|
||||
|
||||
// Indici per velocizzare le ricerche più comuni
|
||||
$table->index('status');
|
||||
$table->index('type');
|
||||
$table->index('city');
|
||||
});
|
||||
}
|
||||
|
||||
// down(): eseguita da "php artisan migrate:rollback" → annulla la migration
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('customers');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user