Skip to content

Commit

Permalink
add activity table
Browse files Browse the repository at this point in the history
  • Loading branch information
xerosanyam committed Jun 28, 2024
1 parent bcb10cb commit 0399d4a
Show file tree
Hide file tree
Showing 5 changed files with 425 additions and 8 deletions.
5 changes: 5 additions & 0 deletions essays/drizzle-gotchas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Drizzle

### LibsqlError: SQL_NO_STATEMENT: SQL string does not contain any statemen

- the last statement cannot be `--> statement-breakpoint`
61 changes: 61 additions & 0 deletions migrations/0001_plain_stingray.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
CREATE TABLE `activity`(
`id` text PRIMARY KEY NOT NULL,
`action` text NOT NULL,
`card_id` text NOT NULL,
`user_id` text NOT NULL,
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
FOREIGN KEY (`card_id`) REFERENCES `card`(`id`) ON UPDATE NO action ON DELETE NO action,
FOREIGN KEY (`user_id`) REFERENCES `auth_user`(`id`) ON UPDATE NO action ON DELETE NO action
);

--> statement-breakpoint
CREATE TRIGGER log_card_insert
AFTER INSERT ON card
BEGIN
INSERT INTO activity(id,
action,
card_id,
user_id,
created_at)
VALUES(lower(hex(randomblob(16))),
'INSERT',
NEW.id,
NEW.user_id,
strftime('%s', 'now'));

END;

--> statement-breakpoint
CREATE TRIGGER log_card_update
AFTER UPDATE ON card
BEGIN
INSERT INTO activity(id,
action,
card_id,
user_id,
created_at)
VALUES(lower(hex(randomblob(16))),
'UPDATE',
NEW.id,
NEW.user_id,
strftime('%s', 'now'));

END;

--> statement-breakpoint
CREATE TRIGGER log_card_delete
AFTER DELETE ON card
BEGIN
INSERT INTO activity(id,
action,
card_id,
user_id,
created_at)
VALUES(lower(hex(randomblob(16))),
'DELETE',
OLD.id,
OLD.user_id,
strftime('%s', 'now'));

END;

Loading

0 comments on commit 0399d4a

Please sign in to comment.