-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit_db.sql
More file actions
155 lines (137 loc) · 6.22 KB
/
init_db.sql
File metadata and controls
155 lines (137 loc) · 6.22 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
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
-- Automotas AI Test Database Initialization
-- ==========================================
-- Create extensions for testing
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
-- Create test schemas
CREATE SCHEMA IF NOT EXISTS test_data;
CREATE SCHEMA IF NOT EXISTS test_results;
CREATE SCHEMA IF NOT EXISTS test_history;
-- Test data tables for seeding
CREATE TABLE IF NOT EXISTS test_data.sample_agents (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name VARCHAR(255) NOT NULL,
type VARCHAR(100) NOT NULL,
description TEXT,
configuration JSONB,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS test_data.sample_workflows (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name VARCHAR(255) NOT NULL,
type VARCHAR(50) NOT NULL,
steps JSONB NOT NULL,
configuration JSONB,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS test_data.sample_documents (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
metadata JSONB,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Test results tables
CREATE TABLE IF NOT EXISTS test_results.test_runs (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
test_run_id VARCHAR(255) UNIQUE NOT NULL,
environment VARCHAR(50) NOT NULL,
total_tests INTEGER NOT NULL DEFAULT 0,
passed INTEGER NOT NULL DEFAULT 0,
failed INTEGER NOT NULL DEFAULT 0,
skipped INTEGER NOT NULL DEFAULT 0,
success_rate DECIMAL(5,2),
duration DECIMAL(10,3),
status VARCHAR(20) NOT NULL,
started_at TIMESTAMP WITH TIME ZONE NOT NULL,
completed_at TIMESTAMP WITH TIME ZONE,
configuration JSONB,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS test_results.test_cases (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
test_run_id UUID REFERENCES test_results.test_runs(id),
test_suite VARCHAR(255) NOT NULL,
test_name VARCHAR(255) NOT NULL,
status VARCHAR(20) NOT NULL,
duration DECIMAL(10,3),
error_message TEXT,
error_details JSONB,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS test_results.performance_metrics (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
test_run_id UUID REFERENCES test_results.test_runs(id),
metric_name VARCHAR(255) NOT NULL,
metric_value DECIMAL(15,6),
metric_unit VARCHAR(50),
endpoint VARCHAR(255),
timestamp TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Seed test data
INSERT INTO test_data.sample_agents (name, type, description, configuration) VALUES
('TestAgent1', 'code_architect', 'Test agent for code architecture', '{"priority": "normal", "skills": ["code_analysis", "architecture_design"]}'),
('TestAgent2', 'security_expert', 'Test agent for security analysis', '{"priority": "high", "skills": ["vulnerability_scanning", "threat_modeling"]}'),
('TestAgent3', 'performance_optimizer', 'Test agent for performance optimization', '{"priority": "normal", "skills": ["performance_analysis", "optimization"]}');
INSERT INTO test_data.sample_workflows (name, type, steps, configuration) VALUES
('TestWorkflow1', 'sequential', '[{"name": "step1", "type": "analysis"}, {"name": "step2", "type": "validation"}]', '{"timeout": 300}'),
('TestWorkflow2', 'parallel', '[{"name": "step1", "type": "security_scan"}, {"name": "step2", "type": "performance_test"}]', '{"max_parallel": 2}');
INSERT INTO test_data.sample_documents (title, content, metadata) VALUES
('Test Document 1', 'This is a test document for context engineering validation. It contains sample text for embedding generation and similarity testing.', '{"type": "test", "source": "framework"}'),
('Test Document 2', 'Another test document focusing on multi-agent systems and collaboration patterns. This document tests document processing capabilities.', '{"type": "test", "source": "framework"}');
-- Create indexes for better performance
CREATE INDEX IF NOT EXISTS idx_test_runs_environment ON test_results.test_runs(environment);
CREATE INDEX IF NOT EXISTS idx_test_runs_status ON test_results.test_runs(status);
CREATE INDEX IF NOT EXISTS idx_test_runs_created_at ON test_results.test_runs(created_at);
CREATE INDEX IF NOT EXISTS idx_test_cases_test_run_id ON test_results.test_cases(test_run_id);
CREATE INDEX IF NOT EXISTS idx_test_cases_status ON test_results.test_cases(status);
CREATE INDEX IF NOT EXISTS idx_performance_metrics_test_run_id ON test_results.performance_metrics(test_run_id);
-- Grant permissions
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA test_data TO postgres;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA test_results TO postgres;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA test_history TO postgres;
GRANT USAGE ON ALL SEQUENCES IN SCHEMA test_data TO postgres;
GRANT USAGE ON ALL SEQUENCES IN SCHEMA test_results TO postgres;
GRANT USAGE ON ALL SEQUENCES IN SCHEMA test_history TO postgres;
-- Create views for common queries
CREATE OR replace VIEW test_results.latest_test_runs AS
SELECT
test_run_id,
environment,
total_tests,
passed,
failed,
success_rate,
duration,
status,
completed_at
FROM test_results.test_runs
ORDER BY completed_at DESC
LIMIT 10;
CREATE OR REPLACE VIEW test_results.test_suite_summary AS
SELECT
tr.environment,
tc.test_suite,
COUNT(*) as total_cases,
COUNT(*) FILTER (WHERE tc.status = 'passed') as passed_cases,
COUNT(*) FILTER (WHERE tc.status = 'failed') as failed_cases,
ROUND(AVG(tc.duration), 3) as avg_duration
FROM test_results.test_runs tr
JOIN test_results.test_cases tc ON tr.id = tc.test_run_id
WHERE tr.completed_at >= NOW() - INTERVAL '30 days'
GROUP BY tr.environment, tc.test_suite
ORDER BY tr.environment, tc.test_suite;
-- Performance tracking view
CREATE OR REPLACE VIEW test_results.performance_trends AS
SELECT
DATE_TRUNC('day', pm.timestamp) as date,
pm.metric_name,
pm.endpoint,
AVG(pm.metric_value) as avg_value,
MIN(pm.metric_value) as min_value,
MAX(pm.metric_value) as max_value
FROM test_results.performance_metrics pm
WHERE pm.timestamp >= NOW() - INTERVAL '30 days'
GROUP BY DATE_TRUNC('day', pm.timestamp), pm.metric_name, pm.endpoint
ORDER BY date DESC, metric_name;
COMMIT;