mirror of
https://github.com/kristoferssolo/Axium.git
synced 2026-02-04 05:22:02 +00:00
first commit
This commit is contained in:
19
migrations/20250128160043_create_roles_table.sql
Normal file
19
migrations/20250128160043_create_roles_table.sql
Normal 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
|
||||
21
migrations/20250128160119_create_users_table.sql
Normal file
21
migrations/20250128160119_create_users_table.sql
Normal 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
|
||||
6
migrations/20250128160204_create_todos_table.sql
Normal file
6
migrations/20250128160204_create_todos_table.sql
Normal 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
|
||||
);
|
||||
Reference in New Issue
Block a user