Using Liquibase with BigQuery

Google BigQuery is a fully managed analytics data warehouse. For more information, see BigQuery Documentation.

Supported versions

  • 2.13.6

Prerequisites

Install drivers

To use Liquibase and BigQuery, you need two JAR files:

Place your JAR file(s) in the liquibase/lib directory. For more information, see Adding and Updating Liquibase Drivers.

If you use Maven, you also need to download the driver JAR file and configure your Maven pom.xml file to use the local copy of the driver. For example:

<dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-bigquery</artifactId>
    <version>2.13.6</version>
</dependency>
<dependency>
    <groupId>org.liquibase.ext</groupId>
    <artifactId>liquibase-bigquery</artifactId>
    <version>4.14.0</version>
</dependency>

Test your connection

  1. Ensure your BigQuery database is configured. See BigQuery Quickstarts for more information. For example, you can run a query of a sample table in BigQuery using the bq command-line tool:
  2. bq show bigquery-public-data:samples.shakespeare
  3. Specify the database URL in the Liquibase properties file:

  4. url: jdbc:bigquery://https://googleapis.com/bigquery/v2:443/<dbname>;ProjectId=<STR>;OAuthType=<INT>;

    Specify the name of your database in place of dbname. Specify the ID of your BigQuery project as the value of ProjectId. Specify your BigQuery authentication method as the value of OAuthType:

    OAuthType Description Notes Example
    0 Google Services Account

    You must also specify the options OAuthServiceAcctEmail and OAuthPvtKeyPath in your url property. For more information, see:

    jdbc:bigquery://https://googleapis.com/bigquery/v2:443/myDatabase;
    ProjectId=myProject;
    OAuthType=0;
    OAuthServiceAcctEmail=lbtest@bq123.iam.gserviceaccount.com;
    OAuthPvtKeyPath=C:\path\serviceKey.p12;
    1 Google User Account

    Requires your user account credentials. For more information, see:

    jdbc:bigquery://https://googleapis.com/bigquery/v2:443/myDatabase;
    ProjectId=myProject;
    OAuthType=1;
    2 Google Authorization Server Access Token

    You must also specify the options OAuthAccessToken, OAuthRefreshToken, OAuthClientId, and OAuthClientSecret in your url property. For more information, see:

    jdbc:bigquery://https://googleapis.com/bigquery/v2:443/myDatabase;
    ProjectId=myProject;
    OAuthType=2;
    OAuthAccessToken=a25c7cfd36214f94a79d;
    OAuthRefreshToken=2kl0Qvuw9qt4abia54qga5t97;
    OAuthClientId=22n6627g243322f7;
    OAuthClientSecret=cDE+F2g3Hcjk4K5lazM;
    3 Application Default Credentials

    For more information, see:

    jdbc:bigquery://https://googleapis.com/bigquery/v2:443/myDatabase;
    ProjectId=myProject;
    OAuthType=3;

    For more information, see Simba JDBC Authentication Driver Configuration Options.

    Tip: To apply a Liquibase Pro key to your project, add the following property to the Liquibase properties file: liquibaseProLicenseKey: <paste code here>

  1. Create a text file called changelog (.xml, .sql, .json, or .yaml) in your project directory and add a changeset.
  2. Navigate to your project folder in the CLI and run the Liquibase status command to see whether the connection is successful:
  3. liquibase --username=test --password=test --changelog-file=<changelog.xml> status

    Note: You can pass arguments in the CLI or keep them in the Liquibase properties file.

  4. Inspect the SQL with the update-sql command. Then make changes to your database with the update command.
  5. liquibase --changelog-file=<changelog.xml> update-sql
    liquibase --changelog-file=<changelog.xml> update
  6. From a database UI tool, ensure that your database contains the test_table you added along with the DATABASECHANGELOG table and DATABASECHANGELOGLOCK table.

Related links