-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb-init.sql
More file actions
63 lines (57 loc) · 1.68 KB
/
db-init.sql
File metadata and controls
63 lines (57 loc) · 1.68 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
-- Enable the pgcrypto extension
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE EXTENSION IF NOT EXISTS plpgsql;
-- Create the users table with audit trail
CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
username TEXT NOT NULL UNIQUE,
password TEXT NOT NULL,
role TEXT NOT NULL DEFAULT 'admin', -- 'admin' or 'user'
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Create the ae_titles table with audit trail
CREATE TABLE IF NOT EXISTS ae_titles (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
host TEXT NOT NULL,
port INTEGER NOT NULL,
aeTitle TEXT NOT NULL,
remoteAETitle TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Create the wado_requests table
CREATE TABLE IF NOT EXISTS wado_requests (
id SERIAL PRIMARY KEY,
study_uid TEXT,
series_uid TEXT,
object_uid TEXT,
ae_title TEXT,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Create the qido_requests table
CREATE TABLE IF NOT EXISTS qido_requests (
id SERIAL PRIMARY KEY,
study_uid TEXT,
accession_number TEXT,
ae_title TEXT,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Create the stow_requests table
CREATE TABLE IF NOT EXISTS stow_requests (
id SERIAL PRIMARY KEY,
study_uid TEXT,
series_uid TEXT,
object_uid TEXT,
ae_title TEXT,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Insert the default admin user (if not exists)
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM users WHERE username = 'admin') THEN
INSERT INTO users (username, password, role)
VALUES ('admin', crypt('admin123', gen_salt('bf')), 'admin');
END IF;
END $$;