-
Notifications
You must be signed in to change notification settings - Fork 177
postgres: Support purge_on_delete on postgres_projects
#5414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| bundle: | ||
| name: deploy-postgres-purge-$UNIQUE_NAME | ||
|
|
||
| sync: | ||
| paths: [] | ||
|
|
||
| # Two projects side by side so the recorded destroy requests make the | ||
| # purge_on_delete contrast obvious: | ||
| # - hard_delete: purge_on_delete: true -> DELETE …?purge=true | ||
| # - soft_delete: field omitted (default) -> DELETE … (no purge query) | ||
| resources: | ||
| postgres_projects: | ||
| hard_delete: | ||
| project_id: test-pg-proj-hard-$UNIQUE_NAME | ||
| display_name: "purge_on_delete = true" | ||
| pg_version: 16 | ||
| purge_on_delete: true | ||
|
|
||
| soft_delete: | ||
| project_id: test-pg-proj-soft-$UNIQUE_NAME | ||
| display_name: "purge_on_delete unset (soft delete)" | ||
| pg_version: 16 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| The following resources will be deleted: | ||
| delete resources.postgres_projects.hard_delete | ||
| delete resources.postgres_projects.soft_delete | ||
|
|
||
| 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.hard_delete | ||
| delete resources.postgres_projects.soft_delete | ||
|
|
||
| All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/deploy-postgres-purge-[UNIQUE_NAME]/default | ||
|
|
||
| Deleting files... | ||
| Destroy complete! | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| { | ||
| "method": "GET", | ||
| "path": "/api/2.0/postgres/projects/test-pg-proj-hard-[UNIQUE_NAME]" | ||
| } | ||
| { | ||
| "method": "GET", | ||
| "path": "/api/2.0/postgres/projects/test-pg-proj-soft-[UNIQUE_NAME]" | ||
| } | ||
| { | ||
| "method": "POST", | ||
| "path": "/api/2.0/postgres/projects", | ||
| "q": { | ||
| "project_id": "test-pg-proj-hard-[UNIQUE_NAME]" | ||
| }, | ||
| "body": { | ||
| "spec": { | ||
| "display_name": "purge_on_delete = true", | ||
| "pg_version": 16 | ||
| } | ||
| } | ||
| } | ||
| { | ||
| "method": "POST", | ||
| "path": "/api/2.0/postgres/projects", | ||
| "q": { | ||
| "project_id": "test-pg-proj-soft-[UNIQUE_NAME]" | ||
| }, | ||
| "body": { | ||
| "spec": { | ||
| "display_name": "purge_on_delete unset (soft delete)", | ||
| "pg_version": 16 | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "method": "DELETE", | ||
| "path": "/api/2.0/postgres/projects/test-pg-proj-hard-[UNIQUE_NAME]", | ||
| "q": { | ||
| "purge": "true" | ||
| } | ||
| } | ||
| { | ||
| "method": "DELETE", | ||
| "path": "/api/2.0/postgres/projects/test-pg-proj-soft-[UNIQUE_NAME]" | ||
| } | ||
| { | ||
| "method": "GET", | ||
| "path": "/api/2.0/postgres/projects/test-pg-proj-hard-[UNIQUE_NAME]" | ||
| } | ||
| { | ||
| "method": "GET", | ||
| "path": "/api/2.0/postgres/projects/test-pg-proj-soft-[UNIQUE_NAME]" | ||
| } |
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,52 @@ | ||
|
|
||
| >>> [CLI] bundle validate | ||
| Name: deploy-postgres-purge-[UNIQUE_NAME] | ||
| Target: default | ||
| Workspace: | ||
| User: [USERNAME] | ||
| Path: /Workspace/Users/[USERNAME]/.bundle/deploy-postgres-purge-[UNIQUE_NAME]/default | ||
|
|
||
| Validation OK! | ||
|
|
||
| >>> [CLI] bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/deploy-postgres-purge-[UNIQUE_NAME]/default/files... | ||
| Deploying resources... | ||
| Updating deployment state... | ||
| Deployment complete! | ||
|
|
||
| >>> [CLI] postgres get-project projects/test-pg-proj-hard-[UNIQUE_NAME] | ||
| { | ||
| "name": "projects/test-pg-proj-hard-[UNIQUE_NAME]", | ||
| "status": { | ||
| "branch_logical_size_limit_bytes": [NUMID], | ||
| "default_branch": "projects/test-pg-proj-hard-[UNIQUE_NAME]/branches/production", | ||
| "display_name": "purge_on_delete = true", | ||
| "enable_pg_native_login": false, | ||
| "owner": "[USERNAME]", | ||
| "pg_version": 16, | ||
| "project_id": "test-pg-proj-hard-[UNIQUE_NAME]", | ||
| "synthetic_storage_size_bytes": 0 | ||
| }, | ||
| "uid": "[UUID]" | ||
| } | ||
|
|
||
| >>> [CLI] postgres get-project projects/test-pg-proj-soft-[UNIQUE_NAME] | ||
| { | ||
| "name": "projects/test-pg-proj-soft-[UNIQUE_NAME]", | ||
| "status": { | ||
| "branch_logical_size_limit_bytes": [NUMID], | ||
| "default_branch": "projects/test-pg-proj-soft-[UNIQUE_NAME]/branches/production", | ||
| "display_name": "purge_on_delete unset (soft delete)", | ||
| "enable_pg_native_login": false, | ||
| "owner": "[USERNAME]", | ||
| "pg_version": 16, | ||
| "project_id": "test-pg-proj-soft-[UNIQUE_NAME]", | ||
| "synthetic_storage_size_bytes": 0 | ||
| }, | ||
| "uid": "[UUID]" | ||
| } | ||
|
|
||
| >>> print_requests.py --sort --get //postgres ^//workspace-files/ ^//workspace/ ^//telemetry-ext ^//operations/ | ||
|
|
||
| === bundle destroy | ||
| >>> print_requests.py --sort --get //postgres ^//workspace-files/ ^//workspace/ ^//telemetry-ext ^//operations/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| envsubst < databricks.yml.tmpl > databricks.yml | ||
|
|
||
| cleanup() { | ||
| # Belt-and-braces in case bundle destroy was skipped or partially failed. | ||
| # The soft-delete case leaves a record in the trash; --purge clears it. | ||
| $CLI postgres delete-project --purge "projects/test-pg-proj-hard-${UNIQUE_NAME}" 2>>LOG.delete-project || true | ||
| $CLI postgres delete-project --purge "projects/test-pg-proj-soft-${UNIQUE_NAME}" 2>>LOG.delete-project || true | ||
| rm -f out.requests.txt | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| trace $CLI bundle validate | ||
|
|
||
| rm -f out.requests.txt | ||
| trace $CLI bundle deploy | ||
|
|
||
| trace $CLI postgres get-project "projects/test-pg-proj-hard-${UNIQUE_NAME}" | jq 'del(.create_time, .update_time)' | ||
| trace $CLI postgres get-project "projects/test-pg-proj-soft-${UNIQUE_NAME}" | jq 'del(.create_time, .update_time)' | ||
|
|
||
| trace print_requests.py --sort --get '//postgres' '^//workspace-files/' '^//workspace/' '^//telemetry-ext' '^//operations/' > out.requests.deploy.json | ||
|
|
||
| # bundle destroy should send ?purge=true on the hard_delete project and no | ||
| # purge query on the soft_delete project. Both DELETEs land in the recorded | ||
| # requests so the contrast is visible in the diff. | ||
| title "bundle destroy" | ||
| $CLI bundle destroy --auto-approve > out.destroy.txt 2>&1 || true | ||
|
|
||
| trace print_requests.py --sort --get '//postgres' '^//workspace-files/' '^//workspace/' '^//telemetry-ext' '^//operations/' > out.requests.destroy.json |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| bundle: | ||
| name: pg-purge-transitions-$UNIQUE_NAME | ||
|
|
||
| sync: | ||
| paths: [] | ||
|
|
||
| # Walks purge_on_delete through unset -> true -> false -> unset, deploying | ||
| # at each step and inspecting the persisted state so reviewers can see that | ||
| # state tracks the user's latest intent. The final destroy is a soft delete | ||
| # (state has purge_on_delete unset), recorded for regression coverage. | ||
| resources: | ||
| postgres_projects: | ||
| proj: | ||
| project_id: test-pg-proj-$UNIQUE_NAME | ||
| display_name: "Transitions test" | ||
| pg_version: 16 | ||
| # PURGE_ON_DELETE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| The following resources will be deleted: | ||
| delete resources.postgres_projects.proj | ||
|
|
||
| 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.proj | ||
|
|
||
| All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/pg-purge-transitions-[UNIQUE_NAME]/default | ||
|
|
||
| Deleting files... | ||
| Destroy complete! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "method": "DELETE", | ||
| "path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]" | ||
| } | ||
| { | ||
| "method": "GET", | ||
| "path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]" | ||
| } |
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,43 @@ | ||
|
|
||
| === Step 1: deploy with purge_on_delete unset | ||
| >>> [CLI] bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/pg-purge-transitions-[UNIQUE_NAME]/default/files... | ||
| Deploying resources... | ||
| Updating deployment state... | ||
| Deployment complete! | ||
|
|
||
| >>> get_purge | ||
| (unset) | ||
|
|
||
| === Step 2: set purge_on_delete: true | ||
| >>> [CLI] bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/pg-purge-transitions-[UNIQUE_NAME]/default/files... | ||
| Deploying resources... | ||
| Updating deployment state... | ||
| Deployment complete! | ||
|
|
||
| >>> get_purge | ||
| json.state.resources.postgres_projects.proj.state.purge_on_delete = true; | ||
|
|
||
| === Step 3: flip to purge_on_delete: false | ||
| >>> [CLI] bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/pg-purge-transitions-[UNIQUE_NAME]/default/files... | ||
| Deploying resources... | ||
| Updating deployment state... | ||
| Deployment complete! | ||
|
|
||
| >>> get_purge | ||
| json.state.resources.postgres_projects.proj.state.purge_on_delete = false; | ||
|
|
||
| === Step 4: remove the line again | ||
| >>> [CLI] bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/pg-purge-transitions-[UNIQUE_NAME]/default/files... | ||
| Deploying resources... | ||
| Updating deployment state... | ||
| Deployment complete! | ||
|
|
||
| >>> get_purge | ||
| json.state.resources.postgres_projects.proj.state.purge_on_delete = false; | ||
|
|
||
| === bundle destroy (must be a plain DELETE, no ?purge=true) | ||
| >>> print_requests.py --sort --get //postgres ^//workspace-files/ ^//workspace/ ^//telemetry-ext ^//operations/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| envsubst < databricks.yml.tmpl > databricks.yml | ||
|
|
||
| cleanup() { | ||
| # After this test the destroy should be a soft delete; --purge here so the | ||
| # trash entry doesn't linger past the test. | ||
| $CLI postgres delete-project --purge "projects/test-pg-proj-${UNIQUE_NAME}" 2>>LOG.delete-project || true | ||
| rm -f out.requests.txt | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| # Prints the persisted purge_on_delete assignment from the direct engine's | ||
| # resources.json. The field is omitted from JSON when unset (omitempty + | ||
| # ForceSendFields tracking), so an absent value falls back to "(unset)". | ||
| get_purge() { | ||
| gron.py < .databricks/bundle/default/resources.json | grep purge_on_delete || echo '(unset)' | ||
| } | ||
|
|
||
| title "Step 1: deploy with purge_on_delete unset" | ||
| trace $CLI bundle deploy | ||
| trace get_purge | ||
|
|
||
| title "Step 2: set purge_on_delete: true" | ||
| update_file.py databricks.yml "# PURGE_ON_DELETE" "purge_on_delete: true" | ||
| trace $CLI bundle deploy | ||
| trace get_purge | ||
|
|
||
| title "Step 3: flip to purge_on_delete: false" | ||
| update_file.py databricks.yml "purge_on_delete: true" "purge_on_delete: false" | ||
| trace $CLI bundle deploy | ||
| trace get_purge | ||
|
|
||
| title "Step 4: remove the line again" | ||
| update_file.py databricks.yml "purge_on_delete: false" "# PURGE_ON_DELETE" | ||
| trace $CLI bundle deploy | ||
| trace get_purge | ||
|
|
||
| rm -f out.requests.txt | ||
|
|
||
| title "bundle destroy (must be a plain DELETE, no ?purge=true)" | ||
| $CLI bundle destroy --auto-approve > out.destroy.txt 2>&1 || true | ||
| trace print_requests.py --sort --get '//postgres' '^//workspace-files/' '^//workspace/' '^//telemetry-ext' '^//operations/' > out.requests.destroy.json |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Direct engine only: this test exercises the FSF preservation in | ||
| # PrepareState and direct's plan/diff classification when the user flips | ||
| # purge_on_delete. Terraform has its own provider-managed state lifecycle. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but destroy requests should match between TF and direct, right? so could still make sense to run part of of these tests on TF to record destroy requests and compare.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cross-engine destroy parity is already covered by the sibling |
||
| EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] | ||
Uh oh!
There was an error while loading. Please reload this page.