mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-08-01 02:42:05 -04:00
28 lines
824 B
SQL
28 lines
824 B
SQL
CREATE TABLE IF NOT EXISTS user_notifications
|
|
(
|
|
notification_id TEXT NOT NULL,
|
|
user_id TEXT NOT NULL,
|
|
data JSONB NOT NULL,
|
|
CONSTRAINT user_notifications_pkey PRIMARY KEY (notification_id, user_id)
|
|
);
|
|
|
|
|
|
ALTER TABLE user_notifications
|
|
ADD CONSTRAINT user_notifications_user_id_fkey
|
|
FOREIGN KEY (user_id)
|
|
REFERENCES users (id)
|
|
ON DELETE CASCADE;
|
|
|
|
-- Row Level Security
|
|
ALTER TABLE user_notifications
|
|
ENABLE ROW LEVEL SECURITY;
|
|
|
|
-- Indexes
|
|
-- The primary key already creates a unique index on (notification_id, user_id)
|
|
|
|
CREATE INDEX IF NOT EXISTS user_notifications_user_id_created_time
|
|
ON public.user_notifications (
|
|
user_id,
|
|
((data ->> 'createdTime')::BIGINT) DESC
|
|
);
|