How-to guides#

SQL files#

The examples below use the view_data_NAME schema and the default database connection settings. Change these as needed.

Run a specific file#

To run, for example, the planning_tmp.sql file:

psql 'dbname=ocdskingfisher user=ocdskingfisher options=--search-path=view_data_NAME' -f planning_tmp.sql

Note

See issue #167 about developer tools.

Time SQL statements#

Add the -c '\timing' option to a psql command, before any -f options. For example:

psql 'dbname=ocdskingfisher user=ocdskingfisher options=--search-path=view_data_NAME' -c '\timing' -f planning_tmp.sql

Drop tables and views#

To undo a SQL file, drop the tables and views that it creates.

To undo the field_counts routine, run:

DROP TABLE field_counts;

Documentation files#

Update the database tables reference#

Database tables reference displays the CSV files in the docs/definitions/ directory. To create and/or update the CSV files, run (replacing NAME below):

./manage.py dev docs-table-ref NAME

Then, for any new CSV file, manually add a new sub-section to docs/database.rst under an appropriate section.

Update the Entity Relationship Diagram#

Add a schema with the --tables-only option:

./manage.py add 123 diagram --tables-only

Use SchemaSpy to generate a diagram, copying the output to docs/_static/erd.png.