-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadd_push_tokens.sql
More file actions
41 lines (34 loc) · 1.5 KB
/
Copy pathadd_push_tokens.sql
File metadata and controls
41 lines (34 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-- Bootstrap schema. Formal uniqueness is (user_id, device_id, token_type) in
-- supabase/migrations/20260813120000_push_tokens_device_id.sql (mirrored in click-web).
CREATE TABLE IF NOT EXISTS push_tokens (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
token TEXT NOT NULL UNIQUE,
platform TEXT NOT NULL CHECK (platform IN ('android', 'ios')),
updated_at BIGINT NOT NULL,
created_at BIGINT NOT NULL DEFAULT (EXTRACT(EPOCH FROM NOW()) * 1000)::BIGINT
);
CREATE INDEX IF NOT EXISTS idx_push_tokens_user_id ON push_tokens(user_id);
CREATE INDEX IF NOT EXISTS idx_push_tokens_platform ON push_tokens(platform);
ALTER TABLE push_tokens ENABLE ROW LEVEL SECURITY;
DROP POLICY IF EXISTS "Users can read their own push tokens" ON push_tokens;
CREATE POLICY "Users can read their own push tokens"
ON push_tokens
FOR SELECT
USING (auth.uid() = user_id);
DROP POLICY IF EXISTS "Users can insert their own push tokens" ON push_tokens;
CREATE POLICY "Users can insert their own push tokens"
ON push_tokens
FOR INSERT
WITH CHECK (auth.uid() = user_id);
DROP POLICY IF EXISTS "Users can update their own push tokens" ON push_tokens;
CREATE POLICY "Users can update their own push tokens"
ON push_tokens
FOR UPDATE
USING (auth.uid() = user_id)
WITH CHECK (auth.uid() = user_id);
DROP POLICY IF EXISTS "Users can delete their own push tokens" ON push_tokens;
CREATE POLICY "Users can delete their own push tokens"
ON push_tokens
FOR DELETE
USING (auth.uid() = user_id);