itmi-id / metabase-migration

Script to update and duplicate question/card in Metabase

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

version

Metabase Migration

Script to update and duplicate Question in Metabase using Metabase REST API.

Here is a blog post on how we approach managing multiple environments in Embedded Metabase https://medium.com/itmi-engineering/managing-multiple-environments-with-embedded-metabase-87b074ea9aad

How to use

Clone this repository and npm install

Create .env file in root folder that contains

METABASE_BASE_URL=xxx
METABASE_USERNAME=xxx
METABASE_PASSWORD=xxx

# Optionaly, when performing actions on the source Metabase instance above to a destination/second Metabase instance, add the following
DESTINATION_METABASE_BASE_URL=xxx
DESTINATION_METABASE_USERNAME=xxx
DESTINATION_METABASE_PASSWORD=xxx

Update Question

node app.js update —-originId=[question_id] --destId=[question_id] —-databaseId=[database_id]

Duplicate Question

node app.js duplicate —-questionId=[question_id] --collectionId=[collection_id] -—name=[name] -—databaseId=[database_id]

--name is optional, if it's not provided it will use the same question name.

Duplicate Question on Destination Instance

node app.js duplicateAcross —-questionId=[question_id] --collectionId=[collection_id] -—name=[name] -—databaseId=[database_id]

--name is optional, if it's not provided it will use the same question name.

Work in Progress

  • Duplicating or updating question between different metabase instance
  • Duplicating or updating Dashboard

Testing with Custom Metabase image just past initial setup

** Note: this container should be used for testing purposes only!!! **

Use the image already generated using the steps below (assumed to be using in the docker-compose.yaml file):

docker-compose up

You should then have a source localhost:3000 and destination localhost:3001 container to execute commands against. Add the following test .env file to your project to use them:

# source instance
METABASE_BASE_URL=http://localhost:3000/api
METABASE_USERNAME=test@test.com
METABASE_PASSWORD=test1234

# destination instance
DESTINATION_METABASE_BASE_URL=http://localhost:3001/api
DESTINATION_METABASE_USERNAME=test@test.com
DESTINATION_METABASE_PASSWORD=test1234

Sanity check by running the following: node app.js duplicateAcross --questionId=6 --collectionId=2 --name="testing coordinates copy across instances" --databaseId=1

If successful, you should be able to view the question @ localhost:3001/collection/2

Steps to generate a post install metabse image

The following are the steps followed to generate the image used in the docker-compose.yaml:

  1. From cli, run docker run -it -p 3000:3000 --name metabase metabase/metabase[:TAG]
  2. Once container is launched, visit localhost:3000/setup
  3. Click Let's get started
  4. Select English as preferred language
  5. Enter the following:
    • First name: test
    • Last name: test
    • Email: test@test.com
    • Create a password: test1234
    • Your company or team name: test
  6. Click Next
  7. Select I'll add my data later
  8. Click Next
  9. Click Take me to Metabase
  10. Under the TRY THESE X-RAYS BASED ON YOUR DATA. section, click A look at your People table
  11. Click Save this
  12. Verify that you have a new collection (id 2 in URL) called Automatically Generated Dashboards
  13. Verify that you have a new collection (id 3 in URL) called A look at your People table
  14. Back on the cli, run the following to generate a snapshot of the image: docker commit metabase mafs/metabase-custom[:TAG]
  15. Push your image to dockerhub: docker push mafs/metabase-custom[:TAG]
  16. Launch 2 instances (a source and destination instance) to run tests against containers: docker-compose up

About

Script to update and duplicate question/card in Metabase

License:MIT License


Languages

Language:JavaScript 100.0%