Following our previous article on managing dev and prod development for dashboards within a single Looker instance, we thought it would be useful to provide a step-by-step guide for developing LookML code using dev or prod tables.

As part of a data team, you’ve likely encountered this challenge: you’re enhancing a table in dev by adding new fields, modifying existing columns, or joining new tables to a model. Naturally, you’d want to test these updates in Looker before pushing them to production. This step is crucial to ensure no errors are introduced, avoiding disruptions for your business users.

However, Looker doesn’t offer a native way to dynamically switch between dev and prod tables in your data warehouse. Fortunately, we’ve discovered a simple solution for teams working within a single Looker environment.

How to Implement It: Step-by-Step Guide

In this example, we assume your Looker project is called sales. Your model file sales.model connects to the prod Bigquery project. Here’s how to set up the solution in Looker:

Step 1: Create a New Model File

Create a new model file named sales_dev.model that connects to the dev Bigquery project.

This file should include all the same Explores as sales.model.

Step 2: Add Logic to the Manifest File

In the manifest file, define a constant that dynamically switches between dev and prod Bigquery project based on the model name:

constant: project_var {
  value: "{% if _model._name == 'sales_dev' %}
            `internal-data-dev`
          {% elsif _model._name == 'sales' %}
            `internal-data-prd`
          {% endif %}"
}


Step 3: Update the LookML Views

In your LookML views, replace the hard-coded table names with the project_var constant.

Before:

view: dm_sales {
  sql_table_name: `internal-data-prd.bqdts_sales.dm_sales` ;;

  dimension: order_id {
    
    }
  
}

After:

view: dm_sales {
  sql_table_name: @{project_var}.`bqdts_sales.dm_sales` ;;

  dimension: order_id {
    
    }
  
}


Step 4: Test Your Changes

When connected to the sales_dev.model, Looker will query the dev tables in BigQuery.

When connected to the sales.model, Looker will query the prod tables.

Workflow

Let’s walk through the process using an example. Imagine your business team requests the addition of a new field to the sales model. For the sake of the example we assume you have dbt for data transformation and BigQuery as a data warehouse. Here’s the high-level workflow:

Conclusion

This simple solution enables you to seamlessly test dbt table developments in Looker before pushing changes to production. It ensures your data remains accurate and consistent for your business users.

If you enjoyed reading this article, stay tuned as we regularly publish articles on data strategy. Follow Astrafy on LinkedIn, Medium, and Youtube to be notified of the next article.

If you are looking for support on Modern Data Stack or Google Cloud solutions, feel free to reach out to us at sales@astrafy.io.