thread-master/deploy/scripts/migrate.sh

38 lines
1.1 KiB
Bash
Executable File
Raw 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
# Mongo migrationgolang-migrate + seed admin
set -euo pipefail
# shellcheck source=_common.sh
source "$(cd "$(dirname "$0")" && pwd)/_common.sh"
load_env
require_cmd go
ensure_migrate() {
if command -v migrate >/dev/null 2>&1; then
return
fi
log "installing golang-migrate (mongodb tag)…"
go install -tags 'mongodb' github.com/golang-migrate/migrate/v4/cmd/migrate@v4.18.3
export PATH="${PATH}:$(go env GOPATH)/bin"
command -v migrate >/dev/null 2>&1 || die "migrate 安裝失敗,請確認 GOPATH/bin 在 PATH"
}
ensure_migrate
export PATH="${PATH}:$(go env GOPATH)/bin"
# 組 MONGO_URL
if [[ -z "${MONGO_URL:-}" ]]; then
die "MONGO_URL 未設定"
fi
log "migrate up → $MONGO_URL"
# 隱藏密碼於 log只顯示 host
cd "$BACKEND_DIR"
migrate -path generate/database/mongo -database "$MONGO_URL" up
migrate -path generate/database/mongo -database "$MONGO_URL" version || true
log "seed adminmigration 000003"
log " email: 見 generate/database/mongo/000003_seed_admin.up.jsonadmin@30cm.net / admin123"
log " 若密碼政策已改為 ≥12 碼,登入後請立刻改密或重設"
log "migrate done"