Skip to content

Commit 7bf2461

Browse files
committed
Integrated v1 schema to this
1 parent 48beeff commit 7bf2461

2 files changed

Lines changed: 116 additions & 31 deletions

File tree

db/schema_create.sql

Lines changed: 99 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,100 @@
1+
-- #############################################################################
2+
-- ### UNIFIED DATABASE SCHEMA (CREATE STATEMENTS) ###
3+
-- #############################################################################
4+
-- This file contains the complete and authoritative CREATE statements for the
5+
-- entire application, merging 'auth_microservice' and 'controller_microservice_v2'.
6+
--
7+
-- Conventions:
8+
-- - 'users' table columns follow 'auth_microservice' conventions for compatibility.
9+
-- - Other tables use snake_case.
10+
-- #############################################################################
11+
12+
13+
-- =============================================================================
14+
-- CORE TABLES (SHARED)
15+
-- =============================================================================
16+
17+
-- Merged from both services, represents the authoritative user model.
18+
-- Column names like 'userName', 'fullName', 'accountStatus' retained for
19+
-- backward compatibility with 'auth_microservice'.
120
CREATE TABLE IF NOT EXISTS users (
2-
id UUID PRIMARY KEY,
3-
username TEXT NOT NULL,
4-
email TEXT NOT NULL,
5-
password TEXT NOT NULL,
6-
role TEXT NOT NULL,
7-
acc_status TEXT NOT NULL
21+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
22+
userName TEXT UNIQUE NOT NULL,
23+
fullName TEXT,
24+
email TEXT UNIQUE NOT NULL,
25+
password TEXT NOT NULL,
26+
role TEXT DEFAULT 'user',
27+
accountStatus TEXT DEFAULT 'active',
28+
createdAt TIMESTAMPTZ DEFAULT now() NOT NULL,
29+
updatedAt TIMESTAMPTZ DEFAULT now() NOT NULL
830
);
931

1032

