chore(messages/labels): removed unnecessary npwd_messages_labels column (#253)

This commit is contained in:
Jan Lecoutere authored and GitHub committed 2021-06-09 20:21:20 +02:00
1 parent 94633e53a6
commit 865a8e44de
3 files changed
+11 -18

No files matched your search

-10
View File
@@ -133,16 +133,6 @@ CREATE TABLE IF NOT EXISTS `npwd_messages_groups` (
PRIMARY KEY (`id`)
);
CREATE TABLE IF NOT EXISTS `npwd_messages_labels` (
`id` int NOT NULL AUTO_INCREMENT,
`user_identifier` varchar(48) NOT NULL,
`label` varchar(60) NOT NULL,
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`group_id` varchar(512) NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE IF NOT EXISTS `npwd_messages` (
`id` int NOT NULL AUTO_INCREMENT,
`message` varchar(512) NOT NULL,
+10 -7
View File
@@ -44,7 +44,7 @@ export class _MessagesDB {
npwd_messages_groups.group_id,
npwd_messages_groups.participant_identifier,
npwd_messages_groups.user_identifier,
npwd_messages_labels.label,
npwd_messages_groups.label,
${config.database.playerTable}.phone_number,
npwd_phone_contacts.avatar,
npwd_phone_contacts.display
@@ -55,7 +55,6 @@ export class _MessagesDB {
) as t
LEFT OUTER JOIN npwd_messages_groups on npwd_messages_groups.group_id = t.group_id
LEFT OUTER JOIN ${config.database.playerTable} on ${config.database.playerTable}.${config.database.identifierColumn} = npwd_messages_groups.participant_identifier
LEFT OUTER JOIN npwd_messages_labels on npwd_messages_labels.group_id = npwd_messages_groups.group_id
LEFT OUTER JOIN npwd_phone_contacts on REGEXP_REPLACE(npwd_phone_contacts.number, '[^0-9]', '') = REGEXP_REPLACE(${config.database.playerTable}.phone_number, '[^0-9]', '') AND npwd_phone_contacts.identifier = ?
ORDER BY npwd_messages_groups.createdAt DESC
`;
@@ -105,13 +104,17 @@ export class _MessagesDB {
* @param groupId - groupId this label is attached to
* @param label - the label itself
*/
async createLabel(userIdentifier: string, groupId: string, label: string): Promise<void> {
async setLabel(userIdentifier: string, groupId: string, label: string): Promise<void> {
const query = `
INSERT INTO npwd_messages_labels
(user_identifier, group_id, label)
VALUES (?, ?, ?)
UPDATE
npwd_messages_groups
SET
label = ?
WHERE
group_id = ?
AND user_identifier = ?
`;
await pool.query(query, [userIdentifier, groupId, label]);
await pool.query(query, [label, groupId, userIdentifier]);
}
/**
+1 -1
View File
@@ -183,7 +183,7 @@ export async function createMessageGroupsFromPhoneNumbers(
// we allow users to attach labels to name their group chats
if (groupLabel) {
queryPromises.push(MessagesDB.createLabel(userIdentifier, groupId, groupLabel));
queryPromises.push(MessagesDB.setLabel(userIdentifier, groupId, groupLabel));
}
// wrap this in a transaction to make sure ALL of these INSERTs succeed