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
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
node app.js update —-originId=[question_id] --destId=[question_id] —-databaseId=[database_id]
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.
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.
- Duplicating or updating question between different metabase instance
- Duplicating or updating Dashboard
** 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
[email protected]
METABASE_PASSWORD=test1234
# destination instance
DESTINATION_METABASE_BASE_URL=http://localhost:3001/api
[email protected]
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
The following are the steps followed to generate the image used in the docker-compose.yaml
:
- From cli, run
docker run -it -p 3000:3000 --name metabase metabase/metabase[:TAG]
- Once container is launched, visit localhost:3000/setup
- Click
Let's get started
- Select
English
as preferred language - Enter the following:
- First name:
test
- Last name:
test
- Email:
[email protected]
- Create a password:
test1234
- Your company or team name:
test
- First name:
- Click
Next
- Select
I'll add my data later
- Click
Next
- Click
Take me to Metabase
- Under the
TRY THESE X-RAYS BASED ON YOUR DATA.
section, clickA look at your People table
- Click
Save this
- Verify that you have a new collection (id 2 in URL) called
Automatically Generated Dashboards
- Verify that you have a new collection (id 3 in URL) called
A look at your People table
- Back on the cli, run the following to generate a snapshot of the image:
docker commit metabase mafs/metabase-custom[:TAG]
- Push your image to dockerhub:
docker push mafs/metabase-custom[:TAG]
- Launch 2 instances (a source and destination instance) to run tests against containers:
docker-compose up