33+
-- =============================================================================
34+
-- AUTH MICROSERVICE & V1 TABLES
35+
-- =============================================================================
36+
37+
CREATE TABLE IF NOT EXISTS registerOtp (
38+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
39+
email TEXT UNIQUE NOT NULL,
40+
otp TEXT NOT NULL,
41+
createdAt TIMESTAMPTZ DEFAULT now() NOT NULL,
42+
updatedAt TIMESTAMPTZ DEFAULT now() NOT NULL
43+
);
44+
45+
CREATE TABLE IF NOT EXISTS run (
46+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
47+
name TEXT NOT NULL,
48+
description TEXT,
49+
status TEXT DEFAULT 'scheduled', -- 'scheduled', 'running', 'completed', 'failed'
50+
type TEXT NOT NULL, -- 'ea', 'gp', 'ml', 'pso'
51+
command TEXT NOT NULL,
52+
createdBy UUID REFERENCES users(id),
53+
createdAt TIMESTAMPTZ DEFAULT now() NOT NULL,
54+
updatedAt TIMESTAMPTZ DEFAULT now() NOT NULL
55+
);
56+
57+
CREATE TABLE IF NOT EXISTS access (
58+
runID UUID REFERENCES run(id),
59+
userID UUID REFERENCES users(id),
60+
mode TEXT DEFAULT 'read', -- 'read', 'write'
61+
PRIMARY KEY (runID, userID),
62+
createdAt TIMESTAMPTZ DEFAULT now() NOT NULL,
63+
updatedAt TIMESTAMPTZ DEFAULT now() NOT NULL
64+
);
65+
66+
CREATE TABLE IF NOT EXISTS team (
67+
teamID UUID PRIMARY KEY DEFAULT gen_random_uuid(),
68+
teamName TEXT UNIQUE NOT NULL,
69+
teamDesc TEXT,
70+
createdBy TEXT NOT NULL,
71+
createdAt TIMESTAMPTZ DEFAULT now() NOT NULL,
72+
updatedAt TIMESTAMPTZ DEFAULT now() NOT NULL
73+
);
74+
75+
CREATE TABLE IF NOT EXISTS teamMembers (
76+
memberId UUID REFERENCES users(id),
77+
teamID UUID REFERENCES team(teamID),
78+
role TEXT,
79+
PRIMARY KEY (memberId, teamID),
80+
createdAt TIMESTAMPTZ DEFAULT now() NOT NULL,
81+
updatedAt TIMESTAMPTZ DEFAULT now() NOT NULL
82+
);
83+
84+
CREATE TABLE IF NOT EXISTS password_reset_otps (
85+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
86+
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
87+
otp_code TEXT NOT NULL,
88+
created_at TIMESTAMPTZ DEFAULT now() NOT NULL,
89+
expires_at TIMESTAMPTZ NOT NULL,
90+
is_used BOOLEAN DEFAULT FALSE
91+
);
92+
93+
94+
-- =============================================================================
95+
-- CONTROLLER MICROSERVICE V2 TABLES
96+
-- =============================================================================
97+
1198
CREATE TABLE IF NOT EXISTS problem_statements (
1299
id UUID PRIMARY KEY,
13100
title TEXT NOT NULL,
@@ -68,22 +155,13 @@ CREATE TABLE cell_variations (
68155
code TEXT NOT NULL,
69156
metric FLOAT NOT NULL,
70157
is_best BOOLEAN NOT NULL,
71-
generation INT NOT NULL
158+
generation INT NOT NULL,
159+
parent_variant_id UUID REFERENCES cell_variations(id) ON DELETE SET NULL
72160
);
73161

74-
ALTER TABLE cell_variations
75-
ADD COLUMN parent_variant_id UUID REFERENCES cell_variations(id) ON DELETE SET NULL;
76162

163+
-- =============================================================================
164+
-- INDEXES
165+
-- =============================================================================
77166

78-
-- Remove this in productions, just a dummy data for testing before integrating the auth service
79-
80-
INSERT INTO users (
81-
id, username, email, password, role, acc_status
82-
) VALUES (
83-
'123e4567-e89b-12d3-a456-426614174000',
84-
'Tharun Kumarr A',
85-
'tharunkumarra@gmail.com',
86-
'HelloThere',
87-
'Student',
88-
'valid'
89-
);
167+
CREATE INDEX IF NOT EXISTS idx_password_reset_user_id ON password_reset_otps(user_id);

db/schema_drop.sql

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
-- Drop child tables first
2-
DROP TABLE IF EXISTS cell_outputs CASCADE;
3-
DROP TABLE IF EXISTS evolution_runs CASCADE;
4-
DROP TABLE IF EXISTS cell_variations CASCADE;
5-
DROP TABLE IF EXISTS cells CASCADE;
6-
DROP TABLE IF EXISTS sessions CASCADE;
7-
DROP TABLE IF EXISTS notebooks CASCADE;
1+
-- This file contains all DROP statements for the unified schema.
2+
-- It is executed first to ensure a clean slate before creating tables.
3+
-- The order respects foreign key constraints.
84

9-
-- Finally, drop parent table
10-
DROP TABLE IF EXISTS problem_statements CASCADE;
11-
DROP TABLE IF EXISTS users CASCADE;
5+
DROP TABLE IF EXISTS cell_variations;
6+
DROP TABLE IF EXISTS cell_outputs;
7+
DROP TABLE IF EXISTS evolution_runs;
8+
DROP TABLE IF EXISTS cells;
9+
DROP TABLE IF EXISTS sessions;
10+
DROP TABLE IF EXISTS notebooks;
11+
DROP TABLE IF EXISTS problem_statements;
12+
DROP TABLE IF EXISTS password_reset_otps;
13+
DROP TABLE IF EXISTS teamMembers;
14+
DROP TABLE IF EXISTS access;
15+
DROP TABLE IF EXISTS run;
16+
DROP TABLE IF EXISTS registerOtp;
17+
DROP TABLE IF EXISTS team;
18+
DROP TABLE IF EXISTS users;

0 commit comments

Comments
 (0)