peppa/packages/db/migrations/0005_push_notifications.sql
Асель ea4bdf38ff PEP-29/35/55: notification prefs and routing, Web Push outbox, daily digest; mock-push, tests
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 05:10:20 +05:00

29 lines
1.2 KiB
SQL

CREATE TABLE `push_outbox` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`dedupe_key` text NOT NULL,
`subscription_id` integer,
`payload` text NOT NULL,
`urgency` text DEFAULT 'normal' NOT NULL,
`status` text DEFAULT 'pending' NOT NULL,
`attempts` integer DEFAULT 0 NOT NULL,
`next_attempt_at` integer DEFAULT (cast(unixepoch('subsec') * 1000 as integer)) NOT NULL,
`error` text,
`created_at` integer DEFAULT (cast(unixepoch('subsec') * 1000 as integer)) NOT NULL,
`sent_at` integer,
FOREIGN KEY (`subscription_id`) REFERENCES `push_subscriptions`(`id`) ON UPDATE no action ON DELETE set null
);
--> statement-breakpoint
CREATE UNIQUE INDEX `push_outbox_dedupe_key_unique` ON `push_outbox` (`dedupe_key`);--> statement-breakpoint
CREATE TABLE `push_subscriptions` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`user_id` integer NOT NULL,
`endpoint` text NOT NULL,
`p256dh` text NOT NULL,
`auth` text NOT NULL,
`user_agent` text,
`created_at` integer DEFAULT (cast(unixepoch('subsec') * 1000 as integer)) NOT NULL,
`last_ok_at` integer,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE UNIQUE INDEX `push_subscriptions_endpoint_unique` ON `push_subscriptions` (`endpoint`);