Files
safekat/ci4/app/Database/Migrations/2024-11-30-170000_OrdenTrabajoTable.php
amazuecos d5719b70a1 ots
2024-12-15 16:07:54 +01:00

105 lines
2.7 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
use CodeIgniter\Database\RawSql;
class OrdenTrabajoTable extends Migration
{
protected array $COLUMNS = [
"id" => [
"type" => "INT",
"unsigned" => true,
"auto_increment" => true
],
"pedido_id" => [
"type" => "INT",
"unsigned" => true,
"constraint" => 16,
"comment" => "Pedido original asociado",
],
"user_created_id" => [
"type" => "INT",
"unsigned" => true,
"constraint" => 10,
"comment" => "Usuario que ha pasado el pedido a producción",
],
"user_updated_id" => [
"type" => "INT",
"unsigned" => true,
"constraint" => 10,
"comment" => "Usuario que ha actualizado la orden de trabajo",
],
"total_tirada" => [
"type" => "DOUBLE",
"null" => true
],
"total_precio" => [
"type" => "DOUBLE",
"null" => true
],
"tipo_entrada" => [
"type" => "ENUM",
"constraint" => ["in", "out"],
"default" => "out",
"comment" => "Tipo de entrada"
],
"progreso" => [
"type" => "DOUBLE",
"default" => 0.00,
"comment" => "Progreso de 0 a 100"
],
"estado" => [
"type" => "ENUM",
"constraint" => ["I","F","P","E"],
"default" => "I",
"comment" => "I => INICIADO, F => FINALIZADO, P => PROGRESO , E => ERROR"
],
"comentarios" => [
"type" => "TEXT",
"null" => true,
"default" => null,
"comment" => "Comentarios orden de trabajo"
]
];
public function up()
{
$this->forge->addField($this->COLUMNS);
$currenttime = new RawSql("CURRENT_TIMESTAMP");
$this->forge->addField([
"created_at" => [
"type" => "TIMESTAMP",
"default" => $currenttime,
],
"updated_at" => [
"type" => "TIMESTAMP",
"null" => true,
],
"deleted_at" => [
"type" => "TIMESTAMP",
"null" => true,
],
]);
$this->forge->addPrimaryKey("id");
$this->forge->addForeignKey("pedido_id","pedidos","id");
$this->forge->addForeignKey("user_created_id","users","id");
$this->forge->addForeignKey("user_updated_id","users","id");
$this->forge->createTable("ordenes_trabajo", true);
}
public function down()
{
$this->forge->dropTable("ordenes_trabajo");
}
}