feat: create tables and seed data for mvp tables

This commit is contained in:
Yehoshua Sandler 2025-03-20 15:35:12 -05:00
parent b637762744
commit 77559d78d9
9 changed files with 417 additions and 56 deletions

View File

@ -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
);

View File

@ -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());

View File

@ -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'
);

View File

@ -2,12 +2,10 @@ package entities
import ( import (
"github.com/google/uuid" "github.com/google/uuid"
"gorm.io/gorm"
"time" "time"
) )
type Client struct { type Client struct {
gorm.Model
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"` ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"`
Name string Name string
Abbreviation string Abbreviation string

18
entities/EntryLog.go Normal file
View File

@ -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"`
}

View File

@ -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
}

View File

@ -2,12 +2,10 @@ package entities
import ( import (
"github.com/google/uuid" "github.com/google/uuid"
"gorm.io/gorm"
"time" "time"
) )
type Project struct { type Project struct {
gorm.Model
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"` ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"`
Name string Name string
Abbreviation string Abbreviation string

View File

@ -2,12 +2,10 @@ package entities
import ( import (
"github.com/google/uuid" "github.com/google/uuid"
"gorm.io/gorm"
"time" "time"
) )
type Task struct { type Task struct {
gorm.Model
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"` ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"`
ProjectId uuid.UUID ProjectId uuid.UUID
SprintId uuid.UUID SprintId uuid.UUID
@ -43,3 +41,12 @@ type TaskHistoryType struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"` ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"`
Label string 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"`
}

View File

@ -2,7 +2,6 @@ package entities
import ( import (
"github.com/google/uuid" "github.com/google/uuid"
"gorm.io/gorm"
"time" "time"
) )
@ -27,7 +26,6 @@ type ClientUser struct {
} }
type ClientUser_Project_Join struct { type ClientUser_Project_Join struct {
gorm.Model
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"` ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"`
ClientId uuid.UUID `gorm:"foreignKey:ClientId;index:clientIdProjectIndex" ` ClientId uuid.UUID `gorm:"foreignKey:ClientId;index:clientIdProjectIndex" `
ProjectId uuid.UUID `gorm:"foreignKey:ProjectId;index:projectIdClientIndex"` ProjectId uuid.UUID `gorm:"foreignKey:ProjectId;index:projectIdClientIndex"`
@ -38,9 +36,8 @@ type ClientUser_Project_Join struct {
} }
type DevUser_Project_Join struct { type DevUser_Project_Join struct {
gorm.Model
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"` 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"` ProjectId uuid.UUID `gorm:"foreignKey:ProjectId;index:projectIdDevIndex"`
CreatedAt time.Time `gorm:"default:now()"` CreatedAt time.Time `gorm:"default:now()"`
UpdatedAt time.Time `gorm:"default:now()"` UpdatedAt time.Time `gorm:"default:now()"`