Skip to content

Commit

Permalink
Add trigger to update roomUpdated timestamp when a new message is ins…
Browse files Browse the repository at this point in the history
…erted
  • Loading branch information
yasuaki640 committed Feb 25, 2024
1 parent a6dfe1c commit d829f91
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drizzle/0001_define_messages.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ CREATE TABLE `messages` (
`message` text NOT NULL,
`messageCreated` text DEFAULT CURRENT_TIMESTAMP NOT NULL
);

-- added by me
CREATE TRIGGER IF NOT EXISTS messages_updated
AFTER INSERT ON messages
BEGIN
UPDATE rooms
SET roomUpdated = CURRENT_TIMESTAMP
WHERE roomId = NEW.roomId;
END;

0 comments on commit d829f91

Please sign in to comment.