Skip to content

How to update database definitions

ulfmueller edited this page Sep 4, 2018 · 17 revisions

This is a how-to which to create/update SQLAlchemy (ORM) definitions for the postgreSQL database. It was taken from #8

  1. Create new branch, e.g. feature/release_v0.x.y

  2. Install sqlacodegen 2.0.0 If not already installed, you have to install sqlacodegen via pip. It is important to take version 2.0.0 (or higher)

  3. Run codegen Add user, pass, server and port to script and run. I got some warnings which I ignored (not sure if there will result any problems..):
    Hint run the shell script from inside your virtual environment.

Write table schemas for demand
Write table schemas for economic
Write table schemas for emission
Write table schemas for environmental
/usr/local/lib/python3.4/dist-packages/sqlalchemy/dialects/postgresql/base.py:2783: SAWarning: Skipped unsupported reflection of expression-based index ecjrc_glc2000_rast_idx
  % idx_name)
/usr/local/lib/python3.4/dist-packages/sqlalchemy/dialects/postgresql/base.py:2783: SAWarning: Skipped unsupported reflection of expression-based index noaa_globe_rast_idx
  % idx_name)
Write table schemas for grid
Write table schemas for openstreetmap
/usr/local/lib/python3.4/dist-packages/sqlalchemy/dialects/postgresql/base.py:2790: SAWarning: Predicate of partial index osm_deu_ways_idx ignored during reflection
  % idx_name)
/usr/local/lib/python3.4/dist-packages/sqlalchemy/dialects/postgresql/base.py:2790: SAWarning: Predicate of partial index osm_deu_rels_idx ignored during reflection
  % idx_name)
Write table schemas for political_boundary
Write table schemas for reference
Write table schemas for scenario
Write table schemas for social
Write table schemas for supply
Write table schemas for weather
Write table schemas for model_draft
/usr/local/lib/python3.4/dist-packages/sqlalchemy/dialects/postgresql/base.py:2783: SAWarning: Skipped unsupported reflection of expression-based index enforce_spatially_unique_ioer_urban_share_industrial_rast
  % idx_name)
/usr/local/lib/python3.4/dist-packages/sqlalchemy/dialects/postgresql/base.py:2783: SAWarning: Skipped unsupported reflection of expression-based index ioer_urban_share_industrial_gix
  % idx_name)

Do not forget no stash your credentials!

  1. Bugfix: Add psql-specific modules / data types Some datatypes are not written by sqlacodegen which are to be added manually (example fix here).

  2. Bugfix: Map reserved 'metadata' to 'meta_data In EgoScenarioLog the attribute metadata is used. The attribute collides with the MetaData instance. So to avoid renaming the table column "metadata" in model_draft.ego_scenario_log (and accessing scripts) I mapped the table name using "meta_data" (example fix here). UPDATE: Should be fixed, please re-check in next run and if so, delete this paragraph.

  3. Bugfix: Tables ending with Bus are translated into Bu No idea where this *Bu bug (see here) comes from -> add missing s Occurrences: model_draft.py and grid.py (example fix here, here, here)
    Update occurrences can be identified by searching project-wide for "Bu'" and "Bu(" (please amend list)

  4. Bugfix: Missing representation of columns in EgoPfHvLoadPqSet. The cause of error is unfortunately not known. (example fix here) Fixed.

  5. Adjust setup.py (example here)

  6. Test it

  7. Create pull request (to dev) And give it some time to be tested by other users. (how long?)

  8. Merge pull request

  9. Delete obsolete branch feature/release_v0.x.y

Further steps concerning the release see How to release.

If you stumble upon any issues with this How-To, please amend this documentation (you may create an issue).

Clone this wiki locally