discord-kurante/aux/init_db

32 lines
762 B
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
DB_NAME="data.sqlite"
PROJECT_ROOT=$(cargo locate-project | sed -E 's#.*"(/.*)/Cargo.toml"}#\1#')
if [ ! -f "$PROJECT_ROOT/$DB_NAME" ]; then
sqlite3 "$PROJECT_ROOT/$DB_NAME" <<EOF
CREATE TABLE IF NOT EXISTS Heck (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
count INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS RollCount (
user_id TEXT PRIMARY KEY UNIQUE NOT NULL,
count INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS OperatorCount (
user_id TEXT NOT NULL,
operator TEXT NOT NULL,
count INTEGER NOT NULL,
UNIQUE(user_id, operator)
);
INSERT INTO Heck (id, count) VALUES (1, 0)
ON CONFLICT(id) DO NOTHING;
EOF
else
echo "$DB_NAME exists, exiting."
fi