pbls/scripts/apply_ddl.sh

24 lines
1.3 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# 幂等落库36 表 DDL + appcodes 注入MariaDB 10.x显式 TCP禁 unix_socket
set -euo pipefail
APP_HOME="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
DB_HOST="${PBLS_DB_HOST:-127.0.0.1}"
DB_PORT="${PBLS_DB_PORT:-3306}"
DB_USER="${PBLS_DB_USER:-}"
DB_NAME="${PBLS_DB_NAME:-pbls}"
echo "[ddl] target tcp://${DB_HOST}:${DB_PORT}/${DB_NAME} (unix_socket disabled)"
mysql --protocol=TCP -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USER" ${PBLS_DB_PASSWORD:+-p"$PBLS_DB_PASSWORD"} \
-e "CREATE DATABASE IF NOT EXISTS \`$DB_NAME\` DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;"
mysql --protocol=TCP -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USER" ${PBLS_DB_PASSWORD:+-p"$PBLS_DB_PASSWORD"} \
--default-character-set=utf8mb4 "$DB_NAME" < "$APP_HOME/scripts/ddl/pbls_tables.sql"
TABLES=$(mysql --protocol=TCP -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USER" ${PBLS_DB_PASSWORD:+-p"$PBLS_DB_PASSWORD"} -N -B -e \
"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='$DB_NAME' AND table_name LIKE 'pbl_%';")
echo "[ddl] pbl_* tables in $DB_NAME = $TABLES (expect >= 36)"
# appcodes 6+2 组幂等注入
PYTHONPATH="$(dirname "$APP_HOME")/modules:$APP_HOME/lib:${PYTHONPATH:-}" \
python3 -c "import sys; sys.path.insert(0,'$(dirname "$APP_HOME")/modules'); import pbl_appcodes; print(pbl_appcodes.inject_all())"