Any time database-related activity is required.
.env via DATABASE_URL (see SQLALCHEMY_DATABASE_URI / DATABASE_URL in config.py).pytest note below).TEST_DATABASE_URL (used by TestingConfig in config.py).db from utils_db/database.py. Do NOT create a new instance in app.py.utils_db/.temp/ first, then promote reusable ones into utils_db/.TestingConfig disables CSRF (WTF_CSRF_ENABLED = False) specifically for tests..env..env
User passwords in DB are hashed. Hash is stored in the pw_hashed column..roo/docs/database_schema.mdmodels/models_*.py (eg, models/models_user.py)utils_db/database.pyutils_db/schema_inspector.pyutils_db/schema_compare.py (writes reports to temp/)Reuse existing tools in utils_db/ before writing new ones:
utils_db/user_password_utils.pyutils_db/user_management_utils.pyutils_db/media_utils.pyThe formal Source of Truth (SoT) hierarchy for database schema information:
models/models_user.py).roo/docs/database_schema.md (generated)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.
When making schema or data changes, follow this workflow in order:
utils_db/ for a suitable or near-suitable script first; reuse/extend if possible.temp/ first..py utility in utils_db/.models/models_*.py.python utils_db/schema_inspector.py generate-docs to update .roo/docs/database_schema.md..roo/docs/pgdb_changes.md.The utils_db/schema_inspector.py tool provides commands for schema management:
introspect - Inspect live database schema and display structurecompare-db-models - Compare live database against SQLAlchemy models to identify discrepanciescompare-models-doc - Compare SQLAlchemy models against .roo/docs/database_schema.mdgenerate-docs - Generate/update .roo/docs/database_schema.md from current database statereport - Generate discrepancy reports under .roo/reports/ (JSON and Markdown)validate - Verify schema documentation is up-to-date with the databaseUsage notes:
.env) and initializes db from utils_db/database.py..roo/reports/ when run.Usage examples:
python utils_db/schema_inspector.py introspectpython utils_db/schema_inspector.py compare-db-modelspython utils_db/schema_inspector.py compare-models-docpython utils_db/schema_inspector.py generate-docspython utils_db/schema_inspector.py validatepytest against the live PostgreSQL database.TestingConfig (config.py), CSRF is disabled (WTF_CSRF_ENABLED = False).