57 lines
2.1 KiB
YAML
57 lines
2.1 KiB
YAML
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
name: {{ .Release.Name }}-db-schema
|
|
namespace: {{ .Values.global.namespace }}
|
|
data:
|
|
schema.sql: |
|
|
-- Create users table
|
|
CREATE TABLE IF NOT EXISTS users (
|
|
id SERIAL PRIMARY KEY,
|
|
username TEXT UNIQUE NOT NULL,
|
|
email TEXT UNIQUE NOT NULL,
|
|
hashed_password TEXT NOT NULL,
|
|
first_name TEXT,
|
|
last_name TEXT,
|
|
age INTEGER,
|
|
gender TEXT,
|
|
bio TEXT,
|
|
profile_picture TEXT,
|
|
location TEXT,
|
|
interests TEXT[] DEFAULT '{}',
|
|
is_active BOOLEAN DEFAULT TRUE,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_users_username ON users (username);
|
|
CREATE INDEX IF NOT EXISTS idx_users_email ON users (email);
|
|
CREATE INDEX IF NOT EXISTS idx_users_is_active ON users (is_active);
|
|
|
|
-- Profiles table for additional user info
|
|
CREATE TABLE IF NOT EXISTS profiles (
|
|
id SERIAL PRIMARY KEY,
|
|
user_id INTEGER UNIQUE NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
verified BOOLEAN DEFAULT FALSE,
|
|
verification_token TEXT,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_profiles_user_id ON profiles (user_id);
|
|
|
|
-- Matches/Likes table
|
|
CREATE TABLE IF NOT EXISTS matches (
|
|
id SERIAL PRIMARY KEY,
|
|
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
matched_user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
status TEXT DEFAULT 'pending',
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_matches_user_id ON matches (user_id);
|
|
CREATE INDEX IF NOT EXISTS idx_matches_matched_user_id ON matches (matched_user_id);
|
|
-- Prevent duplicate matches in both directions
|
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_matches_unique ON matches
|
|
(LEAST(user_id, matched_user_id), GREATEST(user_id, matched_user_id));
|