This repository has been archived on 2023-11-14. You can view files and clone it, but cannot push or open issues/pull-requests.
viscord/packages/server/public/migrations/5-link-messages-to-clients.sql

22 lines
555 B
MySQL
Raw Permalink Normal View History

2022-07-23 17:37:24 -04:00
-- make uid unique in clients
ALTER TABLE `clients`
ADD UNIQUE `uid` (`uid`);
-- add a sender column for foreign key reference
ALTER TABLE `messages`
ADD `sender_uid` varchar(36) COLLATE 'utf8mb4_general_ci' NOT NULL;
-- create an anonymous user for all previous messages
SELECT @anon_uid := UUID();
INSERT INTO clients (name, uid)
VALUES ('Anonymous', @anon_uid);
UPDATE messages
SET sender_uid=@anon_uid
WHERE sender_uid='';
-- create the foreign key relationship
ALTER TABLE `messages`
ADD FOREIGN KEY (`sender_uid`) REFERENCES `clients` (`uid`);