52 lines
1.9 KiB
SQL
52 lines
1.9 KiB
SQL
-- Create users table
|
|
CREATE TABLE IF NOT EXISTS users (
|
|
id SERIAL PRIMARY KEY,
|
|
username TEXT UNIQUE NOT NULL,
|
|
email TEXT UNIQUE NOT NULL,
|
|
password_hash TEXT NOT NULL,
|
|
first_name TEXT,
|
|
last_name TEXT,
|
|
display_name TEXT UNIQUE NOT NULL,
|
|
is_admin BOOLEAN DEFAULT FALSE,
|
|
created_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 recipes table
|
|
CREATE TABLE IF NOT EXISTS recipes (
|
|
id SERIAL PRIMARY KEY,
|
|
name TEXT NOT NULL,
|
|
meal_type TEXT NOT NULL, -- breakfast / lunch / dinner / snack
|
|
time_minutes INTEGER NOT NULL,
|
|
tags TEXT[] NOT NULL DEFAULT '{}', -- {"מהיר", "בריא"}
|
|
ingredients TEXT[] NOT NULL DEFAULT '{}', -- {"ביצה", "עגבניה", "מלח"}
|
|
steps TEXT[] NOT NULL DEFAULT '{}', -- {"לחתוך", "לבשל", ...}
|
|
image TEXT, -- Base64-encoded image or image URL
|
|
made_by TEXT, -- Person who created this recipe version
|
|
user_id INTEGER REFERENCES users(id) ON DELETE SET NULL, -- Recipe owner
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
-- Optional: index for filters
|
|
CREATE INDEX IF NOT EXISTS idx_recipes_meal_type
|
|
ON recipes (meal_type);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_recipes_time_minutes
|
|
ON recipes (time_minutes);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_recipes_made_by
|
|
ON recipes (made_by);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_recipes_user_id
|
|
ON recipes (user_id);
|
|
|
|
-- Create default admin user (password: admin123)
|
|
-- Password hash generated with bcrypt for 'admin123'
|
|
INSERT INTO users (username, email, password_hash, first_name, last_name, display_name, is_admin)
|
|
VALUES ('admin', 'admin@myrecipes.local', '$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5lE7UGf3rCvHC', 'Admin', 'User', 'מנהל', TRUE)
|
|
ON CONFLICT (username) DO NOTHING;
|
|
|
|
|