-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
executable file
·89 lines (74 loc) · 2.24 KB
/
init.sh
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
#!/bin/bash
# Create a directory for the SQLite database
mkdir -p $(pwd)/data/sqlite
# Create a Dockerfile
cat << EOF > Dockerfile
FROM alpine:latest
RUN apk add --no-cache sqlite
CMD ["/bin/sh"]
EOF
# Build the Docker image
docker build -t sqlite3-alpine .
rm Dockerfile
# Function to run SQLite commands
run_sqlite() {
docker run --rm -v "$(pwd)/data/sqlite:/data/sqlite" sqlite3-alpine sqlite3 /data/sqlite/gaia-domain.db "$@"
}
# SQL commands
run_sqlite "$(cat <<EOF
PRAGMA journal_mode = WAL;
CREATE TABLE devices (
id integer PRIMARY KEY AUTOINCREMENT,
device_id varchar UNIQUE NOT NULL,
version varchar NOT NULL,
arch varchar NOT NULL,
os varchar NOT NULL,
client_address varchar DEFAULT "",
login_time bigint,
meta text,
created_at bigint DEFAULT (strftime('%s', 'now')),
updated_at bigint DEFAULT (strftime('%s', 'now'))
);
CREATE TABLE node_status (
id integer PRIMARY KEY AUTOINCREMENT,
node_id varchar UNIQUE NOT NULL,
device_id varchar NOT NULL,
subdomain varchar UNIQUE DEFAULT "",
version varchar NOT NULL,
arch varchar NOT NULL,
os varchar NOT NULL,
client_address varchar DEFAULT "",
geo_coordinates varchar DEFAULT "",
location varchar DEFAULT "",
country varchar DEFAULT "",
subdivision varchar DEFAULT "",
city varchar DEFAULT "",
login_time bigint,
last_active_time bigint,
last_avail_time bigint,
run_id varchar DEFAULT "",
meta text,
hardware text,
node_version varchar DEFAULT "",
chat_model varchar DEFAULT "",
embedding_model varchar DEFAULT "",
status varchar,
created_at bigint DEFAULT (strftime('%s', 'now')),
updated_at bigint DEFAULT (strftime('%s', 'now'))
);
CREATE INDEX idx_status ON node_status (status);
CREATE INDEX idx_login_time ON node_status (login_time);
CREATE INDEX idx_last_active_time ON node_status (last_active_time);
CREATE INDEX idx_last_avail_time ON node_status (last_avail_time);
CREATE INDEX idx_country ON node_status (country);
CREATE INDEX idx_subdivision ON node_status (subdivision);
CREATE INDEX idx_city ON node_status (city);
CREATE TABLE domain_nodes (
domain varchar NOT NULL,
node_id varchar UNIQUE NOT NULL,
weight integer NOT NULL,
PRIMARY KEY (domain, node_id)
);
EOF
)"
echo "Database initialized in ./data/sqlite/gaia-domain.db"