Upcoming: Introducing Dynamic Schema

Hey everyone! :wave:

I wanted to follow up on our Dynamic Data Sources post with another cool feature you might find useful: ​Dynamic Schema​.

:bar_chart: ​Dynamic Schema for Dev/Prod Environments​

For those of you who separate dev and prod environments based on schema (or datasets in BigQuery) instead of the actual data source, we’ve got you covered with our Dynamic Schema option.

This feature lets you switch schemas easily using basic string interpolation in your model’s table_name property.

Here’s a quick example to show how it works:

// This is for dynamic schema use case by branch  

const current_branch = H.git.current_branch
              
const dynamic_schema = 
  if (current_branch == 'master') { 'prod' } 
  else if (current_branch == 'staging') { 'stg' } 
  else { 'dev' }

// in Table Model
model users {
  type: 'table'
  data_source_name: 'your_db'

  // dynamic schema in table name
  table_name: '${dynamic_schema}.users'
}

// in Query Model
model derived_users {
  type: 'query'
  data_source_name: 'your_db'
  
  // dynamic schema in a query
  query: @sql select * from ${dynamic_schema}.users ;;

}

Just a heads up: the syntax shown above is our draft for collecting user input. The final version might look a little different, but the core idea will stay the same.

:wrench: What does this mean?

You can automatically point to the correct schema based on the branch you’re working on—making your workflow even smoother!

And don’t forget, if you find this useful, be sure to submit your beta request! We’ll let you know as soon as it’s ready to be used

Got any questions or thoughts? Feel free to drop them here. We’re here to help! :blush:

7 Likes