Update 2026_01_08_195707_update_proveedors_table.php
This commit is contained in:
@@ -12,12 +12,22 @@ return new class extends Migration
|
|||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
Schema::table('proveedors', function (Blueprint $table) {
|
Schema::table('proveedors', function (Blueprint $table) {
|
||||||
// Agregar nuevos campos
|
// Evitar operaciones que SQLite no maneja correctamente en tests
|
||||||
$table->string('nit')->nullable()->after('nombre');
|
$driver = Schema::getConnection()->getDriverName();
|
||||||
$table->string('categoria')->after('nit');
|
|
||||||
|
|
||||||
// Eliminar campos que no se usarán
|
// Agregar nuevos campos si no existen
|
||||||
$table->dropColumn(['contacto', 'correo']);
|
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
|
public function down(): void
|
||||||
{
|
{
|
||||||
Schema::table('proveedors', function (Blueprint $table) {
|
Schema::table('proveedors', function (Blueprint $table) {
|
||||||
// Restaurar columnas eliminadas
|
$driver = Schema::getConnection()->getDriverName();
|
||||||
$table->string('contacto')->nullable();
|
|
||||||
$table->string('correo')->unique()->nullable();
|
|
||||||
|
|
||||||
// Eliminar columnas nuevas
|
// Restaurar columnas eliminadas si no existen
|
||||||
$table->dropColumn(['nit', 'categoria']);
|
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']);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user