model.util.export ================= .. py:module:: model.util.export .. autoapi-nested-parse:: Utility script to export a scenario to a file. Attributes ---------- .. autoapisummary:: model.util.export.ALL_CLASSES_WITH_SCENARIO_ID model.util.export.ALL_PURE_ASSOC_CLASSES model.util.export.ALL_TABLE_CLASSES model.util.export.args Functions --------- .. autoapisummary:: model.util.export.start_counting_foreign_keys_at model.util.export.get_or_update_max_sequence_number model.util.export.disconnect_obj model.util.export.extract_scenario Module Contents --------------- .. py:data:: ALL_CLASSES_WITH_SCENARIO_ID .. py:data:: ALL_PURE_ASSOC_CLASSES .. py:data:: ALL_TABLE_CLASSES .. py:function:: start_counting_foreign_keys_at(start, objs) Take a collection of related objects, and set the foreign key IDs on the local and remote side of each relationship to values >= the given start value. This is useful when importing a scenario, as it allows to set the IDs of the objects to be imported to values that are not already present in the database. :param start: A dictionary containing the starting value for each class. :param objs: A list of Base objects. :return: The same list of Base objects, but with the foreign key IDs set to values >= the given start value. .. py:function:: get_or_update_max_sequence_number(conn, do_update = False) Loads the maximum sequence number for each table in the database. Can be used to determine the starting point for the sequence numbers when importing a scenario. Or to fix the sequence numbers after importing a scenario. :param conn: An open database connection (PostgreSQL or SQLite). :param do_update: If True, the sequence counters will also be updated in the database to continue counting after the maximum sequence number. :return: A dictionary containing the maximum sequence number for each table. .. py:function:: disconnect_obj(obj) Take an object and disconnect it from the database session. This will make it a pure Python object. This is done by - setting the primary key to None - setting the object to transient state - setting all ids for the foreign keys to None :param obj: An SQLAlchemy object. :return: The same object, but disconnected from the database session. .. py:function:: extract_scenario(scenario_id, session) Extracts the scenario with the given ID from the database. It will be turned into a set of Base objects, which are no longer attached to the database. :param scenario_id: The ID of the scenario to extract. :param session: An active database session. :return: A list of Base objects representing the scenario. .. py:data:: args