feat : chat migrations

This commit is contained in:
amazuecos
2024-09-20 08:54:43 +02:00
parent f8dd56b74c
commit b25abc19d9
5 changed files with 27 additions and 8 deletions

View File

@ -13,9 +13,9 @@ class ChatsTable extends Migration
"unsigned" => true, "unsigned" => true,
"autoincrement" => true "autoincrement" => true
], ],
"department" => [ "chat_department_id" => [
"type" => "VARCHAR", "type" => "INT",
"constraint" => '255', "unsigned" => true,
], ],
"pedido_id" => [ "pedido_id" => [
"type" => "INT", "type" => "INT",
@ -50,13 +50,14 @@ class ChatsTable extends Migration
]); ]);
$this->forge->addPrimaryKey('id'); $this->forge->addPrimaryKey('id');
$this->forge->addForeignKey('pedido_id', 'pedidos', 'id'); $this->forge->addForeignKey('pedido_id', 'pedidos', 'id');
$this->forge->createTable("chats"); // $this->forge->addForeignKey('chat_department_id', 'chat_departments', 'id');
$this->forge->createTable("chats",true);
} }
public function down() public function down()
{ {
// //
$this->forge->dropTable("chats"); $this->forge->dropTable("chats",true);
} }
} }

View File

@ -41,7 +41,7 @@ class ChatDepartments extends Migration
], ],
]); ]);
$this->forge->createTable("chat_departments"); $this->forge->createTable("chat_departments",true);
$this->forge->addPrimaryKey('id'); $this->forge->addPrimaryKey('id');
} }

View File

@ -22,6 +22,9 @@ class ChatMessages extends Migration
"unsigned" => true, "unsigned" => true,
], ],
"message" => [
"type" => "TEXT",
],
]; ];
@ -48,7 +51,7 @@ class ChatMessages extends Migration
], ],
]); ]);
$this->forge->createTable("chat_messages"); $this->forge->createTable("chat_messages",true);
} }

View File

@ -38,7 +38,7 @@ class ChatDepartmentUsers extends Migration
], ],
]); ]);
$this->forge->createTable("chat_department_users"); $this->forge->createTable("chat_department_users",true);

View File

@ -45,4 +45,19 @@ class ChatModel extends Model
protected $afterDelete = []; protected $afterDelete = [];
public function getChat(int $chat_id)
{
$this->db->table('chats')
->select([
"chats.id as chatId",
"users.id as userId",
"users.email",
"chat_messages.created_at as messageCreatedAt",
"chat_messages.message as messageText",
]
)
->join("users","users.id == chat_messages.user_id","left")
->join("chat_messages","chats.id == chat_messages.chat_id","left");
}
} }