so much
This commit is contained in:
1 parent
943408255c
commit
ffa5cd9cd7
38 files changed
+2938
-68
No files matched your search
@@ -0,0 +1,5 @@
|
||||
DROP TABLE IF EXISTS user_identities;
|
||||
|
||||
DROP TABLE IF EXISTS auth_provider;
|
||||
|
||||
DROP TABLE IF EXISTS users;
|
||||
@@ -0,0 +1,65 @@
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
email citext UNIQUE NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
alt_name TEXT,
|
||||
created TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
last_login TIMESTAMPTZ NOT NULL DEFAULT '1970-01-01 00:00:00+00',
|
||||
activated BOOL NOT NULL DEFAULT false,
|
||||
version INT NOT NULL DEFAULT 1
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS auth_provider (
|
||||
id BIGSERIAL PRIMARY KEY, -- e.g., 'local', 'id_austria',
|
||||
description TEXT NOT NULL,
|
||||
active BOOLEAN DEFAULT false
|
||||
);
|
||||
|
||||
INSERT INTO auth_provider (description, active) VALUES ('local', true);
|
||||
INSERT INTO auth_provider (description, active) VALUES ('id_austria', false);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS user_identities (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
provider_id BIGINT NOT NULL REFERENCES auth_provider(id),
|
||||
user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
|
||||
-- For local: the username. For OIDC: the 'sub' (Subject ID)
|
||||
provider_user_id TEXT NOT NULL,
|
||||
|
||||
-- Nullable because OIDC users won't have a password in your DB
|
||||
password bytea,
|
||||
|
||||
version INT NOT NULL DEFAULT 1,
|
||||
|
||||
UNIQUE(provider_id, provider_user_id)
|
||||
);
|
||||
|
||||
-- INSERT INTO users(
|
||||
-- username,
|
||||
-- email,
|
||||
-- password,
|
||||
-- name,
|
||||
-- alt_name
|
||||
-- )
|
||||
-- VALUES(
|
||||
-- 'vik',
|
||||
-- 'vikhenzo@gmail.com',
|
||||
-- '$argon2id$v=19$m=65536,t=1,p=32$+dQ9uB7kKL7t7G3bI+TOMw$Wvic27W6SYH6Fx2Pp84irhVJ/blVh5qINlkv58bpgEc',
|
||||
-- 'Vicente Ferrari Smith',
|
||||
-- 'Vicente'
|
||||
-- );
|
||||
|
||||
-- INSERT INTO users(
|
||||
-- username,
|
||||
-- email,
|
||||
-- password,
|
||||
-- name,
|
||||
-- alt_name
|
||||
-- )
|
||||
-- VALUES(
|
||||
-- 'mkBflwkpe',
|
||||
-- 'bellrebekaou@gmail.com',
|
||||
-- '$argon2id$v=19$m=65536,t=1,p=1$BWcWdp8bhgS84LWqUCb2IA$DGF/FzQbSNHnfZraE9F2qvfdBGf5XB81+w00QgY/jG0',
|
||||
-- 'zWkxKTNolTgJwO',
|
||||
-- 'OahedOBLSo'
|
||||
-- );
|
||||
@@ -0,0 +1,8 @@
|
||||
DROP INDEX IF EXISTS idx_votes_option_id;
|
||||
DROP INDEX IF EXISTS idx_vote_tokens_issue_id;
|
||||
DROP INDEX IF EXISTS idx_options_issue_id;
|
||||
|
||||
DROP TABLE IF EXISTS votes;
|
||||
DROP TABLE IF EXISTS vote_tokens;
|
||||
DROP TABLE IF EXISTS options;
|
||||
DROP TABLE IF EXISTS issues;
|
||||
@@ -0,0 +1,38 @@
|
||||
CREATE TABLE IF NOT EXISTS issues (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
description TEXT,
|
||||
start_time TIMESTAMPTZ NOT NULL,
|
||||
end_time TIMESTAMPTZ NOT NULL,
|
||||
created TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
version INT NOT NULL DEFAULT 1
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS options (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
issue_id BIGINT NOT NULL REFERENCES issues(id) ON DELETE CASCADE,
|
||||
label VARCHAR(255) NOT NULL,
|
||||
created TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
version INT NOT NULL DEFAULT 1
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS vote_tokens (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
issue_id BIGINT NOT NULL REFERENCES issues(id) ON DELETE CASCADE,
|
||||
token UUID NOT NULL UNIQUE DEFAULT gen_random_uuid(),
|
||||
used BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
version INT NOT NULL DEFAULT 1
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS votes (
|
||||
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
token UUID NOT NULL UNIQUE REFERENCES vote_tokens(token) ON DELETE CASCADE,
|
||||
option_id BIGINT NOT NULL REFERENCES options(id) ON DELETE CASCADE,
|
||||
created TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
version INT NOT NULL DEFAULT 1
|
||||
);
|
||||
|
||||
CREATE INDEX idx_votes_option_id ON votes(option_id);
|
||||
CREATE INDEX idx_vote_tokens_issue_id ON vote_tokens(issue_id);
|
||||
CREATE INDEX idx_options_issue_id ON options(issue_id);
|
||||
@@ -0,0 +1,3 @@
|
||||
DROP INDEX IF EXISTS issue_title_idx;
|
||||
|
||||
DROP INDEX IF EXISTS issue_description_idx;
|
||||
@@ -0,0 +1,3 @@
|
||||
CREATE INDEX IF NOT EXISTS issue_title_idx ON issues USING GIN (to_tsvector('simple', title));
|
||||
|
||||
CREATE INDEX IF NOT EXISTS issue_description_idx ON issues USING GIN (to_tsvector('simple', description));
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS tokens;
|
||||
@@ -0,0 +1,7 @@
|
||||
CREATE TABLE IF NOT EXISTS tokens (
|
||||
hash bytea PRIMARY KEY,
|
||||
user_id bigint NOT NULL REFERENCES users ON DELETE CASCADE,
|
||||
user_identity_id bigint REFERENCES user_identities ON DELETE CASCADE,
|
||||
expiry timestamp(0) with time zone NOT NULL,
|
||||
scope text NOT NULL
|
||||
);
|
||||
@@ -0,0 +1,2 @@
|
||||
DROP TABLE IF EXISTS users_permissions;
|
||||
DROP TABLE IF EXISTS permissions;
|
||||
@@ -0,0 +1,14 @@
|
||||
CREATE TABLE IF NOT EXISTS permissions (
|
||||
id bigserial PRIMARY KEY,
|
||||
code text NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS users_permissions (
|
||||
user_id bigint NOT NULL REFERENCES users ON DELETE CASCADE,
|
||||
permission_id bigint NOT NULL REFERENCES permissions ON DELETE CASCADE,
|
||||
PRIMARY KEY (user_id, permission_id)
|
||||
);
|
||||
|
||||
-- Add the two permissions to the table.
|
||||
INSERT INTO permissions (code)
|
||||
VALUES ('issues:read'), ('issues:write');
|
||||
Reference in new issue
Block a user