-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sql
More file actions
57 lines (49 loc) · 1.77 KB
/
setup.sql
File metadata and controls
57 lines (49 loc) · 1.77 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
-- Create snippets table
CREATE TABLE IF NOT EXISTS snippets (
id SERIAL PRIMARY KEY,
title VARCHAR(100) NOT NULL,
content TEXT NOT NULL,
created TIMESTAMP NOT NULL DEFAULT NOW(),
expires TIMESTAMP NOT NULL,
author_name VARCHAR(255) NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_snippets_created ON snippets(created);
-- Create users table
CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
hashed_password CHAR(60) NOT NULL,
created TIMESTAMP NOT NULL DEFAULT NOW()
);
ALTER TABLE users DROP CONSTRAINT IF EXISTS users_uc_email;
ALTER TABLE users ADD CONSTRAINT users_uc_email UNIQUE (email);
-- Create sessions table (for session management)
CREATE TABLE IF NOT EXISTS sessions (
token TEXT PRIMARY KEY,
data BYTEA NOT NULL,
expiry TIMESTAMPTZ NOT NULL
);
CREATE INDEX IF NOT EXISTS sessions_expiry_idx ON sessions (expiry);
-- Insert some sample data for testing (optional)
INSERT INTO snippets (title, content, created, expires, author_name) VALUES (
'An old silent pond',
E'An old silent pond...\nA frog jumps into the pond,\nsplash! Silence again.\n\n– Matsuo Bashō',
NOW(),
NOW() + INTERVAL '365 days',
'Anonymous'
);
INSERT INTO snippets (title, content, created, expires, author_name) VALUES (
'Over the wintry forest',
E'Over the wintry\nforest, winds howl in rage\nwith no leaves to blow.\n\n– Natsume Soseki',
NOW(),
NOW() + INTERVAL '365 days',
'Anonymous'
);
INSERT INTO snippets (title, content, created, expires, author_name) VALUES (
'First autumn morning',
E'First autumn morning\nthe mirror I stare into\nshows my father''s face.\n\n– Murakami Kijo',
NOW(),
NOW() + INTERVAL '7 days',
'Anonymous'
);