geopython / geopython/GeoHealthCheck

Generic export/import of database data

Open
#120 0 comments 0 reactions 1 assignee Claimed by @justb4 View on GitHub
enhancement
Dominant language
Python
Stars
92
Forks
75
PR merge metrics
No merged PRs in 30d

Description

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](https://github.com/schettino72/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](https://github.com/schettino72/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...

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.