Deploying migrations locally

Every schema change to STOCK_RAW, REDBOOK_VEHICLES_RAW, or any other raw table goes through a versioned schemachange migration — never a direct ALTER TABLE. This page is the "how do I run one" runbook. For naming conventions, file structure, and how the two projects' scripts differ under the hood, see Migrations.

Prerequisites

  • Prerequisites & setup done — your snowflake-drive-staging-admin/-prod-admin Snow CLI connections work.
  • schemachange installed (pip install schemachange, or it's already in the venv from setup).

Migrations authenticate through your personal admin Snow CLI connection, not the dbt service-account key — you don't need DRIVE_STAGING_DBT_KEY_PATH exported for this.

Each dbt project has a migrations/deploy-migrations.sh that dry-runs first, then prompts before applying. The two scripts must be run from different working directories:

snippet.bashbash
# Stock — run from the dbt project root
cd src/stock/dbt
source venv/bin/activate
./migrations/deploy-migrations.sh staging

# Redbook — run from inside the migrations directory itself
cd src/redbook/dbt
source venv/bin/activate
cd migrations
./deploy-migrations.sh staging

Running Redbook's script from src/redbook/dbt instead of src/redbook/dbt/migrations fails — it looks for *.sql files in the current directory.

The script:

  1. Runs schemachange deploy --dry-run and shows you what would change.
  2. Prompts Deploy migrations to staging? (y/N) — nothing applies until you confirm.
  3. Runs the real deploy, then prints the schemachange render command to check history.

Passing prod as the first argument deploys to production the same way, using DRIVE_PROD_ROLE_DBT and connection snowflake-drive-prod-admin automatically — the script picks role/connection from the environment argument, you don't set them separately.

Deploy via Makefile

snippet.bashbash
make deploy-migrations-stock         # stock, staging
make deploy-migrations-redbook       # redbook, staging
make deploy-migrations-stock-prod    # stock, production
make deploy-migrations-redbook-prod  # redbook, production

The stock targets work as-is. The redbook targets cd src/redbook/dbt and invoke ./migrations/deploy-migrations.sh from there — but redbook's script requires being run from inside migrations/ itself (see above), so make deploy-migrations-redbook/-redbook-prod currently fail. Use the manual Redbook invocation above instead until that's fixed.

Non-interactive deployment (CI/automation)

Pipe y into the script to skip the confirmation prompt:

snippet.bashbash
cd src/stock/dbt && . venv/bin/activate && \
echo "y" | ./migrations/deploy-migrations.sh staging

Same pattern for Redbook, run from src/redbook/dbt/migrations instead.

Verify

snippet.bashbash
schemachange render -f migrations   # from src/stock/dbt
schemachange render -f .            # from src/redbook/dbt/migrations

Shows applied migration history from each project's own SCHEMACHANGE_HISTORY table.

See also

Esc