From 77559d78d96a948de9444ed157bba909d35b0b99 Mon Sep 17 00:00:00 2001 From: Yehoshua Sandler Date: Thu, 20 Mar 2025 15:35:12 -0500 Subject: [PATCH] feat: create tables and seed data for mvp tables --- .../scripts/01_create_tables.sql | 112 +++++++ .container_volume/scripts/01_users.sql | 27 -- .container_volume/scripts/02_seed_tables.sql | 277 ++++++++++++++++++ entities/Client.go | 2 - entities/EntryLog.go | 18 ++ entities/Log.go | 19 -- entities/Project.go | 2 - entities/Task.go | 11 +- entities/User.go | 5 +- 9 files changed, 417 insertions(+), 56 deletions(-) create mode 100644 .container_volume/scripts/01_create_tables.sql delete mode 100644 .container_volume/scripts/01_users.sql create mode 100644 .container_volume/scripts/02_seed_tables.sql create mode 100644 entities/EntryLog.go delete mode 100644 entities/Log.go diff --git a/.container_volume/scripts/01_create_tables.sql b/.container_volume/scripts/01_create_tables.sql new file mode 100644 index 0000000..dc7a6e4 --- /dev/null +++ b/.container_volume/scripts/01_create_tables.sql @@ -0,0 +1,112 @@ +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; + +DROP TABLE IF EXISTS dev_users; + +DROP TABLE IF EXISTS client_users; + +DROP TABLE IF EXISTS clients; + +DROP TABLE IF EXISTS projects; + +DROP TABLE IF EXISTS client_user_project_joins; + +DROP TABLE IF EXISTS dev_user_project_joins; + +DROP TABLE IF EXISTS statuses; + +DROP TABLE IF EXISTS tasks; + +DROP TABLE IF EXISTS entry_logs; + +CREATE TABLE IF NOT EXISTS dev_users ( + id UUID PRIMARY KEY DEFAULT (uuid_generate_v4()), + first_name character varying(255) NOT NULL, + last_name character varying(255) NOT NULL, + email character varying(255) UNIQUE NOT NULL, + phone_number character varying(255), + created_at timestamp WITH time zone DEFAULT NOW(), + updated_at timestamp WITH time zone DEFAULT NOW() +); + +CREATE TABLE IF NOT EXISTS clients ( + id UUID PRIMARY KEY DEFAULT (uuid_generate_v4()), + name character varying(255) NOT NULL, + abbreviation character varying(255), + website character varying(255), + phone_number character varying(255), + created_at timestamp WITH time zone DEFAULT NOW() NOT NULL, + updated_at timestamp WITH time zone DEFAULT NOW() NOT NULL +); + +CREATE TABLE IF NOT EXISTS client_users ( + id UUID PRIMARY KEY DEFAULT (uuid_generate_v4()), + first_name character varying(255) NOT NULL, + last_name character varying(255) NOT NULL, + email character varying(255) UNIQUE NOT NULL, + phone_number character varying(255), + created_at timestamp WITH time zone DEFAULT NOW(), + updated_at timestamp WITH time zone DEFAULT NOW(), + client_id UUID REFERENCES clients(id), + role_in_company character varying(255) NOT NULL +); + +CREATE TABLE IF NOT EXISTS projects ( + id UUID PRIMARY KEY DEFAULT (uuid_generate_v4()), + name character varying(255) entry_logsNOT NULL, + abbreviation character varying(255), + description TEXT, + created_at timestamp WITH time zone DEFAULT NOW(), + updated_at timestamp WITH time zone DEFAULT NOW(), + client_id UUID REFERENCES clients(id) +); + +CREATE TABLE IF NOT EXISTS client_user_project_joins ( + id UUID PRIMARY KEY DEFAULT (uuid_generate_v4()), + client_id UUID NOT NULL REFERENCES clients(id), + project_id UUID NOT NULL REFERENCES projects(id), + created_at timestamp WITH time zone DEFAULT NOW(), + updated_at timestamp WITH time zone DEFAULT NOW(), + is_stakeholder BOOLEAN DEFAULT FALSE, + notes TEXT +); + +CREATE TABLE IF NOT EXISTS dev_user_project_joins ( + id UUID PRIMARY KEY DEFAULT (uuid_generate_v4()), + dev_user_id UUID NOT NULL REFERENCES dev_users(id), + project_id UUID NOT NULL REFentry_logsERENCES projects(id), + created_at timestamp WITH time zone DEFAULT NOW(), + updated_at timestamp WITH time zone DEFAULT NOW(), + is_lead BOOLEAN DEFAULT FALSE, + notes TEXT +); + +CREATE TABLE IF NOT EXISTS statuses ( + id UUID PRIMARY KEY DEFAULT (uuid_generate_v4()), + name character varying(255) NOT NULL, + description TEXT, + created_at timestamp WITH time zone DEFAULT NOW(), + updated_at timestamp WITH time zone DEFAULT NOW(), + deleted_at timestamp WITH time zone +); + +CREATE TABLE IF NOT EXISTS tasks ( + id UUID PRIMARY KEY DEFAULT (uuid_generate_v4()), + project_id UUID NOT NULL REFERENCES projects(id), + status_id UUID NOT NULL REFERENCES statuses(id), + created_at timestamp WITH time zone DEFAULT NOW(), + updated_at timestamp WITH time zone DEFAULT NOW(), + expected_delivery_date timestamp WITH time zone, + final_delivery_date timestamp WITH time zone, + description TEXT +); + +CREATE TABLE IF NOT EXISTS entry_logs ( + id UUID PRIMARY KEY DEFAULT (uuid_generate_v4()), + project_id UUID NOT NULL REFERENCES projects(id), + task_id UUID NOT NULL REFERENCES tasks(id), + created_at timestamp WITH time zone DEFAULT NOW(), + updated_at timestamp WITH time zone DEFAULT NOW(), + start_time timestamp WITH time zone, + end_time timestamp WITH time zone, + description TEXT +); diff --git a/.container_volume/scripts/01_users.sql b/.container_volume/scripts/01_users.sql deleted file mode 100644 index 24e3470..0000000 --- a/.container_volume/scripts/01_users.sql +++ /dev/null @@ -1,27 +0,0 @@ -CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; - -DROP TABLE dev_users - -CREATE TABLE IF NOT EXISTS dev_users ( - id UUID PRIMARY KEY DEFAULT (uuid_generate_v4()), - first_name character varying(255) NOT NULL, - last_name character varying(255) NOT NULL, - email character varying(255) UNIQUE NOT NULL, - phone_number character varying(255), - created_at timestamp with time zone DEFAULT now(), - updated_at timestamp with time zone DEFAULT now() -); - --- Seed Data -INSERT INTO dev_users (first_name, last_name, email, phone_number, created_at, updated_at) -VALUES -('John', 'Doe', 'john.doe@example.com', '(555) 123-4567', now(), now()), -('Jane', 'Smith', 'jane.smith@example.com', '(555) 123-4568', now(), now()), -('Bob', 'Johnson', 'bob.johnson@example.com', '(555) 123-4569', now(), now()), -('Alice', 'Brown', 'alice.brown@example.com', '(555) 123-4570', now(), now()), -('Charlie', 'Wilson', 'charlie.wilson@example.com', '(555) 123-4571', now(), now()), -('Eva', 'Davis', 'eva.davis@example.com', '(555) 123-4572', now(), now()), -('Frank', 'Miller', 'frank.miller@example.com', '(555) 123-4573', now(), now()), -('Grace', 'Taylor', 'grace.taylor@example.com', '(555) 123-4574', now(), now()), -('Henry', 'Anderson', 'henry.anderson@example.com', '(555) 123-4575', now(), now()), -('Isabella', 'King', 'isabella.king@example.com', '(555) 123-4576', now(), now()); diff --git a/.container_volume/scripts/02_seed_tables.sql b/.container_volume/scripts/02_seed_tables.sql new file mode 100644 index 0000000..2206aeb --- /dev/null +++ b/.container_volume/scripts/02_seed_tables.sql @@ -0,0 +1,277 @@ +INSERT INTO + dev_users ( + first_name, + last_name, + email, + phone_number, + created_at, + updated_at + ) +VALUES + ( + 'John', + 'Doe', + 'john.doe@example.com', + '(555) 123-4567', + NOW(), + NOW() + ), + ( + 'Jane', + 'Smith', + 'jane.smith@example.com', + '(555) 123-4568', + NOW(), + NOW() + ), + ( + 'Isabella', + 'King', + 'isabella.king@example.com', + '(555) 123-4576', + NOW(), + NOW() + ); + +INSERT INTO + clients(name, abbreviation, website) +VALUES + ('Tech Corp', 'TC', 'techcorp.com'), + ('Health Care Inc', 'HCI', 'healthcareinc.com'); + +INSERT INTO + client_users( + first_name, + last_name, + email, + phone_number, + role_in_company, + client_id + ) +VALUES + ( + 'John', + 'Doe', + 'john.doe@techcorp.com', + '+1 555-0101', + 'Developer', + ( + SELECT + id + FROM + clients + WHERE + name = 'Tech Corp' + ) + ), + ( + 'Jane', + 'Smith', + 'jane.smith@healthcareinc.com', + '+1 555-0202', + 'Project Manager', + ( + SELECT + id + FROM + clients + WHERE + name = 'Health Care Inc' + ) + ); + +INSERT INTO + projects(name, abbreviation, description, client_id) +VALUES + ( + 'Web Platform', + 'WP', + 'Core web application platform', + ( + SELECT + id + FROM + clients + WHERE + name = 'Tech Corp' + ) + ), + ( + 'Mobile App', + 'MA', + 'Mobile frontend application', + ( + SELECT + id + FROM + clients + WHERE + name = 'Tech Corp' + ) + ), + ( + 'EHR System', + 'EHR', + 'Electronic Health Records system', + ( + SELECT + id + FROM + clients + WHERE + name = 'Health Care Inc' + ) + ); + +INSERT INTO + statuses(name) +VALUES + ('In Progress'), + ('Completed'); + +INSERT INTO + tasks(project_id, status_id, description) +VALUES + ( + ( + SELECT + id + FROM + projects + WHERE + name = 'Web Platform' + ), + ( + SELECT + id + FROM + statuses + WHERE + name = 'In Progress' + ), + 'Backend API Development' + ), + ( + ( + SELECT + id + FROM + projects + WHERE + name = 'Mobile App' + ), + ( + SELECT + id + FROM + statuses + WHERE + name = 'Completed' + ), + 'iOS Implementation' + ); + +INSERT INTO + client_user_project_joins(client_id, project_id, is_stakeholder) +VALUES + ( + ( + SELECT + id + FROM + clients + WHERE + name = 'Tech Corp' + ), + ( + SELECT + id + FROM + projects + WHERE + name = 'Web Platform' + ), + FALSE + ), + ( + ( + SELECT + id + FROM + clients + WHERE + name = 'Tech Corp' + ), + ( + SELECT + id + FROM + projects + WHERE + name = 'Mobile App' + ), + TRUE + ), + ( + ( + SELECT + id + FROM + clients + WHERE + name = 'Health Care Inc' + ), + ( + SELECT + id + FROM + projects + WHERE + name = 'EHR System' + ), + TRUE + ); + +INSERT INTO + dev_user_project_joins(dev_user_id, project_id, is_lead, notes) +VALUES + ( + ( + SELECT + id + FROM + dev_users + WHERE + email = 'john.doe@example.com' + ), + ( + SELECT + id + FROM + projects + WHERE + name = 'Web Platform' + ), + TRUE, + 'Lead Developer' + ), + ( + ( + SELECT + id + FROM + dev_users + WHERE + email = 'jane.smith@example.com' + ), + ( + SELECT + id + FROM + projects + WHERE + name = 'Mobile App' + ), + TRUE, + 'Lead Developer' + ); diff --git a/entities/Client.go b/entities/Client.go index 6bd8e0e..0db263c 100644 --- a/entities/Client.go +++ b/entities/Client.go @@ -2,12 +2,10 @@ package entities import ( "github.com/google/uuid" - "gorm.io/gorm" "time" ) type Client struct { - gorm.Model ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"` Name string Abbreviation string diff --git a/entities/EntryLog.go b/entities/EntryLog.go new file mode 100644 index 0000000..e2df896 --- /dev/null +++ b/entities/EntryLog.go @@ -0,0 +1,18 @@ +package entities + +import ( + "github.com/google/uuid" + "time" +) + +type EntryLog struct { + ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"` + ProjectId uuid.UUID `gorm:"index"` + TaskId uuid.UUID `gorm:"index"` + CreatedAt time.Time `gorm:"auto_now:Add"` + UpdatedAt time.Time `gorm:"auto_now:update"` + StartTime time.Time `gorm:"default:null"` + EndTime time.Time `gorm:"default:null"` + Description string `gorm:",omitempty" json:",omitempty"` + DeletedAt *time.Time `gorm:"default:null"` +} diff --git a/entities/Log.go b/entities/Log.go deleted file mode 100644 index 7c95131..0000000 --- a/entities/Log.go +++ /dev/null @@ -1,19 +0,0 @@ -package entities - -import ( - "github.com/google/uuid" - "gorm.io/gorm" - "time" -) - -type Log struct { - gorm.Model - ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"` - ProjectId uuid.UUID - TaskId uuid.UUID - CreatedAt time.Time - UpdatedAt time.Time - StartTime time.Time - EndTime time.Time - Description string -} diff --git a/entities/Project.go b/entities/Project.go index fd3afd1..7a32ced 100644 --- a/entities/Project.go +++ b/entities/Project.go @@ -2,12 +2,10 @@ package entities import ( "github.com/google/uuid" - "gorm.io/gorm" "time" ) type Project struct { - gorm.Model ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"` Name string Abbreviation string diff --git a/entities/Task.go b/entities/Task.go index 3076921..c978c95 100644 --- a/entities/Task.go +++ b/entities/Task.go @@ -2,12 +2,10 @@ package entities import ( "github.com/google/uuid" - "gorm.io/gorm" "time" ) type Task struct { - gorm.Model ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"` ProjectId uuid.UUID SprintId uuid.UUID @@ -43,3 +41,12 @@ type TaskHistoryType struct { ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"` Label string } + +type Status struct { + ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"` + Name string `gorm:"size:255"` + Description string `gorm:"type:text"` + CreatedAt time.Time `gorm:"default:now()"` + UpdatedAt time.Time `gorm:"default:now()"` + DeletedAt *time.Time `gorm:"default:null"` +} diff --git a/entities/User.go b/entities/User.go index 8fd9fbe..6054103 100644 --- a/entities/User.go +++ b/entities/User.go @@ -2,7 +2,6 @@ package entities import ( "github.com/google/uuid" - "gorm.io/gorm" "time" ) @@ -27,7 +26,6 @@ type ClientUser struct { } type ClientUser_Project_Join struct { - gorm.Model ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"` ClientId uuid.UUID `gorm:"foreignKey:ClientId;index:clientIdProjectIndex" ` ProjectId uuid.UUID `gorm:"foreignKey:ProjectId;index:projectIdClientIndex"` @@ -38,9 +36,8 @@ type ClientUser_Project_Join struct { } type DevUser_Project_Join struct { - gorm.Model ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"` - ClientId uuid.UUID `gorm:"foreignKey:ClientId;index:clientIdDevIndex" ` + DevUserId uuid.UUID `gorm:"foreignKey:ClientId;index:devUserIdDevIndex" ` ProjectId uuid.UUID `gorm:"foreignKey:ProjectId;index:projectIdDevIndex"` CreatedAt time.Time `gorm:"default:now()"` UpdatedAt time.Time `gorm:"default:now()"`