Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nextchanges/bundles/postgres-snapshot-schedules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add the `postgres_snapshot_schedules` bundle resource for managing a Lakebase Postgres branch's automatic-snapshot schedule (direct deployment engine only).
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
bundle:
name: test-bundle

resources:
postgres_snapshot_schedules:
schedule1:
branch: projects/test-project/branches/main
schedule:
- daily_schedule:
hour: 3
retention: "604800s"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

>>> [CLI] bundle deployment bind schedule1 projects/test-project/branches/main/snapshot-schedule --auto-approve
Successfully bound postgres_snapshot_schedule with an id 'projects/test-project/branches/main/snapshot-schedule'
Run 'bundle deploy' to deploy changes to your workspace

>>> [CLI] bundle summary
Name: test-bundle
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
Resources:
Postgres snapshot schedules:
schedule1:
Name:
URL: (not deployed)

>>> [CLI] bundle deployment unbind schedule1

>>> [CLI] bundle summary
Name: test-bundle
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
Resources:
Postgres snapshot schedules:
schedule1:
Name:
URL: (not deployed)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SCHEDULE_NAME="projects/test-project/branches/main/snapshot-schedule"
trace $CLI bundle deployment bind schedule1 "${SCHEDULE_NAME}" --auto-approve
trace $CLI bundle summary

trace $CLI bundle deployment unbind schedule1
trace $CLI bundle summary
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Cloud = false

# The snapshot schedule was added to the Postgres API in databricks-sdk-go
# v0.177.0, which the pinned Terraform provider does not yet include, so there is
# no databricks_..._snapshot_schedule resource. Run the direct engine only.
EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"]

Ignore = [
".databricks"
]

[[Server]]
Pattern = "GET /api/2.0/postgres/projects/test-project/branches/main/snapshot-schedule"
Response.Body = '''
{
"name": "projects/test-project/branches/main/snapshot-schedule",
"schedule": [
{
"daily_schedule": {
"hour": 3
},
"retention": "604800s"
}
]
}
'''
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
bundle:
name: test-bundle-$UNIQUE_NAME

resources:
postgres_projects:
project:
project_id: test-pg-project-$UNIQUE_NAME
display_name: Test Postgres Project

postgres_branches:
foo:
parent: ${resources.postgres_projects.project.name}
branch_id: test-branch-$UNIQUE_NAME
no_expiry: true

postgres_snapshot_schedules:
foo:
branch: ${resources.postgres_branches.foo.name}
schedule:
- daily_schedule:
hour: 3
retention: "604800s"
18 changes: 18 additions & 0 deletions acceptance/bundle/refschema/out.fields.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3556,6 +3556,24 @@ resources.postgres_roles.*.status.postgres_role string REMOTE
resources.postgres_roles.*.status.role_id string REMOTE
resources.postgres_roles.*.update_time *time.Time REMOTE
resources.postgres_roles.*.url string INPUT
resources.postgres_snapshot_schedules.*.branch string ALL
resources.postgres_snapshot_schedules.*.id string INPUT
resources.postgres_snapshot_schedules.*.lifecycle resources.Lifecycle INPUT
resources.postgres_snapshot_schedules.*.lifecycle.prevent_destroy bool INPUT
resources.postgres_snapshot_schedules.*.modified_status string INPUT
resources.postgres_snapshot_schedules.*.name string REMOTE
resources.postgres_snapshot_schedules.*.schedule []postgres.ScheduleCadence ALL
resources.postgres_snapshot_schedules.*.schedule[*] postgres.ScheduleCadence ALL
resources.postgres_snapshot_schedules.*.schedule[*].daily_schedule *postgres.DailySchedule ALL
resources.postgres_snapshot_schedules.*.schedule[*].daily_schedule.hour int ALL
resources.postgres_snapshot_schedules.*.schedule[*].monthly_schedule *postgres.MonthlySchedule ALL
resources.postgres_snapshot_schedules.*.schedule[*].monthly_schedule.day int ALL
resources.postgres_snapshot_schedules.*.schedule[*].monthly_schedule.hour int ALL
resources.postgres_snapshot_schedules.*.schedule[*].retention duration.Duration ALL
resources.postgres_snapshot_schedules.*.schedule[*].weekly_schedule *postgres.WeeklySchedule ALL
resources.postgres_snapshot_schedules.*.schedule[*].weekly_schedule.day_of_week postgres.DayOfWeek ALL
resources.postgres_snapshot_schedules.*.schedule[*].weekly_schedule.hour int ALL
resources.postgres_snapshot_schedules.*.url string INPUT
resources.postgres_synced_tables.*.accelerated_sync bool ALL
resources.postgres_synced_tables.*.branch string ALL
resources.postgres_synced_tables.*.create_database_objects_if_missing bool ALL
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
bundle:
name: deploy-pg-ss-basic-$UNIQUE_NAME

sync:
paths: []

resources:
postgres_projects:
my_project:
project_id: test-pg-proj-$UNIQUE_NAME
display_name: "Test Project for Snapshot Schedules"
pg_version: 16

