Skip to content
This repository was archived by the owner on Jul 14, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions docs/software/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,44 @@
```sql
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

CREATE TABLE IF NOT EXISTS "User" (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
phone_number VARCHAR(20),
age SMALLINT
);

CREATE TABLE IF NOT EXISTS "Role" (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name VARCHAR(255) NOT NULL,
description TEXT
);

CREATE TABLE IF NOT EXISTS "Permission" (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name VARCHAR(255) NOT NULL,
description TEXT
);

CREATE TABLE IF NOT EXISTS user_roles (
user_id UUID NOT NULL,
role_id UUID NOT NULL,
PRIMARY KEY (user_id, role_id),
FOREIGN KEY (user_id) REFERENCES "User"(id) ON DELETE CASCADE,
FOREIGN KEY (role_id) REFERENCES "Role"(id) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS role_permissions (
role_id UUID NOT NULL,
permission_id UUID NOT NULL,
PRIMARY KEY (role_id, permission_id),
FOREIGN KEY (role_id) REFERENCES "Role"(id) ON DELETE CASCADE,
FOREIGN KEY (permission_id) REFERENCES "Permission"(id) ON DELETE CASCADE
);

CREATE TABLE Quiz (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
title VARCHAR(255) NOT NULL,
Expand Down Expand Up @@ -59,6 +97,36 @@ CREATE TABLE IF NOT EXISTS "Feedback" (
CREATE INDEX IF NOT EXISTS idx_feedback_user ON "Feedback" (user_id);
CREATE INDEX IF NOT EXISTS idx_feedback_survey ON "Feedback" (survey_id);

INSERT INTO "Role" (name, description)
VALUES
('Admin', 'Administrator role with full access'),
('Editor', 'Editor role with content editing permissions'),
('Viewer', 'Viewer role with read-only access');

INSERT INTO "Permission" (name, description)
VALUES
('Manage Users', 'Permission to manage users'),
('Edit Content', 'Permission to edit content'),
('View Content', 'Permission to view content');

INSERT INTO "User" (first_name, last_name, email, password, phone_number, age)
VALUES
('Alice', 'Smith', 'alice@example.com', 'hashedpassword1', '+123456789', 30),
('Bob', 'Johnson', 'bob@example.com', 'hashedpassword2', '+987654321', 25),
('Charlie', 'Brown', 'charlie@example.com', 'hashedpassword3', '+192837465', 35);

INSERT INTO user_roles (user_id, role_id)
VALUES
((SELECT id FROM "User" WHERE email = 'alice@example.com'), (SELECT id FROM "Role" WHERE name = 'Admin')),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very smart! I didn't know about this feature. 👏

((SELECT id FROM "User" WHERE email = 'bob@example.com'), (SELECT id FROM "Role" WHERE name = 'Editor')),
((SELECT id FROM "User" WHERE email = 'charlie@example.com'), (SELECT id FROM "Role" WHERE name = 'Viewer'));

INSERT INTO role_permissions (role_id, permission_id)
VALUES
((SELECT id FROM "Role" WHERE name = 'Admin'), (SELECT id FROM "Permission" WHERE name = 'Manage Users')),
((SELECT id FROM "Role" WHERE name = 'Editor'), (SELECT id FROM "Permission" WHERE name = 'Edit Content')),
((SELECT id FROM "Role" WHERE name = 'Viewer'), (SELECT id FROM "Permission" WHERE name = 'View Content'));

INSERT INTO Quiz (title, description, creation_date, close_date, is_active, owner_id)
VALUES
('Customer Satisfaction Quiz', 'Quiz about customer satisfaction', '2025-04-20 10:00:00', '2025-04-30 23:59:59', TRUE, 'e7b3f5b4-8a63-4e2e-baad-5a8c5c5b1234'),
Expand Down
Loading