Update 2026_01_08_195707_update_proveedors_table.php

This commit is contained in:
lizandrogd
2026-01-19 23:05:20 -05:00
parent 2f22fc7736
commit 674bf82309
@@ -12,12 +12,22 @@ return new class extends Migration
public function up(): void
{
Schema::table('proveedors', function (Blueprint $table) {
// Agregar nuevos campos
$table->string('nit')->nullable()->after('nombre');
$table->string('categoria')->after('nit');
// Evitar operaciones que SQLite no maneja correctamente en tests
$driver = Schema::getConnection()->getDriverName();
// Eliminar campos que no se usarán
$table->dropColumn(['contacto', 'correo']);
// Agregar nuevos campos si no existen
if (! Schema::hasColumn('proveedors', 'nit')) {
$table->string('nit')->nullable();
}
if (! Schema::hasColumn('proveedors', 'categoria')) {
$table->string('categoria')->nullable();
}
// En bases que no son SQLite, eliminar campos antiguos
if ($driver !== 'sqlite') {
$table->dropColumn(['contacto', 'correo']);
}
});
}
@@ -27,12 +37,21 @@ return new class extends Migration
public function down(): void
{
Schema::table('proveedors', function (Blueprint $table) {
// Restaurar columnas eliminadas
$table->string('contacto')->nullable();
$table->string('correo')->unique()->nullable();
$driver = Schema::getConnection()->getDriverName();
// Eliminar columnas nuevas
$table->dropColumn(['nit', 'categoria']);
// Restaurar columnas eliminadas si no existen
if (! Schema::hasColumn('proveedors', 'contacto')) {
$table->string('contacto')->nullable();
}
if (! Schema::hasColumn('proveedors', 'correo')) {
$table->string('correo')->unique()->nullable();
}
// En bases no SQLite, eliminar las columnas nuevas
if ($driver !== 'sqlite') {
$table->dropColumn(['nit', 'categoria']);
}
});
}
};