master
1CREATE EXTENSION IF NOT EXISTS pgcrypto;
2CREATE SCHEMA sundown;
3
4CREATE TABLE sundown.user (
5 id text primary key,
6 password text not null, -- bcrypt
7 check (length(id) >= 3 and length(id) <= 32)
8);
9
10CREATE TABLE sundown.token (
11 token text primary key default gen_random_uuid(),
12 user_id text not null references sundown.user(id),
13 created_at timestamptz not null default now()
14);
15
16CREATE TABLE sundown.secret (
17 id text primary key default gen_random_uuid(),
18 owner_id text not null references sundown.user(id),
19 name text not null,
20 secret text not null,
21 reveal_at timestamptz not null,
22 created_at timestamptz not null default now()
23);
24
25CREATE FUNCTION ms_to_timestamp(ms float8) RETURNS timestamptz AS $$
26 SELECT to_timestamp(ms / 1000.0) AT TIME ZONE 'UTC';
27$$ STRICT IMMUTABLE LANGUAGE sql;
28
29CREATE FUNCTION timestamp_to_ms(ts timestamptz) RETURNS float8 AS $$
30 SELECT extract(epoch from ts) * 1000.0;
31$$ STRICT IMMUTABLE LANGUAGE sql;
32
33------------------------------------------------------------------------------
34
35INSERT INTO sundown.user (id, password) VALUES ('plaid', 'no-login');
36INSERT INTO sundown.secret(id, owner_id, name, secret, reveal_at) VALUES ('13371337-1337-1337-1337-133713371337', 'plaid', 'Flag', 'PCTF{test_flag}', '2026-04-10 21:00:00+00');