An open API service indexing awesome lists of open source software.

https://github.com/anki-code/metabase-sql-wrapper

This is a docker-container based on Metabase container that automatically saves Metabase H2 database to SQL-file and creates Metabase H2 database from SQL-file.
https://github.com/anki-code/metabase-sql-wrapper

docker metabase sql xonsh

Last synced: about 1 month ago
JSON representation

This is a docker-container based on Metabase container that automatically saves Metabase H2 database to SQL-file and creates Metabase H2 database from SQL-file.

Awesome Lists containing this project

README

        


metabase-sql-wrapper is a Docker container based on the Metabase container. It automatically saves the Metabase H2 database to an SQL file when the container stops and recreates the H2 database from the SQL file when the container starts (if the database does not already exist).


This allows to save the Metabase H2 database SQL-file to Git, versioning changes
and restore the database from SQL-file.


If you like the idea click ⭐ on the repo and stay tuned.

## Run container
```shell script
git clone https://github.com/anki-code/metabase-sql-wrapper
cd metabase-sql-wrapper
docker-compose up
```

## How it works

1. [`docker-compose.yml`](https://github.com/anki-code/metabase-sql-wrapper/blob/master/docker-compose.yml) file has environment variables:

```shell script
MB_DB_FILE: /data/metabase
MB_DB_INIT_SQL_FILE: /data/metabase.db.sql # (optional) used to build the DB if MB_DB_FILE doesn't exists
MB_DB_SAVE_TO_SQL_FILE: /data/metabase.db.sql # (optional) used to save SQL when container was stopped
```

2. `docker-compose up` runs `run.xsh` with [xonsh shell](https://xon.sh/) wrapper that catches
the docker signals and environment variables and do saving or creating the Metabase DB after stopping
or before starting the container.

3. If `MB_DB_INIT_SQL_FILE` is set and `MB_DB_FILE` directory doesn't exists then before running Metabse
the database will be created from the SQL-file.

4. If `MB_DB_SAVE_TO_SQL_FILE` is set and the container will get stop/restart signal then the database will be saved
to SQL-file after Metabase has been stopped.

This way you can run container, save your queries to Metabase, stop the container and commit it to Git.

## Cleaning the database before commit to Git

By default Metabase writes logs and history to the database. To clean this before commit to Git you can
use the [`metabase-db-clean.sql`](https://github.com/anki-code/metabase-sql-wrapper/blob/473f3fd23829216cc4384df3bbbda5a3dcd7eec6/metabase-db-clean.sql) script:
```bash
java -cp metabase.jar org.h2.tools.RunScript -url jdbc:h2:./metabase.db -script /path/to/repository/metabase-db-clean.sql
```

## Links

* This container based on [docker-xonsh-wrapper](https://github.com/anki-code/docker-xonsh-wrapper)