How do I select which database a query or database gets run against?

We have different copies of a database, one for each environment.
So say we have an event database for prod and one for test, both have the same tables (schema).
We want to write the SQL once only so that if the SQL changes, we only need to edit it in one place.

We are looking to use Metabase to supply some questions and dashboards but can’t figure out how to let users choose which database to run the SQL (Question/Dashboard) against.

Why is the database tied to a question/dashboard?
Can we have an option to pass in the database to the question/dashboard perhaps as a filter/locked variable etc.

To make this fit in to the current design, I wouldn’t mind having to write the questions and dashboards against a particular database, but would like the options to let the user change the database dynamically.

1 Like

Not the most sophisticated solution, but you could just create two sets of queries, one each for PRD and TST and label the questions as such. If data differs and is meaningful to compare, you can even stack the series within the same chart if appropriate. Otherwise, you can completely separate them into two dashboards. Does that provide the functionality you’re looking for?

Hi,

That while technically working is not workable in practice. We would need to copy n queries x the number of environments.

So if we have 8 environments and 100 queries then we have to copy the exact same sql 7x100 times.

If any on query changes then we have to edit the same sql 8 times

metabase developers should really do something about it