feat : migration and chat models

This commit is contained in:
Alvaro Mazuecos Nogales
2024-09-20 11:25:34 +02:00
parent b25abc19d9
commit bfea4aa67c
9 changed files with 158 additions and 59 deletions

View File

@ -0,0 +1,62 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\RawSql;
use CodeIgniter\Database\Migration;
class ChatsTable extends Migration
{
protected array $COLUMNS = [
"id" => [
"type" => "INT",
"unsigned" => true,
"auto_increment" => true
],
"chat_department_id" => [
"type" => "INT",
"unsigned" => true,
],
"pedido_id" => [
"type" => "INT",
"constraint" => 16,
"unsigned" => true,
],
];
public function up()
{
$this->forge->dropTable("chat_conversaciones", true);
$this->forge->dropTable("chat_mensajes", true);
$this->forge->dropTable("chat_participantes", true);
$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('chat_department_id', 'chat_departments', 'id');
$this->forge->createTable("chats", true);
}
public function down()
{
//
$this->forge->dropTable("chats", true);
}
}