feat: Add Outdoor Fair Attendee and Device management

- Implemented Outdoor Fair Attendee and Device entities, including their respective controllers, services, and mappers.
- Added statistics endpoint for Outdoor Fair data, allowing aggregation by day, week, month, or year.
- Introduced SQL scripts for creating tables and mock data for attendees and devices.
- Created a write-capable script for executing DML/DDL statements against the SHZ HighGo database.
- Enhanced the existing query capabilities to support both read and write operations.
This commit is contained in:
2026-06-26 11:26:04 +08:00
parent 7ca2d878cc
commit 0ccfb6e6dc
15 changed files with 884 additions and 5 deletions

View File

@@ -1,13 +1,18 @@
---
name: query-shz-highgo
description: Query the SHZ HighGo Security Enterprise Edition database through its SSH gateway using a guarded read-only psql workflow. Use when Claude Code is working in the shz-backend project and needs to inspect database schemas, tables, columns, row counts, or application data; diagnose data-related behavior; or execute SELECT, WITH, SHOW, or EXPLAIN statements against the project's HighGo database.
description: Run SQL against the SHZ HighGo Security Enterprise Edition database through its SSH gateway. Use when Claude Code is working in the shz-backend project and needs to inspect schemas, tables, columns, row counts, or application data; diagnose data-related behavior; or execute SELECT/WITH/SHOW/EXPLAIN. Also supports write operations — INSERT, UPDATE, DELETE, MERGE, CREATE, ALTER, DROP, TRUNCATE, GRANT, REVOKE — when the user explicitly asks to add, modify, delete, or otherwise change data or schema.
---
# Query SHZ HighGo
# SHZ HighGo SQL
Use the bundled script to run read-only SQL through the configured SSH gateway.
Two bundled scripts run SQL through the configured SSH gateway:
## Query workflow
- `scripts/query.sh`**read-only**. Default for inspection and diagnostics.
- `scripts/modify.sh`**write-capable**. Use only when an actual change is intended and the user has asked for it.
Both set `search_path` to `shz,public`, apply a 30-second `statement_timeout`, reject multiple statements in one call, and base64-encode the SQL over the SSH channel. `query.sh` additionally enforces database-level `default_transaction_read_only=on` and accepts only `SELECT/WITH/SHOW/EXPLAIN`.
## Query workflow (read-only)
1. Form the narrowest useful query. Add a small `LIMIT` when inspecting rows.
2. For unfamiliar tables, inspect `information_schema.columns` before selecting business data.
@@ -19,7 +24,26 @@ Use the bundled script to run read-only SQL through the configured SSH gateway.
4. Summarize the result and distinguish returned facts from inferences.
The script accepts only statements beginning with `SELECT`, `WITH`, `SHOW`, or `EXPLAIN`, rejects multiple statements, sets `search_path` to `shz,public`, enforces database-level read-only mode, and applies a 30-second timeout. Never bypass these controls or perform writes unless the user explicitly requests a separate write-capable workflow.
## Modify workflow (writes)
⚠️ These statements change data or schema on a production database. Confirm the exact statement with the user before running it, and prefer a `WHERE` clause or scoped target. Read unfamiliar tables with `query.sh` first.
1. Inspect the target with `query.sh` (columns, existing rows) so the statement is well-formed.
2. Run the write:
```bash
.claude/skills/query-shz-highgo/scripts/modify.sh "INSERT INTO shz.some_table (col) VALUES ('val')"
.claude/skills/query-shz-highgo/scripts/modify.sh "UPDATE shz.some_table SET col = 'val' WHERE id = 1"
.claude/skills/query-shz-highgo/scripts/modify.sh "DELETE FROM shz.some_table WHERE id = 1"
.claude/skills/query-shz-highgo/scripts/modify.sh "CREATE TABLE shz.example (id bigint PRIMARY KEY)"
```
3. Verify the effect with a follow-up `query.sh` `SELECT` and report rows affected.
Notes:
- Only one statement per call. To run several, invoke the script multiple times.
- Transactions across calls are NOT supported (each call is its own session). psql autocommits each statement.
- `DROP`/`TRUNCATE`/`DELETE` without a `WHERE` are destructive — re-state the impact to the user and wait for explicit go-ahead.
## Schema discovery

View File

@@ -0,0 +1,46 @@
#!/usr/bin/env bash
set -euo pipefail
# Write-capable counterpart to query.sh. Runs a single DML/DDL statement
# against the SHZ HighGo database through the SSH gateway. Read-only mode
# is NOT applied — only use when an actual change is intended.
skill_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
password_file="${HIGHGO_PASSWORD_FILE:-$skill_dir/.password}"
ssh_host="root@124.243.245.42"
psql_path="/opt/HighGo4.5.7-see/bin/psql"
db_host="39.98.44.136"
db_port="6023"
db_name="highgo"
db_user="sysdba"
if [[ ! -r "$password_file" ]]; then
echo "HighGo password file is missing or unreadable: $password_file" >&2
exit 2
fi
if [[ $# -eq 0 ]]; then
echo "Usage: $0 'INSERT ...' | 'UPDATE ...' | 'DELETE ...' | 'CREATE ...' | 'ALTER ...' | 'DROP ...'" >&2
exit 2
fi
sql="$*"
# Reject multiple statements — prevents a trailing destructive command from
# being smuggled in after the intended one. A single optional trailing
# semicolon is tolerated.
sql_without_final_semicolon="${sql%;}"
if [[ "$sql_without_final_semicolon" == *';'* ]]; then
echo "Rejected: multiple SQL statements are not allowed. Run them one at a time." >&2
exit 3
fi
password="$(<"$password_file")"
sql_base64="$(printf '%s' "$sql" | base64 | tr -d '\n')"
{
printf '%s\n' "$password"
printf '%s\n' "$sql_base64"
} | ssh -o BatchMode=yes -o ConnectTimeout=10 "$ssh_host" \
"read -r PGPASSWORD; read -r SQL_BASE64; export PGPASSWORD; export PGOPTIONS='-c search_path=shz,public -c statement_timeout=30000'; SQL=\$(printf '%s' \"\$SQL_BASE64\" | base64 -d); exec '$psql_path' -X --no-psqlrc -h '$db_host' -p '$db_port' -U '$db_user' -d '$db_name' -v ON_ERROR_STOP=1 -P pager=off -c \"\$SQL\""