Repository navigation
Expand file tree
/
Copy pathaws_init.sql
More file actions
78 lines (70 loc) · 2.75 KB
/
Copy pathaws_init.sql
File metadata and controls
78 lines (70 loc) · 2.75 KB
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
-- Database initialization script for AWS RDS PostgreSQL
-- Run this script on your AWS RDS instance to create required tables and extensions
-- Enable required PostgreSQL extensions
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS vector;
-- Create users table for authentication
CREATE TABLE IF NOT EXISTS users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
email VARCHAR(320) UNIQUE NOT NULL,
username VARCHAR(100) UNIQUE NOT NULL,
hashed_password VARCHAR(1024) NOT NULL,
is_active BOOLEAN DEFAULT TRUE,
is_superuser BOOLEAN DEFAULT FALSE,
is_verified BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
full_name VARCHAR(200),
role VARCHAR(50) DEFAULT 'user'
);
-- Create indexes for users table (better performance)
CREATE INDEX IF NOT EXISTS idx_users_email ON users(email);
CREATE INDEX IF NOT EXISTS idx_users_username ON users(username);
CREATE INDEX IF NOT EXISTS idx_users_is_active ON users(is_active);
-- Create user_sessions table for session management
CREATE TABLE IF NOT EXISTS user_sessions (
session_id VARCHAR(255) PRIMARY KEY,
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
workspace_path TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
last_accessed TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
active BOOLEAN NOT NULL DEFAULT TRUE,
deleted BOOLEAN NOT NULL DEFAULT FALSE,
metadata JSONB DEFAULT '{}'::jsonb
);
-- Create indexes for user_sessions table
CREATE INDEX IF NOT EXISTS idx_user_sessions_user_id ON user_sessions(user_id);
CREATE INDEX IF NOT EXISTS idx_user_sessions_active_deleted ON user_sessions(active, deleted);
CREATE INDEX IF NOT EXISTS idx_user_sessions_last_accessed ON user_sessions(last_accessed);
-- Insert default admin user (password: admin123)
-- Note: Change this password immediately after first login!
INSERT INTO users (
id,
email,
username,
hashed_password,
is_active,
is_superuser,
is_verified,
role,
full_name,
created_at,
updated_at
) VALUES (
gen_random_uuid(),
'admin@example.com',
'admin',
'$2b$12$SIZFiRUJXtoTgNqipUB1FOoDqBL2WqHp6wK2dxLDxIYNyshtvGgwm', -- hashed "admin123"
TRUE,
TRUE,
TRUE,
'admin',
'Administrator',
NOW(),
NOW()
) ON CONFLICT (email) DO NOTHING;
-- LangGraph checkpoint tables will be auto-created by the application
-- You can pre-create them here if needed for specific database policies
COMMENT ON TABLE users IS 'User authentication and profile data';
COMMENT ON TABLE user_sessions IS 'User session management for dairy nutrition agent';
COMMENT ON EXTENSION vector IS 'Required for pgvector operations in LangGraph';