Skip to content

Commit ae9b412

Browse files
authored
Implement synced_database_table in direct deployment (#3525)
## Why <!-- Why are these changes needed? Provide the context that the reviewer might be missing. For example, were there any decisions behind the change that are not reflected in the code itself? --> - This change allows to deploy database catalogs when using direct-exp deployment method ## Tests <!-- How have you tested the changes? --> Important notice: destroying a bundle with a synced database table in it fails when using `direct-exp` method with the following error: ``` Error: cannot delete synced_database_tables.my_synced_table: deleting id=my_catalog_[UNIQUE_NAME].my_database.my_synced_table: Catalog 'my_catalog_[UNIQUE_NAME]' does not exist. (404 CATALOG_DOES_NOT_EXIST) Endpoint: DELETE [DATABRICKS_URL]/api/2.0/database/synced_tables/my_catalog_[UNIQUE_NAME].my_database.my_synced_table? HTTP Status: 404 Not Found API error_code: CATALOG_DOES_NOT_EXIST API message: Catalog 'my_catalog_[UNIQUE_NAME]' does not exist. ``` `direct-exp` method currently does not support waiting for deletion, thus the tests for `direct-exp` are currently not enabled <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent f09257e commit ae9b412

File tree

4 files changed

+65
-21
lines changed

4 files changed

+65
-21
lines changed

acceptance/bundle/deploy/lakebase/synced-database-table/output.txt

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,6 @@ Workspace:
88

99
Validation OK!
1010

11-
>>> [CLI] bundle summary
12-
Name: deploy-lakebase-synced-table-[UNIQUE_NAME]
13-
Target: default
14-
Workspace:
15-
User: [USERNAME]
16-
Path: /Workspace/Users/[USERNAME]/.bundle/deploy-lakebase-synced-table-[UNIQUE_NAME]/default
17-
Resources:
18-
Database catalogs:
19-
my_catalog:
20-
Name: my_catalog_[UNIQUE_NAME]
21-
URL: [DATABRICKS_URL]/explore/data/my_catalog_[UNIQUE_NAME]
22-
Database instances:
23-
my_instance:
24-
Name: test-db-synced-table-[UNIQUE_NAME]
25-
URL: (not deployed)
26-
Synced database tables:
27-
my_synced_table:
28-
Name: ${databricks_database_database_catalog.my_catalog.name}.${databricks_database_database_catalog.my_catalog.database_name}.my_synced_table
29-
URL: [DATABRICKS_URL]/explore/data/$%7Bdatabricks_database_database_catalog.my_catalog.name%7D.$%7Bdatabricks_database_database_catalog.my_catalog.database_name%7D.my_synced_table
30-
3111
>>> [CLI] bundle deploy
3212
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/deploy-lakebase-synced-table-[UNIQUE_NAME]/default/files...
3313
Deploying resources...

acceptance/bundle/deploy/lakebase/synced-database-table/script

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ cleanup() {
66
trap cleanup EXIT
77

88
trace $CLI bundle validate
9-
trace $CLI bundle summary
109
trace $CLI bundle deploy
1110
trace $CLI bundle summary

bundle/terranova/resource.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ var SupportedResources = map[string]ResourceSettings{
119119
ConfigType: TypeOfConfig(&tnresources.ResourceDatabaseCatalog{}),
120120
DeleteFN: tnresources.DeleteDatabaseCatalog,
121121
},
122+
"synced_database_tables": {
123+
New: reflect.ValueOf(tnresources.NewResourceSyncedDatabaseTable),
124+
ConfigType: TypeOfConfig(&tnresources.ResourceSyncedDatabaseTable{}),
125+
DeleteFN: tnresources.DeleteSyncedDatabaseTable,
126+
},
122127
}
123128

124129
type IResource interface {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package tnresources
2+
3+
import (
4+
"context"
5+
6+
"github.com/databricks/cli/bundle/config/resources"
7+
"github.com/databricks/databricks-sdk-go"
8+
"github.com/databricks/databricks-sdk-go/service/database"
9+
)
10+
11+
type ResourceSyncedDatabaseTable struct {
12+
client *databricks.WorkspaceClient
13+
config database.SyncedDatabaseTable
14+
}
15+
16+
func (s ResourceSyncedDatabaseTable) Config() any {
17+
return s.config
18+
}
19+
20+
func (s *ResourceSyncedDatabaseTable) DoCreate(ctx context.Context) (string, error) {
21+
result, err := s.client.Database.CreateSyncedDatabaseTable(ctx, database.CreateSyncedDatabaseTableRequest{
22+
SyncedTable: s.config,
23+
})
24+
if err != nil {
25+
return "", err
26+
}
27+
return result.Name, nil
28+
}
29+
30+
func (s ResourceSyncedDatabaseTable) DoUpdate(ctx context.Context, id string) error {
31+
request := database.UpdateSyncedDatabaseTableRequest{
32+
SyncedTable: s.config,
33+
Name: s.config.Name,
34+
UpdateMask: "*",
35+
}
36+
37+
_, err := s.client.Database.UpdateSyncedDatabaseTable(ctx, request)
38+
return err
39+
}
40+
41+
func (s ResourceSyncedDatabaseTable) WaitAfterCreate(_ context.Context) error {
42+
return nil
43+
}
44+
45+
func (s ResourceSyncedDatabaseTable) WaitAfterUpdate(_ context.Context) error {
46+
return nil
47+
}
48+
49+
func NewResourceSyncedDatabaseTable(client *databricks.WorkspaceClient, resource *resources.SyncedDatabaseTable) (*ResourceSyncedDatabaseTable, error) {
50+
return &ResourceSyncedDatabaseTable{
51+
client: client,
52+
config: resource.SyncedDatabaseTable,
53+
}, nil
54+
}
55+
56+
func DeleteSyncedDatabaseTable(ctx context.Context, client *databricks.WorkspaceClient, name string) error {
57+
return client.Database.DeleteSyncedDatabaseTable(ctx, database.DeleteSyncedDatabaseTableRequest{
58+
Name: name,
59+
})
60+
}

0 commit comments

Comments
 (0)