-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-mysql.sh
executable file
·80 lines (73 loc) · 2.51 KB
/
init-mysql.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
#!/bin/bash
# Create a directory for the MySQL database
mkdir -p $(pwd)/data/mysql
# SQL commands
echo '
CREATE TABLE devices (
id bigint unsigned NOT NULL AUTO_INCREMENT,
device_id varchar(256) NOT NULL,
version varchar(256) NOT NULL,
arch varchar(128) NOT NULL,
os varchar(128) NOT NULL,
client_address varchar(256) DEFAULT "",
login_time TIMESTAMP,
meta JSON,
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW() ON UPDATE NOW(),
PRIMARY KEY (id),
UNIQUE KEY device_id (device_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE node_status (
id bigint unsigned NOT NULL AUTO_INCREMENT,
node_id varchar(256) NOT NULL,
device_id varchar(256) NOT NULL,
subdomain varchar(256) DEFAULT "",
version varchar(256) NOT NULL,
arch varchar(128) NOT NULL,
os varchar(128) NOT NULL,
client_address varchar(256) DEFAULT "",
geo_coordinates varchar(256) DEFAULT "",
location varchar(256) DEFAULT "",
country varchar(28) DEFAULT "",
subdivision varchar(28) DEFAULT "",
city varchar(28) DEFAULT "",
login_time TIMESTAMP,
last_active_time TIMESTAMP,
last_avail_time TIMESTAMP,
run_id varchar(256) DEFAULT "",
meta JSON,
hardware JSON,
node_version varchar(20) DEFAULT "",
chat_model varchar(256) DEFAULT "",
embedding_model varchar(256) DEFAULT "",
status varchar(24),
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW() ON UPDATE NOW(),
PRIMARY KEY (id),
UNIQUE KEY node_id (node_id),
UNIQUE KEY subdomain (subdomain),
INDEX idx_status (status),
INDEX idx_login_time (login_time),
INDEX idx_last_active_time (last_active_time),
INDEX idx_last_avail_time (last_avail_time),
INDEX idx_country (country),
INDEX idx_subdivision (subdivision),
INDEX idx_city (city)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE domain_nodes (
domain varchar(256) NOT NULL,
node_id varchar(256) NOT NULL,
weight bigint unsigned NOT NULL,
UNIQUE KEY node_id (node_id),
PRIMARY KEY (domain, node_id)
);
' > init.sql
# Function to run MySQL commands
docker network create gaia-network
docker run --rm --network gaia-network --name gaia-mysql -e MYSQL_DATABASE=gaia.domain -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -e MYSQL_USER=gaia -e MYSQL_PASSWORD=$MYSQL_PASSWORD -v "$(pwd)/data/mysql:/var/lib/mysql" -d mysql:8
sleep 20
docker run -i --rm --network gaia-network mysql:8 mysql -hgaia-mysql -ugaia -p$MYSQL_PASSWORD -D gaia.domain < init.sql
docker stop gaia-mysql
docker network rm gaia-network
rm init.sql
echo "Database initialized in ./data/mysql"