pdv.backend/database/migrations/2026_02_10_093124_create_suppliers_table.php

51 lines
1.7 KiB
PHP

<?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
{
// 1. Preguntamos si la tabla NO existe antes de crearla
if (!Schema::hasTable('suppliers')) {
Schema::create('suppliers', function (Blueprint $table) {
$table->id();
$table->string('business_name');
$table->string('rfc')->nullable();
$table->string('email')->nullable();
$table->string('phone')->nullable();
$table->string('address')->nullable();
$table->string('postal_code')->nullable();
$table->text('notes')->nullable();
$table->timestamps();
});
}
if (!Schema::hasColumn('inventory_movements', 'supplier_id')) {
Schema::table('inventory_movements', function (Blueprint $table) {
$table->foreignId('supplier_id')
->nullable()
->after('warehouse_to_id')
->constrained('suppliers')
->onDelete('restrict');
$table->index(['supplier_id', 'movement_type']);
});
}
}
public function down(): void
{
Schema::table('inventory_movements', function (Blueprint $table) {
if (Schema::hasColumn('inventory_movements', 'supplier_id')) {
$table->dropForeign(['supplier_id']);
$table->dropIndex(['supplier_id', 'movement_type']);
$table->dropColumn('supplier_id');
}
});
Schema::dropIfExists('suppliers');
}
};