# Upgrade Cortex Framework

This guide explains the standard workflow for upgrading an existing
Google Cloud Cortex Framework deployment to a target release, including repository
updates, custom `table_settings.yaml` handling, targeted Dataform full
refreshes, and post-upgrade verification.

Use this guide together with the version-specific upgrade guide for your target
release, the [Release notes](https://docs.cloud.google.com/cortex/docs/release-notes.md.txt), and
[Cortex Framework deprecations](https://docs.cloud.google.com/cortex/docs/deprecations.md.txt).

> [!NOTE]
> **Note:** These guides cover upgrades within Cortex Framework version 7 (`7.x`). If you are adopting version 7 from version 6 while preserving existing Looker dashboards or downstream SQL schemas, see [Version 6 compatibility](https://docs.cloud.google.com/cortex/docs/v6-compatibility.md.txt).

## Version-specific upgrade guides

| Target version | Upgrading from | Upgrade guide |
|---|---|---|
| `7.1` | `7.0.x` | [Upgrade to version 7.1](https://docs.cloud.google.com/cortex/docs/upgrade/v7-1.md.txt) |

## Step 1: Prepare and pull the target release

Validate the upgrade in a non-production Google Cloud project first. If your
target release requires a full refresh on any incremental tables, confirm that
your raw or data foundation tables still retain the historical records needed to
rebuild them.

- **Forked repository** : Fetch and merge the target release branch or tag into your fork, resolve any conflicts, and run `uv sync` in `cortex-framework-core/`.
- **Fresh clone** : Clone the target release into a new directory, copy your `config/config.yaml`, custom `table_settings.yaml` files, and custom namespaces into it, and run `uv sync` in `cortex-framework-core/`.

## Step 2: Update configuration, custom settings, and extensions

Apply the configuration, CLI, and custom extension updates in your target
[version-specific upgrade guide](https://docs.cloud.google.com/cortex/docs/upgrade/overview.md.txt#version-guides).

### Custom `table_settings.yaml` behavior across upgrades

- **Data products (field-level merge)**: Keep only the tables and fields you explicitly override. Copied default keys freeze older release values across upgrades.
- **Data foundations (full replacement)** : Diff any custom foundation file against the target release's `table_settings.default.yaml` so you keep added tables and default assertions.

For full merge and validation rules, see
[Deployment configuration](https://docs.cloud.google.com/cortex/docs/deployment-configuration.md.txt).

## Step 3: Build, compile, and deploy

1. Build the Dataform workspace and check for configuration or
   deprecation warnings:

   ```bash
   uv run cortex-build --config config/config.yaml
   ```
2. Compile the generated workspace offline to catch SQL or JavaScript errors:

   ```bash
   uv run cortex-compile
   ```
3. Deploy the compiled workspace to Dataform or Git:

   ```bash
   uv run cortex-deploy --config config/config.yaml
   ```

   Pass `--create-datasets` if the release introduces a new dataset, and pass
   `-y` (`--yes`) in CI/CD pipelines after reviewing planned file deletions.

> [!NOTE]
> **Note:** `uv run cortex-deploy` removes retired or renamed compiled files automatically while preserving unmanaged files listed in `targetSettings.ignoredPaths` (`type: dataform`; default `["definitions/custom"]`) or `targetSettings.ignorePatterns` (`type: git`). See [Deployment environment](https://docs.cloud.google.com/cortex/docs/deployment-configuration.md.txt#deployment-environment).

## Step 4: Run targeted full refreshes when required

Skip this step if your target version guide lists no tables requiring a full
refresh. Incremental tables compile with `onSchemaChange: "EXTEND"`, so columns
renamed or removed in a new release fail with `Removing column on EXTEND is not
allowed` until refreshed.

> [!CAUTION]
> **Caution:** A full refresh rebuilds each selected table from your data foundation dataset (increasing query scan cost); historical records already purged from raw or foundation tables can't be restored.

### Run a targeted full refresh

Refresh only the affected actions listed in your target version guide:

- **Dataform console** : Select the affected actions in your workspace and choose **Run with full refresh**.
- **Dataform CLI**:

  ```sh
  dataform run --actions ACTION_NAME --full-refresh
  ```
- **Deployments with `data.security` enabled** : Standard `--full-refresh`
  doesn't trigger a governed incremental reload on its own. Pass both
  `--full-refresh` and the `cortex_full_refresh` compilation variable (separate
  multiple table names with `;`, or use `true` for a one-off reload of all
  governed incremental actions---don't persist `true` in scheduled workflows):

  ```sh
  dataform run --actions ACTION_NAME --full-refresh \
    --vars='cortex_full_refresh=TABLE_1;TABLE_2'
  ```

## Step 5: Verify and clean up

1. **Run a normal incremental execution** : Trigger a second (non-full-refresh) Dataform run and confirm all actions and `unique_key` assertions pass with stable row counts.
2. **Re-run optional post-deployment tools (if enabled)** : Run [`uv run cortex-apply-security --config config/config.yaml`](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-apply-security.md.txt) for `data.security`, and re-sync [Knowledge Catalog](https://docs.cloud.google.com/cortex/docs/knowledge-catalog.md.txt), [Conversational analytics](https://docs.cloud.google.com/cortex/docs/conversational-analytics.md.txt), or [Gemini](https://docs.cloud.google.com/cortex/docs/gemini.md.txt) integrations so published metadata and agents pick up schema updates.
3. **Validate consumers and drop orphaned tables**: Verify downstream SQL, LookML, BI dashboards, and agents, then drop any confirmed orphaned BigQuery tables listed in your target version guide.

## Upgrade policy

- **Patch releases** (for example, `7.1.0` to `7.1.1`): Pull the release and run [Step 3](https://docs.cloud.google.com/cortex/docs/upgrade/overview.md.txt#build-compile-deploy) and [Step 5](https://docs.cloud.google.com/cortex/docs/upgrade/overview.md.txt#verification).
- **Multi-hop minor upgrades** (for example, `7.0` to `7.2`): Pull the final target release once and apply each intermediate version guide in order before deploying.
- **Major releases** (for example, `7.x` to `8.0`): Resolve all items in [Cortex Framework deprecations](https://docs.cloud.google.com/cortex/docs/deprecations.md.txt) scheduled for removal before upgrading.

## What's next

- Follow [Upgrade to version 7.1](https://docs.cloud.google.com/cortex/docs/upgrade/v7-1.md.txt) for version 7.0.x-to-7.1 migration steps and the SAP column rename map.
- Review [Cortex Framework deprecations](https://docs.cloud.google.com/cortex/docs/deprecations.md.txt) for items scheduled for removal in version 8.0.
- Review the [Release notes](https://docs.cloud.google.com/cortex/docs/release-notes.md.txt) for feature additions and resolved issues.