Skip to content

Change Joined to Single Table Inheritance

schmidni requested to merge feature/single_table_inheritance into develop

@sarsonl

I noticed that the delete cascades still don't work for a couple of tables, for example the SeismicCatalog, so I investigated and found the reason:

ORM-enabled UPDATEs and DELETEs do not handle joined table inheritance automatically. If the operation is against multiple tables, typically individual UPDATE / DELETE statements against the individual tables should be used.

The same is true for the database level cascade.

Since we don't need a joined table inheritance for Settings and Catalogs, I just changed it to Single Table Inheritance.

Also, for the Settings class, your docstring actually said it would be a Single Table Inheritance, which it wasn't. Also, your setting on the table extend_existing=True is incorrect. I know that the error says to fix it this way, however the problem lies with missconfigured tablename. Our Base class adds automatically a __tablename__. This fails to give the correct tablename when using inheritance. For joined table inheritance the tablename needs to be explicitly set, for single table inheritance it needs to be explicitly 'unset'. Don't worry though, it took me about 2 hours to figure that out on my other project....

The Model and ModelRun constructs are not quite as easy to change. Let's look at it at a later point (I'd like to look at the whole Hazard part of the datamodel again once we get there). We could probably have a think about it then. Just know for the moment, that the ModelRun and Model table don't get deleted when deleting SeismicityModel or SeismicityModelRun, and also not if for example the parent project or forecast get deleted.

Removed the datetime de- and encoder since its not used anywhere.

Merge request reports