Refactor Metabase Queries

We use Metabase extensively in our team and company. People can create their own questions and queries and build their own dashboards.There has been a structural change in our database structure and we need to make sure that are Metabase cards are updated to reflect the database change. Does metabase have its own database that I can query to determine which cards are affected ? If so how can I access the database and write the query ?

Hi @neerupama
Yes, the metadata is stored in a database - by default it’s H2, which is not recommended for production use, so if you’ve migrated to Postgres or MariaDB/MySQL, then have a look in the table query and report_card.
https://www.metabase.com/docs/latest/operations-guide/start.html#migrating-from-using-the-h2-database-to-mysql-or-postgres

2 Likes

This should help:

1 Like

I use H2 as my metadata database, and I use metabase to access it. Just add a new connection in admin panel, choose H2, and provide the path to your H2 file. Then, take some time to familiarize with the tables in there - the table you want to look at is “query execution”. It is particularly easy to look for native queries, since you can ask metabase “which questions use field ‘my_renamed_field’”. I’ve used it tons of times, always very effecftive.

1 Like

@lucas.lima
H2 can easily become corrupted, that’s why it’s not recommended for production.

1 Like

Yeah, I’m well aware of H2 issues, not advocating for it - away from me. Just saying that, once you get you instance running, it might take some time to migrate it, a time that you may not have (my case). I, instead, wrote a script that makes a backup of my H2 every 30 minutes (my H2 file is currently aat about 1.5BG, so, yeah, it suckes). I really wish to migrate, eventually. But maybe there is someone in a similar scenario - in which case I wished to help.

1 Like