-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
118 lines (106 loc) · 4.21 KB
/
docker-compose.yml
File metadata and controls
118 lines (106 loc) · 4.21 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
services:
umamusume-db:
image: mariadb:11.4
container_name: umamusume-db
environment:
MARIADB_ROOT_PASSWORD: yourpassword
MARIADB_DATABASE: umamusume
MARIADB_ROOT_HOST: "%"
ports:
- "3306:3306"
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
volumes:
- umamusume-db-data:/var/lib/mysql
- ./Global/master.mdb:/data/master.mdb:ro
- ./UmaMusumeAPI/SqlScripts/TableCreation.sql:/docker-entrypoint-initdb.d/01-tables.sql
- ./UmaMusumeAPI/SqlScripts/Functions/FROM_UNIXTIME_SECONDS.sql:/docker-entrypoint-initdb.d/02-functions.sql
- ./UmaMusumeAPI/SqlScripts/ViewCreation.sql:/docker-entrypoint-initdb.d/03-views.sql
- ./UmaMusumeAPI/SqlScripts/StoredProcedureCreation.sql:/docker-entrypoint-initdb.d/04-procedures.sql
- ./UmaMusumeAPI/SqlScripts/AddMissingColumns.sql:/docker-entrypoint-initdb.d/05-add-missing-columns.sql
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
interval: 10s
timeout: 5s
retries: 5
db-loader:
image: python:3.12-slim
container_name: umamusume-db-loader
depends_on:
umamusume-db:
condition: service_healthy
environment:
DB_HOST: umamusume-db
DB_USER: root
DB_PASSWORD: yourpassword
DB_NAME: umamusume
MDB_PATH: /data/master.mdb
volumes:
- ./Global/master.mdb:/data/master.mdb:ro
command:
- sh
- -c
- |
pip install pymysql -q
python3 << 'PYEOF'
import sqlite3, pymysql, os, sys, time
host=os.environ["DB_HOST"]; user=os.environ["DB_USER"]
pw=os.environ["DB_PASSWORD"]; db=os.environ["DB_NAME"]
mdb=os.environ["MDB_PATH"]
conn = None
for i in range(30):
try:
conn = pymysql.connect(host=host, user=user, password=pw, database=db, charset="utf8mb4")
print("Connected to MariaDB."); break
except Exception as e:
print(f"Waiting... ({i+1}/30): {e}"); time.sleep(3)
if not conn: sys.exit("ERROR: Could not connect.")
sq = sqlite3.connect(mdb)
sq.row_factory = sqlite3.Row
sqc = sq.cursor()
myc = conn.cursor()
myc.execute("SET FOREIGN_KEY_CHECKS=0")
sqc.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name")
tables = [r[0] for r in sqc.fetchall()]
print(f"Importing data from {len(tables)} tables...")
total = 0
for table in tables:
sqc.execute(f"SELECT * FROM `{table}` LIMIT 1")
if not sqc.fetchone():
continue
# get columns from sqlite
sqc.execute(f"PRAGMA table_info(`{table}`)")
sq_cols = {row[1] for row in sqc.fetchall()}
# get columns from mariadb, skip table if it doesn't exist
try:
myc.execute(f"SHOW COLUMNS FROM `{table}`")
except Exception:
print(f" {table}: SKIP (not in MariaDB schema)")
continue
my_cols = {row[0] for row in myc.fetchall()}
# only use columns present in both
common_cols = [c for c in sq_cols if c in my_cols]
if not common_cols:
print(f" {table}: SKIP (no matching columns)")
continue
col_list = ",".join(f"`{c}`" for c in common_cols)
sqc.execute(f"SELECT {col_list} FROM `{table}`")
rows = sqc.fetchall()
ph = ",".join(["%s"] * len(common_cols))
data = [tuple(r) for r in rows]
try:
for i in range(0, len(data), 1000):
myc.executemany(f"INSERT IGNORE INTO `{table}` ({col_list}) VALUES ({ph})", data[i:i+1000])
conn.commit()
print(f" {table}: {len(data)} rows")
total += len(data)
except Exception as e:
conn.rollback()
print(f" {table}: ERROR - {e}")
myc.execute("SET FOREIGN_KEY_CHECKS=1")
conn.commit()
sq.close(); conn.close()
print(f"\nDone. {total} total rows imported.")
PYEOF
restart: "no"
volumes:
umamusume-db-data: