forked from VRAutomatize/browser-use
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigration.sql
More file actions
71 lines (61 loc) · 2.46 KB
/
migration.sql
File metadata and controls
71 lines (61 loc) · 2.46 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
-- Migration script that checks for existing tables before creating
DO $$
BEGIN
-- Check if tables already exist
IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'tasks') THEN
-- Create tasks table
CREATE TABLE tasks (
id SERIAL PRIMARY KEY,
task VARCHAR NOT NULL,
config JSONB,
status VARCHAR NOT NULL,
result JSONB,
error VARCHAR,
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
started_at TIMESTAMP WITH TIME ZONE,
completed_at TIMESTAMP WITH TIME ZONE
);
-- Create index for tasks
CREATE INDEX idx_tasks_status ON tasks(status);
CREATE INDEX idx_tasks_created_at ON tasks(created_at);
RAISE NOTICE 'Created tasks table';
ELSE
RAISE NOTICE 'tasks table already exists, skipping creation';
END IF;
IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'metrics') THEN
-- Create metrics table
CREATE TABLE metrics (
id SERIAL PRIMARY KEY,
name VARCHAR NOT NULL,
value DOUBLE PRECISION NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL
);
-- Create index for metrics
CREATE INDEX idx_metrics_name ON metrics(name);
CREATE INDEX idx_metrics_created_at ON metrics(created_at);
RAISE NOTICE 'Created metrics table';
ELSE
RAISE NOTICE 'metrics table already exists, skipping creation';
END IF;
IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'sessions') THEN
-- Create sessions table
CREATE TABLE sessions (
id SERIAL PRIMARY KEY,
task_id INTEGER NOT NULL,
start_time TIMESTAMP WITH TIME ZONE NOT NULL,
end_time TIMESTAMP WITH TIME ZONE,
status VARCHAR NOT NULL,
error VARCHAR,
created_at TIMESTAMP WITH TIME ZONE NOT NULL
);
-- Create index for sessions
CREATE INDEX idx_sessions_task_id ON sessions(task_id);
CREATE INDEX idx_sessions_status ON sessions(status);
CREATE INDEX idx_sessions_start_time ON sessions(start_time);
RAISE NOTICE 'Created sessions table';
ELSE
RAISE NOTICE 'sessions table already exists, skipping creation';
END IF;
END $$;
-- Output the results
SELECT 'Migration completed with existence checks' AS result;