Spaces:
Sleeping
Sleeping
File size: 13,030 Bytes
9a951d7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | -- =============================================================
-- MODULE: Onboarding
-- File: docs/schema-onboarding.sql
-- Managed by: TypeORM (synchronize: true in development)
-- =============================================================
-- -----------------------------------------------------------
-- ENUMS
-- -----------------------------------------------------------
-- Defined in: src/common/enums/user-enums.ts
CREATE TYPE user_goal_type_enum AS ENUM (
'university_search',
'course_recommendation',
'job_matching',
'career_guidance',
'skill_development',
'resume_improvement',
'interview_preparation',
'networking',
'salary_negotiation',
'career_transition'
);
CREATE TYPE experience_level_enum AS ENUM (
'student',
'recent_graduate',
'entry_level', -- 0-2 years
'mid_level', -- 3-5 years
'senior', -- 6-10 years
'lead', -- 10+ years
'executive'
);
CREATE TYPE education_level_enum AS ENUM (
'high_school',
'associate',
'bachelors',
'masters',
'phd',
'professional_cert',
'bootcamp'
);
CREATE TYPE industry_type_enum AS ENUM (
'technology',
'finance',
'healthcare',
'education',
'marketing',
'engineering',
'design',
'sales',
'consulting',
'manufacturing',
'retail',
'hospitality',
'legal',
'media',
'real_estate',
'other'
);
CREATE TYPE career_stage_enum AS ENUM (
'exploring', -- Exploring options
'transitioning', -- Changing careers
'advancing', -- Moving up in current field
'pivoting', -- Shifting within industry
'returning' -- Returning to workforce
);
CREATE TYPE personality_trait_category_enum AS ENUM (
'work_style',
'communication',
'problem_solving',
'leadership',
'learning',
'motivation'
);
CREATE TYPE data_source_type_enum AS ENUM (
'onboarding_quiz',
'personality_quiz',
'resume_analysis',
'search_behavior',
'user_input',
'system_inference'
);
-- -----------------------------------------------------------
-- TABLE: user_profiles
-- Entity: src/modules/users/entities/user-profile.entity.ts
-- Description: Career profile built during onboarding.
-- One-to-one with user. Powers LLM context.
-- -----------------------------------------------------------
CREATE TABLE user_profiles (
-- Primary key
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
-- Foreign key
user_id UUID NOT NULL UNIQUE
REFERENCES "user"(id) ON DELETE CASCADE,
-- Professional background
experience_level experience_level_enum,
years_of_experience INTEGER,
education_level education_level_enum,
current_role VARCHAR(200),
target_role VARCHAR(200),
current_industry industry_type_enum,
target_industry industry_type_enum,
career_stage career_stage_enum,
-- Location preferences
location VARCHAR(100),
target_location VARCHAR(100),
willing_to_relocate BOOLEAN NOT NULL DEFAULT FALSE,
open_to_remote BOOLEAN NOT NULL DEFAULT FALSE,
-- Skills & interests (free-form arrays)
skills JSONB, -- e.g. ["JavaScript","React","Node.js"]
interests JSONB, -- e.g. ["open-source","AI/ML"]
-- Bio
bio TEXT,
-- Completeness tracking (0β100)
profile_completeness INTEGER NOT NULL DEFAULT 0,
-- Timestamps
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);
-- Indexes
CREATE INDEX idx_user_profiles_user_id ON user_profiles (user_id);
CREATE INDEX idx_user_profiles_career_stage ON user_profiles (career_stage);
CREATE INDEX idx_user_profiles_experience ON user_profiles (experience_level);
-- -----------------------------------------------------------
-- TABLE: user_goals
-- Entity: src/modules/users/entities/user-goal.entity.ts
-- Description: One or more goals per user, ranked by priority.
-- Used to personalize LLM prompts.
-- -----------------------------------------------------------
CREATE TABLE user_goals (
-- Primary key
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
-- Foreign key
user_id UUID NOT NULL
REFERENCES "user"(id) ON DELETE CASCADE,
-- Goal details
goal_type user_goal_type_enum NOT NULL,
priority INTEGER NOT NULL DEFAULT 5, -- 1 (highest) to 5 (lowest)
is_active BOOLEAN NOT NULL DEFAULT TRUE,
source data_source_type_enum NOT NULL DEFAULT 'onboarding_quiz',
-- Timestamps
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);
-- Indexes
CREATE INDEX idx_user_goals_user_id ON user_goals (user_id);
CREATE INDEX idx_user_goals_priority ON user_goals (user_id, priority);
-- -----------------------------------------------------------
-- TABLE: user_data_sources
-- Entity: src/modules/users/entities/user-data-source.entity.ts
-- Description: Tracks every information source that contributed
-- to the user's profile (data lineage / audit trail).
-- -----------------------------------------------------------
CREATE TABLE user_data_sources (
-- Primary key
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
-- Foreign key
user_id UUID NOT NULL
REFERENCES "user"(id) ON DELETE CASCADE,
-- Source info
source_type data_source_type_enum NOT NULL,
source_name VARCHAR(100) NOT NULL, -- e.g. "onboarding_v1", "resume_2024.pdf"
raw_data JSONB NOT NULL, -- Raw extracted data from this source
-- Processing status
is_processed BOOLEAN NOT NULL DEFAULT FALSE,
confidence INTEGER NOT NULL DEFAULT 100, -- Data quality 0-100
-- Timestamp
created_at TIMESTAMP NOT NULL DEFAULT NOW()
);
-- Indexes
CREATE INDEX idx_user_data_sources_user_id ON user_data_sources (user_id);
CREATE INDEX idx_user_data_sources_processed ON user_data_sources (user_id, is_processed);
-- -----------------------------------------------------------
-- TABLE: user_personality_traits
-- Entity: src/modules/users/entities/user-personality.entity.ts
-- Description: Stores structured personality traits.
-- Can be populated from onboarding quiz or future
-- personality assessments.
-- -----------------------------------------------------------
CREATE TABLE user_personality_traits (
-- Primary key
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
-- Foreign key
user_id UUID NOT NULL
REFERENCES "user"(id) ON DELETE CASCADE,
-- Trait
category personality_trait_category_enum NOT NULL,
trait_key VARCHAR(100) NOT NULL, -- e.g. "prefers_collaborative_work"
trait_value VARCHAR(255) NOT NULL, -- e.g. "high", "true", "introvert"
score INTEGER, -- Optional 0-100 numeric score
-- Source
source VARCHAR(50) NOT NULL, -- e.g. "onboarding_quiz", "personality_test_v1"
-- Timestamp
created_at TIMESTAMP NOT NULL DEFAULT NOW()
);
-- Indexes
CREATE INDEX idx_user_personality_user_id ON user_personality_traits (user_id);
CREATE INDEX idx_user_personality_category ON user_personality_traits (user_id, category);
-- -----------------------------------------------------------
-- TABLE: user_context_snapshots
-- Entity: src/modules/users/entities/user-context-snapshot.entity.ts
-- Description: Pre-computed LLM context snapshots.
-- Aggregates profile + goals + personality into
-- a structured JSON ready for prompt injection.
-- Regenerated whenever user data changes.
-- -----------------------------------------------------------
CREATE TABLE user_context_snapshots (
-- Primary key
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
-- Foreign key
user_id UUID NOT NULL
REFERENCES "user"(id) ON DELETE CASCADE,
-- Context type
context_type VARCHAR(50) NOT NULL, -- "career_guidance", "resume_analysis", "job_matching"
-- Pre-computed context
structured_context JSONB NOT NULL,
/*
* Example structure:
* {
* "primary_goals": ["job_matching", "resume_improvement"],
* "professional_context": {
* "experience_level": "mid_level",
* "years": 4,
* "current_role": "Software Engineer",
* "target_role": "Senior Engineer",
* "industry": "technology"
* },
* "personality_insights": {
* "work_style": "collaborative",
* "learning_preference": "hands_on"
* },
* "skills": ["JavaScript", "React", "Node.js"],
* "location": "New York, NY",
* "preferences": {
* "remote": true,
* "willing_to_relocate": false
* }
* }
*/
llm_ready_prompt TEXT NOT NULL, -- Pre-formatted natural language context for LLM
version INTEGER NOT NULL DEFAULT 1, -- Increments on each regeneration
-- Timestamp
created_at TIMESTAMP NOT NULL DEFAULT NOW()
);
-- Indexes
CREATE INDEX idx_context_snapshots_user_id ON user_context_snapshots (user_id);
CREATE INDEX idx_context_snapshots_type ON user_context_snapshots (user_id, context_type);
-- -----------------------------------------------------------
-- VARIABLE REFERENCE β ONBOARDING MODULE
-- -----------------------------------------------------------
--
-- user_profiles:
-- user_id β FK to user; one profile per user
-- experience_level β Enum; populates LLM prompt ("mid_level" β "mid level")
-- years_of_experience β Integer; used in LLM context generation
-- education_level β Enum; shown in LLM context
-- current_role β Free text; used in resume scoring relevance (Lens A)
-- target_role β Free text; used in resume scoring relevance (Lens A)
-- current_industry β Enum; used in LLM context
-- target_industry β Enum; used in LLM context
-- career_stage β Enum; used to calibrate LLM tone (entry vs senior)
-- location / target_location β Used in job matching context
-- willing_to_relocate β Preference flag for job matching
-- open_to_remote β Preference flag for job matching
-- skills β JSONB array; injected into resume scoring prompt
-- interests β JSONB array; used in LLM context
-- bio β Free text; appended to LLM context if present
-- profile_completeness β Computed 0-100; shown in GET /onboarding/status
--
-- user_goals:
-- goal_type β Enum; determines which LLM features to activate
-- priority β Int 1-5; first goal is primary, drives LLM focus
-- is_active β Allows deactivating goals without deletion
-- source β Tracks how the goal was captured
--
-- user_data_sources:
-- source_type β Enum; classifies origin of data
-- source_name β String identifier; useful for debugging/auditing
-- raw_data β JSONB blob of original unprocessed input
-- is_processed β Flag; marks when raw_data has been distributed
-- confidence β Quality score; lower = less reliable data
--
-- user_personality_traits:
-- category β Enum groups traits (work_style, leadership, etc.)
-- trait_key β Snake_case string key e.g. "prefers_deep_work"
-- trait_value β String value e.g. "high", "true", "introvert"
-- score β Optional 0-100 numeric; NULL if not applicable
-- source β Which quiz/tool produced this trait
--
-- user_context_snapshots:
-- context_type β Which LLM use-case this snapshot is for
-- structured_context β JSONB pre-aggregated from profile + goals + traits
-- llm_ready_prompt β Text ready to be injected into Groq/GPT system prompt
-- version β Increments each time snapshot is regenerated
|