Claude-skill-registry database-use
Any time database-related activity is required.
install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/database-use" ~/.claude/skills/majiayu000-claude-skill-registry-database-use && rm -rf "$T"
manifest:
skills/data/database-use/SKILL.mdsource content
Database use instructions
Configuration & Standards
- Engine: PostgreSQL only (Port: 5433).
- Connection string: sourced from
via.env
(seeDATABASE_URL
/SQLALCHEMY_DATABASE_URI
inDATABASE_URL
).config.py - Testing DB:
- By default tests also use the live DB (see
note below).pytest - Optional override:
(used byTEST_DATABASE_URL
inTestingConfig
).config.py
- By default tests also use the live DB (see
- SQLAlchemy instance: Import
fromdb
. Do NOT create a new instance inutils_db/database.py
.app.py - Scripts location:
- Canonical database scripts/utilities live in
.utils_db/ - No ad-hoc “root scripts” in the repo root.
- Canonical database scripts/utilities live in
- Execution safety:
- Do NOT paste multi-line SQL or Python into the terminal.
- Draft ad-hoc scripts in
first, then promote reusable ones intotemp/
.utils_db/
- Testing CSRF:
disables CSRF (TestingConfig
) specifically for tests.WTF_CSRF_ENABLED = False
Credentials
- Connection credentials:
..env - Users' credentials:
User passwords in DB are hashed. Hash is stored in the pw_hashed column..env
Structure
- Schema documentation:
.roo/docs/database_schema.md - SQLAlchemy model files:
(eg,models/models_*.py
)models/models_user.py - SQLAlchemy database instance:
utils_db/database.py - Schema tools:
- Primary:
utils_db/schema_inspector.py - Supplemental:
(writes reports toutils_db/schema_compare.py
)temp/
- Primary:
Preferred Utilities
Reuse existing tools in
utils_db/ before writing new ones:
utils_db/user_password_utils.pyutils_db/user_management_utils.pyutils_db/media_utils.py
Source of Truth Hierarchy
The formal Source of Truth (SoT) hierarchy for database schema information:
- PGDB (live PostgreSQL)
- models_*.py (SQLAlchemy) (eg,
)models/models_user.py
(generated).roo/docs/database_schema.md
When there is any doubt about a column, see PGDB. If a column is needed or a column name needs to change, always ask user for permission to make the add/change.
Schema Update Workflow
When making schema or data changes, follow this workflow in order:
- Modify PGDB
- Make changes to the live database (see "Credentials" above).
- When creating a script to check or change the database:
- Do NOT paste the script into the terminal.
- Check
for a suitable or near-suitable script first; reuse/extend if possible.utils_db/ - If it’s a true one-off, draft it in
first.temp/ - If it’s reusable, create/update a
utility in.py
.utils_db/
- Update models
- Update the appropriate SQLAlchemy model file(s) under
.models/models_*.py
- Update the appropriate SQLAlchemy model file(s) under
- Regenerate documentation
- Run:
to updatepython utils_db/schema_inspector.py generate-docs
..roo/docs/database_schema.md
- Run:
- Log changes
- Record the date and change in
..roo/docs/pgdb_changes.md
- Record the date and change in
Schema Inspector Utility
The
utils_db/schema_inspector.py tool provides commands for schema management:
- Inspect live database schema and display structureintrospect
- Compare live database against SQLAlchemy models to identify discrepanciescompare-db-models
- Compare SQLAlchemy models againstcompare-models-doc.roo/docs/database_schema.md
- Generate/updategenerate-docs
from current database state.roo/docs/database_schema.md
- Generate discrepancy reports underreport
(JSON and Markdown).roo/reports/
- Verify schema documentation is up-to-date with the databasevalidate
Usage notes:
- This utility uses the configured database URL (from
) and initializes.env
fromdb
.utils_db/database.py - Some schema comparison utilities may emit reports under
when run..roo/reports/
Usage examples:
- Introspect schema:
python utils_db/schema_inspector.py introspect - Compare:
python utils_db/schema_inspector.py compare-db-models - Compare models vs docs:
python utils_db/schema_inspector.py compare-models-doc - Generate docs:
python utils_db/schema_inspector.py generate-docs - Validate docs:
python utils_db/schema_inspector.py validate
Testing
- Run tests with
against the live PostgreSQL database.pytest - In
(TestingConfig
), CSRF is disabled (config.py
).WTF_CSRF_ENABLED = False