Skip to content

PostgresBranch

laktory.models.resources.databricks.PostgresBranch ¤

Bases: PostgresBranchBase

Lakebase Autoscaling (Postgres) Branch

Isolated, copy-on-write version of the data of a project (e.g. production, development, a feature branch), with its own endpoints, databases and roles. A production branch is created implicitly with each project: set replace_existing: true to manage it. Can also be declared in the branches of a PostgresProject.

Lakebase Autoscaling resources don't detect changes made outside Terraform, and a value removed from spec is kept by the server.

Examples:

import io

from laktory import models

branch_yaml = '''
parent: projects/app
branch_id: production
replace_existing: true
spec:
  no_expiry: true
endpoints:
- endpoint_id: primary
  replace_existing: true
  spec:
    endpoint_type: ENDPOINT_TYPE_READ_WRITE
    autoscaling_limit_min_cu: 0.5
    autoscaling_limit_max_cu: 4.0
catalogs:
- catalog_id: app_pg
  spec:
    postgres_database: app_db
    create_database_if_missing: true
synced_tables:
- synced_table_id: app_pg.public.dim_customers
  spec:
    postgres_database: app_db
    source_table_full_name: prod.gold.dim_customers
    primary_key_columns:
    - customer_id
    scheduling_policy: SNAPSHOT
    new_pipeline_spec:
      storage_catalog: prod
      storage_schema: lakebase
snapshot_schedule:
  schedule:
  - daily_schedule:
      hour: 3
    retention: 168h0m0s
'''
branch = models.resources.databricks.PostgresBranch.model_validate_yaml(
    io.StringIO(branch_yaml)
)
References
BASE DESCRIPTION
branch_id

Part of the resource name

TYPE: str | VariableType

parent

Project of the branch (projects/{project_id}). Set automatically when declared in the branches of a project.

TYPE: str | VariableType DEFAULT: None

provider_config

Configure the provider for management through account provider

TYPE: PostgresBranchProviderConfig | None | VariableType DEFAULT: None

purge_on_delete

If true, permanently delete the branch; if false, soft delete

TYPE: bool | None | VariableType DEFAULT: None

replace_existing

If true, update the branch if it already exists instead of returning an error

TYPE: bool | None | VariableType DEFAULT: None

spec

The spec contains the branch configuration

TYPE: PostgresBranchSpec | None | VariableType DEFAULT: None

LAKTORY DESCRIPTION
catalogs

Unity Catalog catalogs registering databases of the branch. Their spec.branch is set automatically.

TYPE: list[PostgresCatalog | VariableType] | VariableType DEFAULT: None

databases

Databases of the branch. Their parent is set automatically.

TYPE: list[PostgresDatabase | VariableType] | VariableType DEFAULT: None

endpoints

Endpoints (compute) of the branch. Their parent is set automatically.

TYPE: list[PostgresEndpoint | VariableType] | VariableType DEFAULT: None

roles

Roles of the branch. Their parent is set automatically.

TYPE: list[PostgresRole | VariableType] | VariableType DEFAULT: None

snapshot_schedule

Snapshot schedule of the branch. Its parent is set automatically.

TYPE: PostgresSnapshotSchedule | VariableType DEFAULT: None

synced_tables

Unity Catalog tables synced into databases of the branch. Their spec.branch is set automatically.

TYPE: list[PostgresSyncedTable | VariableType] | VariableType DEFAULT: None

METHOD DESCRIPTION
assign_parents

Set the branch path on nested resources

ATTRIBUTE DESCRIPTION
additional_core_resources
  • endpoints

TYPE: list

path

Lakebase resource path {project path}/branches/{branch_id}

TYPE: str

additional_core_resources property ¤

  • endpoints
  • roles
  • databases
  • snapshot schedule
  • catalogs
  • synced tables

Siblings reference each other by name only (database owner role, catalog and synced table Postgres database), so they are created in that order: roles, databases, catalogs, synced tables.

path property ¤

Lakebase resource path {project path}/branches/{branch_id}

assign_parents() ¤

Set the branch path on nested resources

Source code in laktory/models/resources/databricks/postgresbranch.py
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
@model_validator(mode="after")
def assign_parents(self):
    """Set the branch path on nested resources"""
    if self.parent is None:
        return self
    children = (
        (self.endpoints or [])
        + (self.roles or [])
        + (self.databases or [])
        + ([self.snapshot_schedule] if self.snapshot_schedule else [])
    )
    for r in children:
        if r.parent is None:
            r.parent = self.path
    for db in self.databases or []:
        db.assign_parents()
    for r in (self.catalogs or []) + (self.synced_tables or []):
        if r.spec is not None and r.spec.branch is None:
            r.spec.branch = self.path
    return self

laktory.models.resources.databricks.postgresbranch.PostgresBranchProviderConfig ¤

Bases: BaseModel

PARAMETER DESCRIPTION
workspace_id

Workspace ID which the resource belongs to. This workspace must be part of the account which the provider is configured with

TYPE: str | None | VariableType DEFAULT: None


laktory.models.resources.databricks.postgresbranch.PostgresBranchSpec ¤

Bases: BaseModel

PARAMETER DESCRIPTION
expire_time

Absolute expiration time for the branch. Empty if expiration is disabled

TYPE: str | None | VariableType DEFAULT: None

is_protected

Whether the branch is protected

TYPE: bool | None | VariableType DEFAULT: None

no_expiry

Explicitly disable expiration. When set to true, the branch will not expire. If set to false, the request is invalid; provide either ttl or expire_time instead. Mutually exclusive with expire_time and ttl

TYPE: bool | None | VariableType DEFAULT: None

source_branch

The name of the source branch from which this branch was created. Format: projects/{project_id}/branches/{branch_id}

TYPE: str | None | VariableType DEFAULT: None

source_branch_lsn

The Log Sequence Number (LSN) on the source branch from which this branch was created

TYPE: str | None | VariableType DEFAULT: None

source_branch_time

The point in time on the source branch from which this branch was created

TYPE: str | None | VariableType DEFAULT: None

source_snapshot

The snapshot this branch was restored from. Set only for branches created by restoring a snapshot; unset for all other branches. Format: projects/{project_id}/snapshots/{snapshot_id}

TYPE: str | None | VariableType DEFAULT: None

ttl

Relative time-to-live duration. When set, the branch will expire at creation_time + ttl. Mutually exclusive with expire_time and no_expiry

TYPE: str | None | VariableType DEFAULT: None