Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: populate sid and service name (#5028)

Danny Xucd5f4ee8a845
diff --git a/backend/api/v1/instance_service.go b/backend/api/v1/instance_service.go
index ec34efee64..f26a5db896 100644
--- a/backend/api/v1/instance_service.go
+++ b/backend/api/v1/instance_service.go
@@ -330,6 +330,10 @@ func (s *InstanceService) UpdateDataSource(ctx context.Context, request *v1pb.Up
patch.SRV = &request.DataSources.Srv
case "authentication_database":
patch.AuthenticationDatabase = &request.DataSources.AuthenticationDatabase
+ case "sid":
+ patch.SID = &request.DataSources.Sid
+ case "service_name":
+ patch.SID = &request.DataSources.ServiceName
}
}
@@ -406,6 +410,8 @@ func convertToInstance(instance *store.InstanceMessage) *v1pb.Instance {
Database: ds.Database,
Srv: ds.SRV,
AuthenticationDatabase: ds.AuthenticationDatabase,
+ Sid: ds.SID,
+ ServiceName: ds.ServiceName,
})
}
@@ -467,6 +473,8 @@ func (s *InstanceService) convertToDataSourceMessage(dataSource *v1pb.DataSource
Database: dataSource.Database,
SRV: dataSource.Srv,
AuthenticationDatabase: dataSource.AuthenticationDatabase,
+ SID: dataSource.Sid,
+ ServiceName: dataSource.ServiceName,
}, nil
}
diff --git a/backend/component/dbfactory/dbfactory.go b/backend/component/dbfactory/dbfactory.go
index 6b809d77ff..ede16c2d4a 100644
--- a/backend/component/dbfactory/dbfactory.go
+++ b/backend/component/dbfactory/dbfactory.go
@@ -88,6 +88,8 @@ func (d *DBFactory) GetAdminDatabaseDriver(ctx context.Context, instance *store.
Database: databaseName,
SRV: adminDataSource.SRV,
AuthenticationDatabase: adminDataSource.AuthenticationDatabase,
+ SID: adminDataSource.SID,
+ ServiceName: adminDataSource.ServiceName,
},
db.ConnectionContext{
EnvironmentID: instance.EnvironmentID,
diff --git a/backend/legacyapi/data_source.go b/backend/legacyapi/data_source.go
index 629818d6f6..0864c481ea 100644
--- a/backend/legacyapi/data_source.go
+++ b/backend/legacyapi/data_source.go
@@ -48,10 +48,7 @@ type DataSourceOptions struct {
// getDefaultDataSourceOptions returns the default data source options.
func getDefaultDataSourceOptions() DataSourceOptions {
- return DataSourceOptions{
- SRV: false,
- AuthenticationDatabase: "",
- }
+ return DataSourceOptions{}
}
// Scan implements database/sql Scanner interface, converts JSONB to DataSourceOptions struct.
diff --git a/backend/legacyapi/instance.go b/backend/legacyapi/instance.go
index 3d97e4c51e..74f20439bc 100644
--- a/backend/legacyapi/instance.go
+++ b/backend/legacyapi/instance.go
@@ -55,6 +55,9 @@ type InstanceCreate struct {
SRV bool `jsonapi:"attr,srv"`
// AuthenticationDatabase is used for MongoDB only.
AuthenticationDatabase string `jsonapi:"attr,authenticationDatabase"`
+ // SID and ServiceName are used for Oracle.
+ SID string `jsonapi:"attr,sid"`
+ ServiceName string `jsonapi:"attr,serviceName"`
}
// InstanceFind is the API message for finding instances.
@@ -86,6 +89,7 @@ type InstancePatch struct {
Name *string `jsonapi:"attr,name"`
EngineVersion *string
ExternalLink *string `jsonapi:"attr,externalLink"`
+ // TODO(zp): deprecate SRV and AuthenticationDatabase in InstancePatch.
// SRV record is used for MongoDB only.
SRV bool `jsonapi:"attr,srv"`
// AuthenticationDatabase is used for MongoDB only.
diff --git a/backend/legacyapi/sql.go b/backend/legacyapi/sql.go
index 5c4489b31f..77db373e94 100644
--- a/backend/legacyapi/sql.go
+++ b/backend/legacyapi/sql.go
@@ -24,6 +24,8 @@ type ConnectionInfo struct {
SRV bool `jsonapi:"attr,srv"`
// AuthenticationDatabase is used for MongoDB only.
AuthenticationDatabase string `json:"authenticationDatabase" jsonapi:"attr,authenticationDatabase"`
+ SID string `json:"sid" jsonapi:"attr,sid"`
+ ServiceName string `json:"serviceName" jsonapi:"attr,serviceName"`
}
// SQLSyncSchema is the API message for sync schemas.
diff --git a/backend/plugin/db/driver.go b/backend/plugin/db/driver.go
index 51c488061b..bfd371eb9d 100644
--- a/backend/plugin/db/driver.go
+++ b/backend/plugin/db/driver.go
@@ -369,6 +369,9 @@ type ConnectionConfig struct {
SRV bool
// AuthenticationDatabase is only supported for MongoDB now.
AuthenticationDatabase string
+ // SID and ServiceName are Oracle only.
+ SID string
+ ServiceName string
}
// ConnectionContext is the context for connection.
diff --git a/backend/server/database.go b/backend/server/database.go
index 701bd8ba1d..b3c23726b6 100644
--- a/backend/server/database.go
+++ b/backend/server/database.go
@@ -544,6 +544,8 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
Database: dataSourceCreate.Database,
SRV: dataSourceCreate.Options.SRV,
AuthenticationDatabase: dataSourceCreate.Options.AuthenticationDatabase,
+ SID: dataSourceCreate.Options.SID,
+ ServiceName: dataSourceCreate.Options.ServiceName,
}
if err := s.store.AddDataSourceToInstanceV2(ctx, instance.UID, creatorID, instance.EnvironmentID, instance.ResourceID, dataSourceMessage); err != nil {
return err
@@ -653,6 +655,8 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
if dataSourcePatch.Options != nil {
updateMessage.SRV = &dataSourcePatch.Options.SRV
updateMessage.AuthenticationDatabase = &dataSourcePatch.Options.AuthenticationDatabase
+ updateMessage.SID = &dataSourcePatch.Options.SID
+ updateMessage.ServiceName = &dataSourcePatch.Options.ServiceName
}
if err := s.store.UpdateDataSourceV2(ctx, updateMessage); err != nil {
return err
diff --git a/backend/server/instance.go b/backend/server/instance.go
index 86501f0b50..ddc45ed68b 100644
--- a/backend/server/instance.go
+++ b/backend/server/instance.go
@@ -79,6 +79,8 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
Database: instanceCreate.Database,
SRV: instanceCreate.SRV,
AuthenticationDatabase: instanceCreate.AuthenticationDatabase,
+ SID: instanceCreate.SID,
+ ServiceName: instanceCreate.ServiceName,
},
},
}, creator)
diff --git a/backend/server/sql.go b/backend/server/sql.go
index 9946f124d2..8e9653ab7c 100644
--- a/backend/server/sql.go
+++ b/backend/server/sql.go
@@ -122,10 +122,12 @@ func (s *Server) registerSQLRoutes(g *echo.Group) {
Password: password,
Host: connectionInfo.Host,
Port: connectionInfo.Port,
+ Database: connectionInfo.Database,
TLSConfig: tlsConfig,
SRV: connectionInfo.SRV,
AuthenticationDatabase: connectionInfo.AuthenticationDatabase,
- Database: connectionInfo.Database,
+ SID: connectionInfo.SID,
+ ServiceName: connectionInfo.ServiceName,
},
db.ConnectionContext{},
)
diff --git a/backend/store/data_source.go b/backend/store/data_source.go
index 74073a335a..2b7f9755e3 100644
--- a/backend/store/data_source.go
+++ b/backend/store/data_source.go
@@ -27,6 +27,8 @@ type DataSourceMessage struct {
// Flatten data source options.
SRV bool
AuthenticationDatabase string
+ SID string
+ ServiceName string
// (deprecated) Output only.
UID int
DatabaseID int
@@ -51,6 +53,8 @@ type UpdateDataSourceMessage struct {
// Flatten data source options.
SRV *bool
AuthenticationDatabase *string
+ SID *string
+ ServiceName *string
}
func (*Store) listDataSourceV2(ctx context.Context, tx *Tx, instanceID string) ([]*DataSourceMessage, error) {
@@ -106,6 +110,8 @@ func (*Store) listDataSourceV2(ctx context.Context, tx *Tx, instanceID string) (
}
dataSourceMessage.SRV = dataSourceOptions.Srv
dataSourceMessage.AuthenticationDatabase = dataSourceOptions.AuthenticationDatabase
+ dataSourceMessage.SID = dataSourceOptions.Sid
+ dataSourceMessage.ServiceName = dataSourceOptions.ServiceName
dataSourceMessages = append(dataSourceMessages, &dataSourceMessage)
}
@@ -211,6 +217,12 @@ func (s *Store) UpdateDataSourceV2(ctx context.Context, patch *UpdateDataSourceM
if v := patch.AuthenticationDatabase; v != nil {
optionSet, args = append(optionSet, fmt.Sprintf("jsonb_build_object('authenticationDatabase', to_jsonb($%d::TEXT))", len(args)+1)), append(args, *v)
}
+ if v := patch.SID; v != nil {
+ optionSet, args = append(optionSet, fmt.Sprintf("jsonb_build_object('sid', to_jsonb($%d::TEXT))", len(args)+1)), append(args, *v)
+ }
+ if v := patch.ServiceName; v != nil {
+ optionSet, args = append(optionSet, fmt.Sprintf("jsonb_build_object('serviceName', to_jsonb($%d::TEXT))", len(args)+1)), append(args, *v)
+ }
if len(optionSet) != 0 {
set = append(set, fmt.Sprintf(`options = options || %s`, strings.Join(optionSet, "||")))
}
@@ -252,6 +264,8 @@ func (*Store) addDataSourceToInstanceImplV2(ctx context.Context, tx *Tx, instanc
dataSourceOptions := storepb.DataSourceOptions{
Srv: dataSource.SRV,
AuthenticationDatabase: dataSource.AuthenticationDatabase,
+ Sid: dataSource.SID,
+ ServiceName: dataSource.ServiceName,
}
protoBytes, err := protojson.Marshal(&dataSourceOptions)
if err != nil {
diff --git a/backend/store/instance.go b/backend/store/instance.go
index 5fb3568d54..c4c5d0c62f 100644
--- a/backend/store/instance.go
+++ b/backend/store/instance.go
@@ -89,7 +89,7 @@ func (s *Store) composeInstance(ctx context.Context, instance *InstanceMessage)
Username: ds.Username,
Host: ds.Host,
Port: ds.Port,
- Options: api.DataSourceOptions{SRV: ds.SRV, AuthenticationDatabase: ds.AuthenticationDatabase},
+ Options: api.DataSourceOptions{SRV: ds.SRV, AuthenticationDatabase: ds.AuthenticationDatabase, SID: ds.SID, ServiceName: ds.ServiceName},
Database: ds.Database,
})
if ds.Type == api.Admin {