fix: 数据库初始化顺序(索引移到migrateCloudConfigs后) + deploy.sh自动检测Redis密码
This commit is contained in:
@@ -22,17 +22,25 @@ if [ -n "$EXISTING_REDIS" ]; then
|
|||||||
docker network connect cloudsearch-net "$EXISTING_REDIS" 2>/dev/null || true
|
docker network connect cloudsearch-net "$EXISTING_REDIS" 2>/dev/null || true
|
||||||
echo " ✅ 已加入 cloudsearch-net"
|
echo " ✅ 已加入 cloudsearch-net"
|
||||||
fi
|
fi
|
||||||
REDIS_HOST="$EXISTING_REDIS"
|
|
||||||
|
# 检测 Redis 密码
|
||||||
|
REDIS_PASS=$(docker inspect "$EXISTING_REDIS" --format '{{range .Config.Cmd}}{{println .}}{{end}}' 2>/dev/null | grep -A1 'requirepass' | tail -1 || true)
|
||||||
|
if [ -n "$REDIS_PASS" ]; then
|
||||||
|
REDIS_URL="redis://:${REDIS_PASS}@${EXISTING_REDIS}:6379"
|
||||||
|
echo " 🔑 检测到 Redis 密码,已自动配置"
|
||||||
|
else
|
||||||
|
REDIS_URL="redis://${EXISTING_REDIS}:6379"
|
||||||
|
fi
|
||||||
PROFILE=""
|
PROFILE=""
|
||||||
else
|
else
|
||||||
echo "📦 未检测到 Redis,将自动创建..."
|
echo "📦 未检测到 Redis,将自动创建..."
|
||||||
REDIS_HOST="CloudSearch_Redis"
|
REDIS_URL="redis://CloudSearch_Redis:6379"
|
||||||
PROFILE="--profile full"
|
PROFILE="--profile full"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 生成 .env
|
# 生成 .env
|
||||||
cat > .env <<EOF
|
cat > .env <<EOF
|
||||||
REDIS_URL=redis://${REDIS_HOST}:6379
|
REDIS_URL=${REDIS_URL}
|
||||||
CORS_ORIGIN=https://zy.hk.timxx.cn
|
CORS_ORIGIN=https://zy.hk.timxx.cn
|
||||||
JWT_SECRET=cloudsearch-jwt-secret-2024
|
JWT_SECRET=cloudsearch-jwt-secret-2024
|
||||||
ADMIN_PASSWORD=0nL5kLhMIJ1121PYmQb25A
|
ADMIN_PASSWORD=0nL5kLhMIJ1121PYmQb25A
|
||||||
|
|||||||
@@ -19,13 +19,6 @@ export function getDb(): Database.Database {
|
|||||||
db.pragma('journal_mode = WAL');
|
db.pragma('journal_mode = WAL');
|
||||||
db.pragma('foreign_keys = ON');
|
db.pragma('foreign_keys = ON');
|
||||||
|
|
||||||
// Performance indexes (IF NOT EXISTS ensures idempotent)
|
|
||||||
db.exec(`
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_cc_type_active ON cloud_configs(cloud_type, is_active);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_cc_uid ON cloud_configs(cookie_uid);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_cc_verification ON cloud_configs(verification_status);
|
|
||||||
`);
|
|
||||||
|
|
||||||
runMigrations(db);
|
runMigrations(db);
|
||||||
seedAdmin(db);
|
seedAdmin(db);
|
||||||
|
|
||||||
@@ -131,6 +124,14 @@ function runMigrations(db: Database.Database): void {
|
|||||||
migrateSaveRecords(db);
|
migrateSaveRecords(db);
|
||||||
migrateContentCache(db);
|
migrateContentCache(db);
|
||||||
migrateCloudConfigs(db);
|
migrateCloudConfigs(db);
|
||||||
|
|
||||||
|
// Performance indexes on cloud_configs (after all columns exist)
|
||||||
|
db.exec(`
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_cc_type_active ON cloud_configs(cloud_type, is_active);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_cc_uid ON cloud_configs(cookie_uid);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_cc_verification ON cloud_configs(verification_status);
|
||||||
|
`);
|
||||||
|
|
||||||
cleanupOldSaveRecords(db);
|
cleanupOldSaveRecords(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user