SKILL.md--- name: database-operation version: 3 description: >- Use this skill when you need to inspect, query, maintain, or carefully modify the MoviePilot database. This skill uses the bundled scripts/mp-db.py helper, which reads MoviePilot local settings itself and never requires database passwords or full PostgreSQL DSNs in the agent prompt. Applicable scenarios include data statistics, counts, aggregations, inspecting or fixing records, cleanup requests, and questions like "how many downloads", "show site stats", "delete old records", or "why is this subscription stuck". --- # Database Operation > All script paths are relative to this skill file. Use `scripts/mp-db.py` for all database access. Do not extract database passwords, API tokens, or full PostgreSQL DSNs from the prompt. The script reads MoviePilot local settings and connects to SQLite or PostgreSQL internally. ## Scope And Boundaries This skill is the direct SQL boundary. It is implemented as a Python script and is appropriate when the agent must inspect records, run data statistics, repair stuck state, or perform an explicitly requested database update. Prefer safer product surfaces first: | Request | Preferred skill | |---|---| | Normal local MoviePilot product operation exposed as an MCP tool | `moviepilot-cli` | | Direct REST endpoint call | `moviepilot-api` | | Slash commands or plugin/system command dispatch | `command-dispatch` | | Manual file organization | `organize-files` | | Retry failed transfer history records | `transfer-failed-retry` | Use this skill as the final fallback for data access or mutation. It may run `SELECT`, `INSERT`, `UPDATE`, `DELETE`, and schema-changing statements through the bundled script, but broad or destructive writes still require explicit user authorization. ## Commands List tables: ```bash python scripts/mp-db.py tables ``` Show table schema: ```bash python scripts/mp-db.py schema downloadhistory ``` Run a read query: ```bash python scripts/mp-db.py query "SELECT COUNT(*) AS total FROM downloadhistory" ``` Read SQL from stdin or a file: ```bash python scripts/mp-db.py query --file /path/to/query.sql ``` Run a write statement: ```bash python scripts/mp-db.py write "UPDATE subscribe SET state = 'S' WHERE id = 123" ``` `query --write` is also supported for compatibility, but prefer the `write` subcommand for `INSERT`, `UPDATE`, `DELETE`, and schema changes. ## Workflow 1. Prefer existing MoviePilot tools or APIs for normal product workflows. 2. Use this skill for direct database inspection only when no existing tool covers the request. 3. For unknown schema, run `tables` first, then `schema <table>`. 4. For `SELECT` queries, execute directly with a narrow projection and an explicit `LIMIT` when reading rows. 5. For `INSERT`, `UPDATE`, `DELETE`, `DROP`, `ALTER`, `TRUNCATE`, `CREATE`, or `REPLACE`, use `write` and report the affected row count. ## Built-in