mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-26 07:19:22 +00:00
Update database structure
This commit is contained in:
parent
bce79a76e9
commit
d680b2bb49
@ -68,6 +68,7 @@ CREATE TABLE `comunic_conversations_list` (
|
|||||||
`color` varchar(6) DEFAULT NULL,
|
`color` varchar(6) DEFAULT NULL,
|
||||||
`background` varchar(255) DEFAULT NULL,
|
`background` varchar(255) DEFAULT NULL,
|
||||||
`group_id` int DEFAULT NULL,
|
`group_id` int DEFAULT NULL,
|
||||||
|
`last_activity` int DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||||
|
|
||||||
@ -245,40 +246,3 @@ CREATE TABLE `comunic_custom_emojis` (
|
|||||||
`shortcut` VARCHAR(45) NULL,
|
`shortcut` VARCHAR(45) NULL,
|
||||||
`path` VARCHAR(255) NULL,
|
`path` VARCHAR(255) NULL,
|
||||||
PRIMARY KEY (`id`));
|
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;
|
|
@ -20,45 +20,8 @@ alter table comunic_conversations_members
|
|||||||
|
|
||||||
-- Conversations list table
|
-- Conversations list table
|
||||||
alter table comunic_conversations_list drop column user_id;
|
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
|
alter table comunic_conversations_list
|
||||||
add column color varchar(6),
|
add column color varchar(6),
|
||||||
add column background varchar(255),
|
add column background varchar(255),
|
||||||
add group_id int;
|
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;
|
|
Loading…
Reference in New Issue
Block a user