Vega AI uses SQLite with Write-Ahead Logging (WAL) mode for concurrent reads and writes. The schema is designed with multi-tenancy in mind, ensuring complete data isolation between users.
CREATE TABLE users ( id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT NOT NULL, password TEXT, role TEXT NOT NULL DEFAULT 'user', last_login TIMESTAMP, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP);CREATE UNIQUE INDEX idx_users_username ON users(username);
Key Fields:
username - Unique identifier for authentication
password - Bcrypt-hashed password (nullable for OAuth-only users)
role - User role (user or admin)
last_login - Tracks last successful login
Multi-Tenant Note: Users table is the root of data isolation. All user-specific tables reference this via user_id.
CREATE TABLE companies ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP);CREATE UNIQUE INDEX idx_companies_name ON companies(name);
Companies table is intentionally shared across users to normalize company data and enable future features like company insights.
CREATE TABLE jobs ( id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL, title TEXT NOT NULL, description TEXT NOT NULL, location TEXT, job_type INTEGER NOT NULL DEFAULT 0, source_url TEXT, required_skills TEXT, -- JSON array application_url TEXT, company_id INTEGER NOT NULL, status INTEGER NOT NULL DEFAULT 0, match_score INTEGER, notes TEXT, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, FOREIGN KEY (company_id) REFERENCES companies(id), CHECK (match_score IS NULL OR (match_score >= 0 AND match_score <= 100)));-- Multi-tenant indexesCREATE INDEX idx_jobs_user_id ON jobs(user_id);CREATE INDEX idx_jobs_user_id_status ON jobs(user_id, status);CREATE INDEX idx_jobs_user_id_created_at ON jobs(user_id, created_at DESC);-- Prevent duplicate job URLs per userCREATE UNIQUE INDEX idx_jobs_user_id_source_url ON jobs(user_id, source_url);-- Query optimization indexesCREATE INDEX idx_jobs_title ON jobs(title);CREATE INDEX idx_jobs_status ON jobs(status);CREATE INDEX idx_jobs_match_score ON jobs(match_score);CREATE INDEX idx_jobs_company_id ON jobs(company_id);
User professional profile with 1:1 relationship to users.
CREATE TABLE profiles ( id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL UNIQUE, first_name TEXT DEFAULT '', last_name TEXT DEFAULT '', title TEXT DEFAULT '', industry INTEGER DEFAULT 64, -- IndustryUnspecified career_summary TEXT DEFAULT '', skills TEXT DEFAULT '', -- JSON string phone_number TEXT DEFAULT '', email TEXT DEFAULT '', location TEXT DEFAULT '', linkedin_profile TEXT DEFAULT '', github_profile TEXT DEFAULT '', website TEXT DEFAULT '', context TEXT DEFAULT '', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE);CREATE INDEX idx_profiles_user_id ON profiles(user_id);-- Automatic profile creation triggerCREATE TRIGGER create_profile_after_user_insertAFTER INSERT ON usersFOR EACH ROWBEGIN INSERT INTO profiles (user_id, created_at) VALUES (NEW.id, CURRENT_TIMESTAMP);END;
Professional work history with 1:many relationship to profiles.
CREATE TABLE work_experiences ( id INTEGER PRIMARY KEY AUTOINCREMENT, profile_id INTEGER NOT NULL, company TEXT NOT NULL, title TEXT NOT NULL, location TEXT, start_date TIMESTAMP NOT NULL, end_date TIMESTAMP, description TEXT, current BOOLEAN DEFAULT 0, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (profile_id) REFERENCES profiles(id) ON DELETE CASCADE);CREATE INDEX idx_work_experiences_profile_id ON work_experiences(profile_id);CREATE INDEX idx_work_experiences_start_date ON work_experiences(start_date);
Educational background with 1:many relationship to profiles.
CREATE TABLE education ( id INTEGER PRIMARY KEY AUTOINCREMENT, profile_id INTEGER NOT NULL, institution TEXT NOT NULL, degree TEXT NOT NULL, field_of_study TEXT, start_date TIMESTAMP NOT NULL, end_date TIMESTAMP, description TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (profile_id) REFERENCES profiles(id) ON DELETE CASCADE);CREATE INDEX idx_education_profile_id ON education(profile_id);CREATE INDEX idx_education_start_date ON education(start_date);
Professional certifications with 1:many relationship to profiles.
CREATE TABLE certifications ( id INTEGER PRIMARY KEY AUTOINCREMENT, profile_id INTEGER NOT NULL, name TEXT NOT NULL, issuing_org TEXT NOT NULL, issue_date TIMESTAMP NOT NULL, expiry_date TIMESTAMP, credential_id TEXT, credential_url TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (profile_id) REFERENCES profiles(id) ON DELETE CASCADE);CREATE INDEX idx_certifications_profile_id ON certifications(profile_id);CREATE INDEX idx_certifications_issue_date ON certifications(issue_date);
Tracks AI analysis usage per user (cloud mode only).
CREATE TABLE quota_usage ( id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL, quota_type TEXT NOT NULL, period_start TIMESTAMP NOT NULL, period_end TIMESTAMP NOT NULL, used_count INTEGER NOT NULL DEFAULT 0, limit_count INTEGER NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE);CREATE INDEX idx_quota_usage_user_id ON quota_usage(user_id);CREATE INDEX idx_quota_usage_user_id_type_period ON quota_usage(user_id, quota_type, period_start, period_end);
CREATE TABLE quota_usage_history ( id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL, quota_type TEXT NOT NULL, job_id INTEGER, action TEXT NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, FOREIGN KEY (job_id) REFERENCES jobs(id) ON DELETE SET NULL);CREATE INDEX idx_quota_history_user_id ON quota_usage_history(user_id);CREATE INDEX idx_quota_history_created_at ON quota_usage_history(created_at DESC);
CREATE TABLE generated_documents ( id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL, job_id INTEGER, document_type TEXT NOT NULL, content TEXT NOT NULL, format TEXT NOT NULL DEFAULT 'html', metadata TEXT, -- JSON expires_at TIMESTAMP, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, FOREIGN KEY (job_id) REFERENCES jobs(id) ON DELETE SET NULL);CREATE INDEX idx_generated_documents_user_id ON generated_documents(user_id);CREATE INDEX idx_generated_documents_job_id ON generated_documents(job_id);CREATE INDEX idx_generated_documents_expires_at ON generated_documents(expires_at);
-- Multi-tenant query optimizationCREATE INDEX idx_jobs_user_id_status ON jobs(user_id, status);CREATE INDEX idx_jobs_user_id_created_at ON jobs(user_id, created_at DESC);-- Sorting and filteringCREATE INDEX idx_jobs_user_id_match_score ON jobs(user_id, match_score DESC);