mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
99 lines
2.8 KiB
PHP
99 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Database\Migrations;
|
|
|
|
use CodeIgniter\Database\Migration;
|
|
|
|
class ModifyAlbaranesAndAlbaranesLineas extends Migration
|
|
{
|
|
public function up()
|
|
{
|
|
// --- Tabla albaranes ---
|
|
$this->forge->dropColumn('albaranes', [
|
|
'pedido_id',
|
|
'presupuesto_id',
|
|
'presupuesto_direccion_id',
|
|
'total'
|
|
]);
|
|
|
|
$this->forge->addColumn('albaranes', [
|
|
'fecha_albaran' => [
|
|
'type' => 'DATE',
|
|
'null' => true,
|
|
'after' => 'numero_albaran'
|
|
],
|
|
'envio_id' => [
|
|
'type' => 'INT',
|
|
'constraint' => 10,
|
|
'unsigned' => true,
|
|
'null' => true,
|
|
'after' => 'fecha_albaran'
|
|
]
|
|
]);
|
|
|
|
// Añadir foreign key a envios con ON DELETE SET NULL
|
|
$this->db->query('ALTER TABLE `albaranes`
|
|
ADD CONSTRAINT `fk_albaranes_envio_id` FOREIGN KEY (`envio_id`)
|
|
REFERENCES `envios`(`id`) ON DELETE SET NULL ON UPDATE CASCADE');
|
|
|
|
// --- Tabla albaranes_lineas ---
|
|
$this->forge->dropColumn('albaranes_lineas', ['cajas', 'ejemplares_por_caja']);
|
|
|
|
$this->forge->addColumn('albaranes_lineas', [
|
|
'iva_reducido' => [
|
|
'type' => 'TINYINT',
|
|
'constraint' => 1,
|
|
'default' => 0,
|
|
'null' => false,
|
|
'after' => 'precio_unidad'
|
|
]
|
|
]);
|
|
}
|
|
|
|
public function down()
|
|
{
|
|
// Deshacer cambios tabla albaranes
|
|
$this->forge->dropForeignKey('albaranes', 'fk_albaranes_envio_id');
|
|
$this->forge->dropColumn('albaranes', ['envio_id', 'fecha_albaran']);
|
|
|
|
$this->forge->addColumn('albaranes', [
|
|
'pedido_id' => [
|
|
'type' => 'INT',
|
|
'constraint' => 10,
|
|
'unsigned' => true,
|
|
'null' => true,
|
|
],
|
|
'presupuesto_id' => [
|
|
'type' => 'INT',
|
|
'constraint' => 10,
|
|
'unsigned' => true,
|
|
'null' => true,
|
|
],
|
|
'presupuesto_direccion_id' => [
|
|
'type' => 'INT',
|
|
'constraint' => 10,
|
|
'unsigned' => true,
|
|
'null' => true,
|
|
],
|
|
'total' => [
|
|
'type' => 'DOUBLE',
|
|
'null' => true,
|
|
],
|
|
]);
|
|
|
|
// Deshacer cambios tabla albaranes_lineas
|
|
$this->forge->dropColumn('albaranes_lineas', ['iva_reducido']);
|
|
|
|
$this->forge->addColumn('albaranes_lineas', [
|
|
'cajas' => [
|
|
'type' => 'INT',
|
|
'null' => true,
|
|
],
|
|
'ejemplares_por_caja' => [
|
|
'type' => 'INT',
|
|
'null' => true,
|
|
],
|
|
]);
|
|
}
|
|
}
|