#!/usr/bin/env bash set -euo pipefail db_path="${1:-LionWebsite.db}" if [[ ! -f "$db_path" ]]; then echo "数据库不存在: $db_path" >&2 exit 2 fi if command -v systemctl >/dev/null 2>&1 && systemctl is-active --quiet lionwebsite 2>/dev/null; then echo "检测到 lionwebsite.service 仍在运行;请先停止服务再迁移,避免写冲突。" >&2 exit 3 fi if pgrep -f 'java .*lionwebsite\.jar' >/dev/null 2>&1; then echo "检测到主站进程仍在运行;请先停止服务再迁移,避免写冲突。" >&2 exit 3 fi backup="${db_path}.before-refresh-schedule.$(date -u +%Y%m%dT%H%M%SZ)" cp "$db_path" "$backup" echo "已备份: $backup" sqlite3 "$db_path" < "$(dirname "$0")/migrate_subscription_refresh.sql" echo "--- 校验 ---" sqlite3 "$db_path" "select count(*) as accounts, sum(next_refresh_at is null) as missing_schedule from subscription_account;" echo "订阅刷新计划迁移完成: $db_path"