GithubHelp home page GithubHelp logo

anki-code / metabase-sql-wrapper Goto Github PK

View Code? Open in Web Editor NEW
42.0 1.0 2.0 33 KB

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.

License: BSD 3-Clause "New" or "Revised" License

Dockerfile 7.80% Python 92.20%
metabase docker xonsh sql

metabase-sql-wrapper's Introduction

metabase-sql-wrapper is a docker-container based on Metabase container
that automatically saves Metabase H2 database to SQL-file (on docker stop)
and creates Metabase H2 database from SQL-file (on docker start if the database doesn't exists).

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

git clone https://github.com/anki-code/metabase-sql-wrapper
cd metabase-sql-wrapper
docker-compose up

How it works

  1. docker-compose.yml file has environment variables:

    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 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 script:

java -cp metabase.jar org.h2.tools.RunScript -url jdbc:h2:./metabase.db -script /path/to/repository/metabase-db-clean.sql

Links

metabase-sql-wrapper's People

Contributors

anki-code avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.