From d680b2bb494b441b1b14d8798dac96153a5737a4 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 4 Mar 2021 15:11:56 +0100 Subject: [PATCH] Update database structure --- docs/db_struct.sql | 40 ++-------------------------------------- docs/migration.sql | 41 ++--------------------------------------- 2 files changed, 4 insertions(+), 77 deletions(-) diff --git a/docs/db_struct.sql b/docs/db_struct.sql index d1006ee..94cf4ce 100644 --- a/docs/db_struct.sql +++ b/docs/db_struct.sql @@ -68,6 +68,7 @@ CREATE TABLE `comunic_conversations_list` ( `color` varchar(6) DEFAULT NULL, `background` varchar(255) DEFAULT NULL, `group_id` int DEFAULT NULL, + `last_activity` int DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; @@ -244,41 +245,4 @@ CREATE TABLE `comunic_custom_emojis` ( `user_id` INT NULL, `shortcut` VARCHAR(45) NULL, `path` VARCHAR(255) NULL, - PRIMARY KEY (`id`)); - - -CREATE VIEW comunic_conversations_info AS - SELECT - l.id, - m.user_id, - l.name, - l.color, - l.background, - l.creation_time, - l.group_id, - l.can_everyone_add_members, - m.is_admin, - m.added_on AS user_added_on, - m.following, - m.last_message_seen, - msg.id AS last_msg_id, - msg.time_sent AS last_msg_time_sent, - msg.user_id AS last_msg_user_id, - msg.message AS last_msg_message, - msg.filepath AS last_msg_filepath, - msg.file_size AS last_msg_file_size, - msg.file_name AS last_msg_file_name, - msg.file_thumbnail AS last_msg_file_thumbnail, - msg.file_type AS last_msg_file_type - FROM - comunic_conversations_list l - JOIN - comunic_conversations_members m ON l.id = m.conv_id - JOIN - (SELECT - MAX(id) AS max_msg_id, conv_id - FROM - comunic_conversations_messages - GROUP BY conv_id) msg_id ON msg_id.conv_id = l.id - JOIN - comunic_conversations_messages msg ON msg.id = msg_id.max_msg_id; \ No newline at end of file + PRIMARY KEY (`id`)); \ No newline at end of file diff --git a/docs/migration.sql b/docs/migration.sql index 0faabd4..9f4cb0f 100644 --- a/docs/migration.sql +++ b/docs/migration.sql @@ -20,45 +20,8 @@ alter table comunic_conversations_members -- Conversations list table alter table comunic_conversations_list drop column user_id; -alter table comunic_conversations_list drop column last_active; +alter table comunic_conversations_list rename column last_active to last_activity; alter table comunic_conversations_list add column color varchar(6), add column background varchar(255), - add group_id int; - --- Conversations view -CREATE VIEW comunic_conversations_info AS - SELECT - l.id, - m.user_id, - l.name, - l.color, - l.background, - l.creation_time, - l.group_id, - l.can_everyone_add_members, - m.is_admin, - m.added_on AS user_added_on, - m.following, - m.last_message_seen, - msg.id AS last_msg_id, - msg.time_sent AS last_msg_time_sent, - msg.user_id AS last_msg_user_id, - msg.message AS last_msg_message, - msg.filepath AS last_msg_filepath, - msg.file_size AS last_msg_file_size, - msg.file_name AS last_msg_file_name, - msg.file_thumbnail AS last_msg_file_thumbnail, - msg.file_type AS last_msg_file_type - FROM - comunic_conversations_list l - JOIN - comunic_conversations_members m ON l.id = m.conv_id - JOIN - (SELECT - MAX(id) AS max_msg_id, conv_id - FROM - comunic_conversations_messages - GROUP BY conv_id) msg_id ON msg_id.conv_id = l.id - JOIN - comunic_conversations_messages msg ON msg.id = msg_id.max_msg_id; \ No newline at end of file + add group_id int; \ No newline at end of file