Schema changes without breaking Questions

How can we make schema changes without breaking all our existing Questions (on Postgres)?

For example:

  • Rename tables
  • Rename columns
  • Move tables to other schemas

What internal Metabase table holds the actual table/columns/query for each Question? What caches would we need to clear, and how? We’re not afraid to get our hands dirty.

Thank you!

You could change the Metabase database, but it’s a lot to get right!

What if you just created views to match the existing tables? That way the questions would just hit the views instead of the change tables.

For future searchers, here’s how we moved tables to a different Postgres schema:

  • Move the tables with alter table set schema
  • In the Metabase DB, update metabase_table set schema = 'newschema' where schema = 'oldschema' and db_id = 9
  • On /admin/databases/9, click “Sync database schema now”

Questions are still working as before.

We also wrote a script to make sure all questions are still working. It uses the API to get the IDs of all non-archived questions, then POSTs to /api/card/NNN/query, and asserts that the “status” field is “completed”.

1 Like