postgres_branches:
main:
parent: ${resources.postgres_projects.my_project.id}
branch_id: main
no_expiry: true

postgres_snapshot_schedules:
main_schedule:
branch: ${resources.postgres_branches.main.id}
schedule:
- daily_schedule:
hour: 3
retention: "604800s"
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"method": "GET",
"path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]/branches/main/snapshot-schedule"
}
{
"method": "PATCH",
"path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]/branches/main/snapshot-schedule",
"q": {
"update_mask": "schedule"
},
"body": {
"schedule": [
{
"daily_schedule": {
"hour": 3
},
"retention": "604800s"
}
]
}
}
{
"method": "POST",
"path": "/api/2.0/postgres/projects",
"q": {
"project_id": "test-pg-proj-[UNIQUE_NAME]"
},
"body": {
"spec": {
"display_name": "Test Project for Snapshot Schedules",
"pg_version": 16
}
}
}
{
"method": "POST",
"path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]/branches",
"q": {
"branch_id": "main"
},
"body": {
"spec": {
"no_expiry": true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"method": "GET",
"path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]"
}
{
"method": "GET",
"path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]"
}
{
"method": "GET",
"path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]/branches/main"
}
{
"method": "GET",
"path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]/branches/main/snapshot-schedule"
}
{
"method": "GET",
"path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]/branches/main/snapshot-schedule"
}
{
"method": "PATCH",
"path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]/branches/main/snapshot-schedule",
"q": {
"update_mask": "schedule"
},
"body": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"method": "GET",
"path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]"
}
{
"method": "GET",
"path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]"
}
{
"method": "GET",
"path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]/branches/main"
}
{
"method": "GET",
"path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]/branches/main"
}
{
"method": "GET",
"path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]/branches/main/snapshot-schedule"
}
{
"method": "GET",
"path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]/branches/main/snapshot-schedule"
}
{
"method": "PATCH",
"path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]/branches/main/snapshot-schedule",
"q": {
"update_mask": "schedule"
},
"body": {
"schedule": [
{
"daily_schedule": {
"hour": 5
},
"retention": "604800s"
}
]
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@

=== Create with a snapshot schedule
>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/deploy-pg-ss-basic-[UNIQUE_NAME]/default/files...
Created postgres_branches.main
Created postgres_projects.my_project
Created postgres_snapshot_schedules.main_schedule
Files: 0 uploaded, 0 deleted
Resources: 3 created, 0 changed, 0 deleted, 0 unchanged

>>> [CLI] postgres get-snapshot-schedule projects/test-pg-proj-[UNIQUE_NAME]/branches/main/snapshot-schedule
{
"name": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main/snapshot-schedule",
"schedule": [
{
"daily_schedule": {
"hour": 3
},
"retention": "604800s"
}
]
}

=== Update the schedule cadence
>>> [CLI] bundle deploy --auto-approve
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/deploy-pg-ss-basic-[UNIQUE_NAME]/default/files...
Updated postgres_snapshot_schedules.main_schedule
Files: 0 uploaded, 0 deleted
Resources: 0 created, 1 changed, 0 deleted, 2 unchanged

>>> [CLI] postgres get-snapshot-schedule projects/test-pg-proj-[UNIQUE_NAME]/branches/main/snapshot-schedule
{
"name": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main/snapshot-schedule",
"schedule": [
{
"daily_schedule": {
"hour": 5
},
"retention": "604800s"
}
]
}

=== Remove the snapshot schedule resource (disables automatic snapshots)
>>> cat databricks.yml
bundle:
name: deploy-pg-ss-basic-[UNIQUE_NAME]

sync:
paths: []

resources:
postgres_projects:
my_project:
project_id: test-pg-proj-[UNIQUE_NAME]
display_name: "Test Project for Snapshot Schedules"
pg_version: 16

postgres_branches:
main:
parent: ${resources.postgres_projects.my_project.id}
branch_id: main
no_expiry: true


>>> [CLI] bundle deploy --auto-approve
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/deploy-pg-ss-basic-[UNIQUE_NAME]/default/files...
Deleted postgres_snapshot_schedules.main_schedule
Files: 0 uploaded, 0 deleted
Resources: 0 created, 0 changed, 1 deleted, 2 unchanged

>>> [CLI] postgres get-snapshot-schedule projects/test-pg-proj-[UNIQUE_NAME]/branches/main/snapshot-schedule
{
"name": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main/snapshot-schedule",
"schedule": null
}

=== Plan again to confirm no drift after removal
>>> [CLI] bundle plan
Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged

>>> [CLI] bundle destroy --auto-approve
The following resources will be deleted:
delete resources.postgres_branches.main
delete resources.postgres_projects.my_project

This action will result in the deletion of the following Lakebase projects along with
all their branches, databases, and endpoints. All data stored in them will be permanently lost:
delete resources.postgres_projects.my_project

This action will result in the deletion of the following Lakebase branches.
All data stored in them will be permanently lost:
delete resources.postgres_branches.main

All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/deploy-pg-ss-basic-[UNIQUE_NAME]/default

Destroy: 2 deleted
Loading
Loading