sendou.ink/migrations/082-notification.js
Kalle 4ff0586ff8
Notifications (#2117)
* Initial

* Progress

* Fix

* Progress

* Notifications list page

* BADGE_MANAGER_ADDED

* Mark as seen initial

* Split tables

* Progress

* Fix styles

* Push notifs initial

* Progress

* Rename

* Routines

* Progress

* Add e2e tests

* Done?

* Try updating actions

* Consistency

* Dep fix

* A couple fixes
2025-03-01 13:59:34 +02:00

52 lines
1.3 KiB
JavaScript

export function up(db) {
db.transaction(() => {
db.prepare(
/*sql*/ `
create table "Notification" (
"id" integer primary key,
"type" text not null,
"meta" text,
"pictureUrl" text,
"createdAt" integer default (strftime('%s', 'now')) not null
) strict
`,
).run();
db.prepare(
/*sql*/ `create index notification_type on "Notification"("type")`,
).run();
db.prepare(
/*sql*/ `
create table "NotificationUser" (
"notificationId" integer not null,
"userId" integer not null,
"seen" integer default 0 not null,
unique("notificationId", "userId"),
foreign key ("notificationId") references "Notification"("id") on delete cascade,
foreign key ("userId") references "User"("id") on delete cascade
) strict
`,
).run();
db.prepare(
/*sql*/ `create index notification_user_id on "NotificationUser"("userId")`,
).run();
db.prepare(
/*sql*/ `
create table "NotificationUserSubscription" (
"id" integer primary key,
"userId" integer not null,
"subscription" text not null,
foreign key ("userId") references "User"("id") on delete cascade
) strict
`,
).run();
db.prepare(
/*sql*/ `create index notification_push_url_user_id on "NotificationUserSubscription"("userId")`,
).run();
})();
}