GeoHealthCheck
GeoHealthCheck copied to clipboard
Generic export/import of database data
Though we can dump/restore using the DB, it may be very useful to have a simple export/import facility. YAML is simple enough. In another Flask project I used sqla_yaml_fixtures to import YAML files into a SQLAlchemy DB.
This could be useful to bulk import e.g. Resources from Metadata but also as backup/restore via the GUI and a new and simpler format for Test fixtures.
To export I used a minimal Jinja2 template to generate a sqla_yaml_fixtures compatible YAML file (data contains all data as an array of SQLAlchemy tuples, with 0: SQLA Object Class, 1: the SQLA Objects, 2: the SQLA Class Columns, 'id' is mapped to __key__):
{% for d in data %}
{{ d[0] }}:
{% for rec in d[1] %}
- __key__: {{ d[0] }}{{ rec['id'] }}
{%- for col in d[2] -%}
{% if col != 'id' %}
{{ col }}: {{ rec[col] -}}
{% endif %}
{%- endfor %}
{%- endfor %}
{% endfor %}
One issue may be PostGIS columns though...