Initial project commit
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import asyncio
|
||||
from dataclasses import dataclass
|
||||
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
|
||||
from app.main import app
|
||||
|
||||
|
||||
@dataclass
|
||||
class CheckResult:
|
||||
method: str
|
||||
path: str
|
||||
status: int
|
||||
|
||||
|
||||
async def run_checks() -> list[CheckResult]:
|
||||
results: list[CheckResult] = []
|
||||
transport = ASGITransport(app=app)
|
||||
async with AsyncClient(transport=transport, base_url="http://testserver") as client:
|
||||
login = await client.post(
|
||||
"/api/v1/admin/auth/login",
|
||||
json={"account": "13900000001", "password": "demo123456"},
|
||||
)
|
||||
if login.status_code != 200:
|
||||
raise RuntimeError(f"admin login failed: {login.status_code} {login.text}")
|
||||
token = login.json()["access_token"]
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
|
||||
checks: list[tuple[str, str]] = [
|
||||
("GET", "/api/v1/admin/module-design"),
|
||||
("GET", "/api/v1/admin/spots?page=1&page_size=5"),
|
||||
("GET", "/api/v1/admin/events?page=1&page_size=5"),
|
||||
("GET", "/api/v1/admin/shooting?page=1&page_size=5"),
|
||||
("GET", "/api/v1/admin/promotions?page=1&page_size=5"),
|
||||
("GET", "/api/v1/admin/app-nav-configs?page=1&page_size=5"),
|
||||
("GET", "/api/v1/admin/membership/plans?page=1&page_size=5"),
|
||||
("GET", "/api/v1/admin/membership/user-memberships?page=1&page_size=5"),
|
||||
("GET", "/api/v1/admin/points/ledger?page=1&page_size=5"),
|
||||
("GET", "/api/v1/admin/notifications?page=1&page_size=5"),
|
||||
("GET", "/api/v1/admin/reports?page=1&page_size=5"),
|
||||
("GET", "/api/v1/admin/audit-logs?page=1&page_size=5"),
|
||||
("GET", "/api/v1/admin/system-configs?page=1&page_size=5"),
|
||||
("GET", "/api/v1/admin/user-options"),
|
||||
("GET", "/api/v1/admin/spot-tag-options"),
|
||||
("GET", "/api/v1/admin/promotion-link-options?link_type=spot"),
|
||||
]
|
||||
for method, path in checks:
|
||||
resp = await client.request(method, path, headers=headers)
|
||||
results.append(CheckResult(method=method, path=path, status=resp.status_code))
|
||||
|
||||
for list_path, detail_template in [
|
||||
("/api/v1/admin/spots?page=1&page_size=1", "/api/v1/admin/spots/{id}"),
|
||||
("/api/v1/admin/events?page=1&page_size=1", "/api/v1/admin/events/{id}"),
|
||||
("/api/v1/admin/shooting?page=1&page_size=1", "/api/v1/admin/shooting/{id}"),
|
||||
]:
|
||||
list_resp = await client.get(list_path, headers=headers)
|
||||
results.append(CheckResult(method="GET", path=list_path, status=list_resp.status_code))
|
||||
if list_resp.status_code != 200:
|
||||
continue
|
||||
items = list_resp.json().get("items", [])
|
||||
if not items:
|
||||
continue
|
||||
detail_path = detail_template.format(id=items[0]["id"])
|
||||
detail_resp = await client.get(detail_path, headers=headers)
|
||||
results.append(CheckResult(method="GET", path=detail_path, status=detail_resp.status_code))
|
||||
return results
|
||||
|
||||
|
||||
async def main():
|
||||
results = await run_checks()
|
||||
has_error = False
|
||||
for item in results:
|
||||
line = f"{item.method} {item.path} -> {item.status}"
|
||||
print(line)
|
||||
if item.status >= 400:
|
||||
has_error = True
|
||||
if has_error:
|
||||
raise SystemExit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
# Database backup script for ciyuan_viewfinder
|
||||
# Usage: ./scripts/backup_db.sh
|
||||
# Recommended: add to crontab for daily backups
|
||||
# Example crontab: 0 3 * * * /path/to/server/scripts/backup_db.sh
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
SERVER_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
|
||||
# Load .env
|
||||
if [ -f "$SERVER_DIR/.env" ]; then
|
||||
export $(grep -v '^#' "$SERVER_DIR/.env" | xargs)
|
||||
fi
|
||||
|
||||
DB_HOST="${DB_HOST:-10.0.10.11}"
|
||||
DB_PORT="${DB_PORT:-5432}"
|
||||
DB_NAME="${DB_NAME:-ciyuan_viewfinder}"
|
||||
DB_USER="${DB_USER:-shiran}"
|
||||
|
||||
BACKUP_DIR="${BACKUP_DIR:-$SERVER_DIR/backups}"
|
||||
RETENTION_DAYS="${RETENTION_DAYS:-30}"
|
||||
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
|
||||
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
||||
BACKUP_FILE="$BACKUP_DIR/${DB_NAME}_${TIMESTAMP}.sql.gz"
|
||||
|
||||
echo "[$(date)] Starting backup of $DB_NAME..."
|
||||
|
||||
pg_dump -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" \
|
||||
--no-owner --no-acl --format=plain \
|
||||
| gzip > "$BACKUP_FILE"
|
||||
|
||||
echo "[$(date)] Backup saved to $BACKUP_FILE ($(du -sh "$BACKUP_FILE" | cut -f1))"
|
||||
|
||||
# Cleanup old backups
|
||||
find "$BACKUP_DIR" -name "${DB_NAME}_*.sql.gz" -mtime +$RETENTION_DAYS -delete
|
||||
echo "[$(date)] Cleaned up backups older than $RETENTION_DAYS days"
|
||||
|
||||
echo "[$(date)] Backup complete."
|
||||
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
# Database restore script
|
||||
# Usage: ./scripts/restore_db.sh <backup_file.sql.gz>
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "Usage: $0 <backup_file.sql.gz>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BACKUP_FILE="$1"
|
||||
|
||||
if [ ! -f "$BACKUP_FILE" ]; then
|
||||
echo "Error: File not found: $BACKUP_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
SERVER_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
|
||||
if [ -f "$SERVER_DIR/.env" ]; then
|
||||
export $(grep -v '^#' "$SERVER_DIR/.env" | xargs)
|
||||
fi
|
||||
|
||||
DB_HOST="${DB_HOST:-10.0.10.11}"
|
||||
DB_PORT="${DB_PORT:-5432}"
|
||||
DB_NAME="${DB_NAME:-ciyuan_viewfinder}"
|
||||
DB_USER="${DB_USER:-shiran}"
|
||||
|
||||
echo "[$(date)] WARNING: This will overwrite the current database '$DB_NAME'."
|
||||
read -p "Are you sure? (yes/no): " confirm
|
||||
if [ "$confirm" != "yes" ]; then
|
||||
echo "Aborted."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "[$(date)] Restoring from $BACKUP_FILE..."
|
||||
|
||||
gunzip -c "$BACKUP_FILE" | psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME"
|
||||
|
||||
echo "[$(date)] Restore complete."
|
||||
Reference in New Issue
Block a user