AgentSkillsCN

debug-local-database

每当智能体需要从本地 PostgreSQL 数据库中查询、检查或调试数值时,务必使用此技能。这包括核查用户数据、草稿状态、实验室分配、学生排名、教师选择,或其他存储于数据库中的信息。

SKILL.md
--- frontmatter
name: debug-local-database
description: >
  MUST be used whenever the agent needs to query, inspect, or debug values from the local
  PostgreSQL database. This includes checking user data, draft states, lab assignments,
  student rankings, faculty choices, or any other database-stored information.
user-invocable: false
disable-model-invocation: false
allowed-tools:
  - Read
  - Bash(docker compose exec postgres psql:*)

Debug Database Skill

Query and inspect the local PostgreSQL database for debugging.

IMPORTANT: All queries MUST be READ-ONLY (SELECT statements only). Do NOT execute INSERT, UPDATE, DELETE, TRUNCATE, DROP, or any other dangerous data-modifying statements unless the user EXPLICITLY requests a write operation.

Prerequisites

Before writing queries, read the database schema files to understand table structures:

  • src/lib/server/database/schema/app.ts - Main app tables (drap schema)
  • src/lib/server/database/schema/auth.ts - Session tables (auth schema)
  • src/lib/server/database/schema/email.ts - Email sender tables (email schema)

Connection

bash
docker compose exec postgres psql

No auth flags needed (local Unix socket with trust auth). The database has three schemas:

SchemaPurpose
drapApp data (users, labs, drafts, rankings, choices)
authSessions
emailEmail sender configuration

Key Tables

drap Schema

TablePurpose
drap.userAll users (students, faculty, admins)
drap.labResearch labs
drap.draftDraft instances with round state
drap.student_rankStudent ranking submission timestamps
drap.student_rank_labIndividual lab rankings per student
drap.faculty_choiceFaculty round selections (header)
drap.faculty_choice_userStudents selected by faculty per round
drap.lab_member_viewView joining faculty choices with user info
drap.active_lab_viewView of non-deleted labs

auth Schema

TablePurpose
auth.sessionActive user sessions

email Schema

TablePurpose
email.candidate_senderUsers who have authorized email sending
email.designated_senderCurrently active email sender

SQL Scripts

Pre-written queries for common debugging scenarios:

ScriptUse Case
user-registered.sqlCheck if a user with given email exists
user-ranking-submission.sqlWhen a student submitted rankings
student-lab-rankings.sqlGet student's ranked lab preferences
faculty-round-choice.sqlWhat faculty chose in a specific round
pending-students.sqlStudents still awaiting selection
lottery-students.sqlStudents who entered the lottery
lab-assignments.sqlCurrent lab member assignments
draft-status.sqlCurrent draft state and round
active-sessions.sqlDebug user sessions
email-senders.sqlEmail sender configuration

SQL Conventions

  • Use $placeholder$ syntax for parameters (replace with actual values)
  • Add explicit type casts: $email$::text, $user_id$::ulid, $draft_id$::bigint
  • Always qualify table names with schema (e.g., drap.user)

Example Usage

bash
# List all tables
docker compose exec postgres psql -c '\dt drap.*'

# Run a query
docker compose exec postgres psql -c "SELECT * FROM drap.user WHERE email = 'test@up.edu.ph'"

# Interactive mode
docker compose exec postgres psql