first commit

This commit is contained in:
Rik Heijmann
2025-01-30 22:43:30 +01:00
commit e20f21bc8b
33 changed files with 1667 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
-- Create the roles table
CREATE TABLE IF NOT EXISTS roles (
id SERIAL PRIMARY KEY,
level INT NOT NULL,
role VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL,
description VARCHAR(255),
CONSTRAINT unique_role UNIQUE (role) -- Add a unique constraint to the 'role' column
);
-- Insert a role into the roles table (this assumes role_id=1 is for 'user')
INSERT INTO roles (level, role, name, description)
VALUES (1, 'user', 'User', 'A regular user with basic access.')
ON CONFLICT (role) DO NOTHING; -- Prevent duplicate insertions if role already exists
-- Insert a role into the roles table (this assumes role_id=2 is for 'admin')
INSERT INTO roles (level, role, name, description)
VALUES (2, 'admin', 'Administrator', 'An administrator.')
ON CONFLICT (role) DO NOTHING; -- Prevent duplicate insertions if role already exists

View File

@@ -0,0 +1,21 @@
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(255) NOT NULL UNIQUE,
email VARCHAR(255) NOT NULL UNIQUE,
password_hash VARCHAR(255) NOT NULL,
totp_secret VARCHAR(255),
role_id INT NOT NULL DEFAULT 1 REFERENCES roles(id), -- Default role_id is set to 1
CONSTRAINT unique_username UNIQUE (username) -- Ensure that username is unique
);
-- Insert the example 'user' into the users table with a conflict check for username
INSERT INTO users (username, email, password_hash, role_id)
VALUES
('user', 'user@test.com', '$argon2i$v=19$m=16,t=2,p=1$ZE1qUWd0U21vUUlIM0ltaQ$dowBmjU4oHtoPd355dXypQ', 1)
ON CONFLICT (username) DO NOTHING; -- Prevent duplicate insertions if username already exists
-- Insert the example 'admin' into the users table with a conflict check for username
INSERT INTO users (username, email, password_hash, role_id)
VALUES
('admin', 'admin@test.com', '$argon2i$v=19$m=16,t=2,p=1$ZE1qUWd0U21vUUlIM0ltaQ$dowBmjU4oHtoPd355dXypQ', 2)
ON CONFLICT (username) DO NOTHING; -- Prevent duplicate insertions if username already exists

View File

@@ -0,0 +1,6 @@
CREATE TABLE todos (
id SERIAL PRIMARY KEY, -- Auto-incrementing primary key
task TEXT NOT NULL, -- Task description, cannot be null
description TEXT, -- Optional detailed description
user_id INT NOT NULL REFERENCES users(id) -- Foreign key to link to users table
);