-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
84 lines (75 loc) · 2.8 KB
/
schema.sql
File metadata and controls
84 lines (75 loc) · 2.8 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
-- BetterAuth core schema for Supabase
-- Run this in your Supabase SQL Editor
-- User table
CREATE TABLE IF NOT EXISTS "user" (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
email TEXT NOT NULL UNIQUE,
"emailVerified" BOOLEAN NOT NULL DEFAULT FALSE,
image TEXT,
role TEXT DEFAULT 'user',
"createdAt" TIMESTAMP NOT NULL DEFAULT NOW(),
"updatedAt" TIMESTAMP NOT NULL DEFAULT NOW()
);
-- Session table
CREATE TABLE IF NOT EXISTS "session" (
id TEXT PRIMARY KEY,
"userId" TEXT NOT NULL REFERENCES "user"(id) ON DELETE CASCADE,
token TEXT NOT NULL UNIQUE,
"expiresAt" TIMESTAMP NOT NULL,
"ipAddress" TEXT,
"userAgent" TEXT,
"createdAt" TIMESTAMP NOT NULL DEFAULT NOW(),
"updatedAt" TIMESTAMP NOT NULL DEFAULT NOW()
);
-- Account table
CREATE TABLE IF NOT EXISTS "account" (
id TEXT PRIMARY KEY,
"userId" TEXT NOT NULL REFERENCES "user"(id) ON DELETE CASCADE,
"accountId" TEXT NOT NULL,
"providerId" TEXT NOT NULL,
"accessToken" TEXT,
"refreshToken" TEXT,
"accessTokenExpiresAt" TIMESTAMP,
"refreshTokenExpiresAt" TIMESTAMP,
scope TEXT,
"idToken" TEXT,
password TEXT,
"createdAt" TIMESTAMP NOT NULL DEFAULT NOW(),
"updatedAt" TIMESTAMP NOT NULL DEFAULT NOW()
);
-- Verification table (used by email OTP plugin)
CREATE TABLE IF NOT EXISTS "verification" (
id TEXT PRIMARY KEY,
identifier TEXT NOT NULL,
value TEXT NOT NULL,
"expiresAt" TIMESTAMP NOT NULL,
"createdAt" TIMESTAMP NOT NULL DEFAULT NOW(),
"updatedAt" TIMESTAMP NOT NULL DEFAULT NOW()
);
-- Indexes for performance
CREATE INDEX IF NOT EXISTS "session_userId_idx" ON "session"("userId");
CREATE INDEX IF NOT EXISTS "account_userId_idx" ON "account"("userId");
CREATE INDEX IF NOT EXISTS "verification_identifier_idx" ON "verification"(identifier);
-- Per-overlay narration tracks (supports multiple voices per page)
-- Requires existing "pages" table from application schema.
CREATE TABLE IF NOT EXISTS page_overlay_narrations (
id BIGSERIAL PRIMARY KEY,
page_id BIGINT NOT NULL REFERENCES pages(id) ON DELETE CASCADE,
overlay_element_id VARCHAR(255) NOT NULL,
voice_id VARCHAR(255) NOT NULL,
voice_name VARCHAR(255),
text_content TEXT NOT NULL,
audio_url VARCHAR(500) NOT NULL,
word_timestamps JSONB,
word_pronunciations JSONB,
sort_order INT NOT NULL DEFAULT 0,
inserted_at TIMESTAMP(0) NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP(0) NOT NULL DEFAULT NOW()
);
CREATE UNIQUE INDEX IF NOT EXISTS page_overlay_narrations_page_element_voice_idx
ON page_overlay_narrations(page_id, overlay_element_id, voice_id);
CREATE INDEX IF NOT EXISTS page_overlay_narrations_page_id_idx
ON page_overlay_narrations(page_id);
CREATE INDEX IF NOT EXISTS page_overlay_narrations_voice_id_idx
ON page_overlay_narrations(voice_id);