Skip to content

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

chore: pre append to prepend (#15946)

h3n4l641057c0c3e8
diff --git a/backend/plugin/parser/pg/restore.go b/backend/plugin/parser/pg/restore.go
index 89ab3a88d8..b9848b81ca 100644
--- a/backend/plugin/parser/pg/restore.go
+++ b/backend/plugin/parser/pg/restore.go
@@ -46,15 +46,15 @@ func GenerateRestoreSQL(ctx context.Context, rCtx base.RestoreContext, statement
sqlForComment += "..."
}
- preAppendStatements, err := getPreAppendStatements(statement)
+ prependStatements, err := getPrependStatements(statement)
if err != nil {
- return "", errors.Wrap(err, "failed to get pre-append statements")
+ return "", errors.Wrap(err, "failed to get prepend statements")
}
- return doGenerate(ctx, rCtx, sqlForComment, tree, backupItem, preAppendStatements)
+ return doGenerate(ctx, rCtx, sqlForComment, tree, backupItem, prependStatements)
}
-func doGenerate(ctx context.Context, rCtx base.RestoreContext, sqlForComment string, tree *ParseResult, backupItem *storepb.PriorBackupDetail_Item, preAppendStatements string) (string, error) {
+func doGenerate(ctx context.Context, rCtx base.RestoreContext, sqlForComment string, tree *ParseResult, backupItem *storepb.PriorBackupDetail_Item, prependStatements string) (string, error) {
_, sourceDatabase, err := common.GetInstanceDatabaseID(backupItem.SourceTable.Database)
if err != nil {
return "", errors.Wrapf(err, "failed to get source database ID for %s", backupItem.SourceTable.Database)
@@ -102,8 +102,8 @@ func doGenerate(ctx context.Context, rCtx base.RestoreContext, sqlForComment str
return "", g.err
}
- if len(preAppendStatements) > 0 {
- return fmt.Sprintf("%s\n/*\nOriginal SQL:\n%s\n*/\n%s", preAppendStatements, sqlForComment, g.result), nil
+ if len(prependStatements) > 0 {
+ return fmt.Sprintf("%s\n/*\nOriginal SQL:\n%s\n*/\n%s", prependStatements, sqlForComment, g.result), nil
}
return fmt.Sprintf("/*\nOriginal SQL:\n%s\n*/\n%s", sqlForComment, g.result), nil
}
@@ -259,7 +259,7 @@ func inRange(start, end, targetStart, targetEnd *storepb.Position) bool {
return true
}
-func getPreAppendStatements(statement string) (string, error) {
+func getPrependStatements(statement string) (string, error) {
nodes, err := pgrawparser.Parse(pgrawparser.ParseContext{}, statement)
if err != nil {
return "", errors.Wrap(err, "failed to parse statement")
diff --git a/backend/runner/taskrun/data_update_executor.go b/backend/runner/taskrun/data_update_executor.go
index 48353acc03..d39decff04 100644
--- a/backend/runner/taskrun/data_update_executor.go
+++ b/backend/runner/taskrun/data_update_executor.go
@@ -231,9 +231,9 @@ func (exec *DataUpdateExecutor) backupData(
return nil, errors.Wrap(err, "failed to transform DML to select")
}
- preAppendStatements, err := getPreAppendStatements(instance.Metadata.GetEngine(), originStatement)
+ prependStatements, err := getPrependStatements(instance.Metadata.GetEngine(), originStatement)
if err != nil {
- return nil, errors.Wrap(err, "failed to get pre append statements")
+ return nil, errors.Wrap(err, "failed to get prepend statements")
}
priorBackupDetail := &storepb.PriorBackupDetail{}
@@ -243,8 +243,8 @@ func (exec *DataUpdateExecutor) backupData(
}
for _, statement := range statements {
backupStatement := statement.Statement
- if preAppendStatements != "" {
- backupStatement = preAppendStatements + backupStatement
+ if prependStatements != "" {
+ backupStatement = prependStatements + backupStatement
}
if _, err := driver.Execute(driverCtx, backupStatement, db.ExecuteOptions{}); err != nil {
return nil, errors.Wrapf(err, "failed to execute backup statement %q", backupStatement)
@@ -385,7 +385,7 @@ func BuildListDatabaseNamesFunc(storeInstance *store.Store) parserbase.ListDatab
}
}
-func getPreAppendStatements(engine storepb.Engine, statement string) (string, error) {
+func getPrependStatements(engine storepb.Engine, statement string) (string, error) {
if engine != storepb.Engine_POSTGRES {
return "", nil
}
diff --git a/frontend/src/types/proto/google/protobuf/descriptor.ts b/frontend/src/types/proto/google/protobuf/descriptor.ts
index 683ca835c8..391ece45b7 100644
--- a/frontend/src/types/proto/google/protobuf/descriptor.ts
+++ b/frontend/src/types/proto/google/protobuf/descriptor.ts
@@ -245,7 +245,12 @@ export interface MessageOptions {
deprecatedLegacyJsonFieldConflicts?:
| boolean
| undefined;
- /** Any features defined in the specific edition. */
+ /**
+ * Any features defined in the specific edition.
+ * WARNING: This field should only be used by protobuf plugins or special
+ * cases like the proto compiler. Other uses are discouraged and
+ * developers should rely on the protoreflect APIs for their client language.
+ */
features?:
| FeatureSet
| undefined;
@@ -350,7 +355,12 @@ export interface FieldOptions {
retention?: FieldOptions_OptionRetention | undefined;
targets: FieldOptions_OptionTargetType[];
editionDefaults: FieldOptions_EditionDefault[];
- /** Any features defined in the specific edition. */
+ /**
+ * Any features defined in the specific edition.
+ * WARNING: This field should only be used by protobuf plugins or special
+ * cases like the proto compiler. Other uses are discouraged and
+ * developers should rely on the protoreflect APIs for their client language.
+ */
features?: FeatureSet | undefined;
featureSupport?:
| FieldOptions_FeatureSupport
@@ -696,7 +706,12 @@ export interface MethodOptions {
idempotencyLevel?:
| MethodOptions_IdempotencyLevel
| undefined;
- /** Any features defined in the specific edition. */
+ /**
+ * Any features defined in the specific edition.
+ * WARNING: This field should only be used by protobuf plugins or special
+ * cases like the proto compiler. Other uses are discouraged and
+ * developers should rely on the protoreflect APIs for their client language.
+ */
features?:
| FeatureSet
| undefined;
@@ -813,6 +828,7 @@ export interface FeatureSet {
utf8Validation?: FeatureSet_Utf8Validation | undefined;
messageEncoding?: FeatureSet_MessageEncoding | undefined;
jsonFormat?: FeatureSet_JsonFormat | undefined;
+ enforceNamingStyle?: FeatureSet_EnforceNamingStyle | undefined;
}
export enum FeatureSet_FieldPresence {
@@ -1141,6 +1157,59 @@ export function featureSet_JsonFormatToNumber(object: FeatureSet_JsonFormat): nu
}
}
+export enum FeatureSet_EnforceNamingStyle {
+ ENFORCE_NAMING_STYLE_UNKNOWN = "ENFORCE_NAMING_STYLE_UNKNOWN",
+ STYLE2024 = "STYLE2024",
+ STYLE_LEGACY = "STYLE_LEGACY",
+ UNRECOGNIZED = "UNRECOGNIZED",
+}
+
+export function featureSet_EnforceNamingStyleFromJSON(object: any): FeatureSet_EnforceNamingStyle {
+ switch (object) {
+ case 0:
+ case "ENFORCE_NAMING_STYLE_UNKNOWN":
+ return FeatureSet_EnforceNamingStyle.ENFORCE_NAMING_STYLE_UNKNOWN;
+ case 1:
+ case "STYLE2024":
+ return FeatureSet_EnforceNamingStyle.STYLE2024;
+ case 2:
+ case "STYLE_LEGACY":
+ return FeatureSet_EnforceNamingStyle.STYLE_LEGACY;
+ case -1:
+ case "UNRECOGNIZED":
+ default:
+ return FeatureSet_EnforceNamingStyle.UNRECOGNIZED;
+ }
+}
+
+export function featureSet_EnforceNamingStyleToJSON(object: FeatureSet_EnforceNamingStyle): string {
+ switch (object) {
+ case FeatureSet_EnforceNamingStyle.ENFORCE_NAMING_STYLE_UNKNOWN:
+ return "ENFORCE_NAMING_STYLE_UNKNOWN";
+ case FeatureSet_EnforceNamingStyle.STYLE2024:
+ return "STYLE2024";
+ case FeatureSet_EnforceNamingStyle.STYLE_LEGACY:
+ return "STYLE_LEGACY";
+ case FeatureSet_EnforceNamingStyle.UNRECOGNIZED:
+ default:
+ return "UNRECOGNIZED";
+ }
+}
+
+export function featureSet_EnforceNamingStyleToNumber(object: FeatureSet_EnforceNamingStyle): number {
+ switch (object) {
+ case FeatureSet_EnforceNamingStyle.ENFORCE_NAMING_STYLE_UNKNOWN:
+ return 0;
+ case FeatureSet_EnforceNamingStyle.STYLE2024:
+ return 1;
+ case FeatureSet_EnforceNamingStyle.STYLE_LEGACY:
+ return 2;
+ case FeatureSet_EnforceNamingStyle.UNRECOGNIZED:
+ default:
+ return -1;
+ }
+}
+
function createBaseMessageOptions(): MessageOptions {
return {
messageSetWireFormat: false,
@@ -2200,6 +2269,7 @@ function createBaseFeatureSet(): FeatureSet {
utf8Validation: FeatureSet_Utf8Validation.UTF8_VALIDATION_UNKNOWN,
messageEncoding: FeatureSet_MessageEncoding.MESSAGE_ENCODING_UNKNOWN,
jsonFormat: FeatureSet_JsonFormat.JSON_FORMAT_UNKNOWN,
+ enforceNamingStyle: FeatureSet_EnforceNamingStyle.ENFORCE_NAMING_STYLE_UNKNOWN,
};
}
@@ -2234,6 +2304,12 @@ export const FeatureSet: MessageFns<FeatureSet> = {
if (message.jsonFormat !== undefined && message.jsonFormat !== FeatureSet_JsonFormat.JSON_FORMAT_UNKNOWN) {
writer.uint32(48).int32(featureSet_JsonFormatToNumber(message.jsonFormat));
}
+ if (
+ message.enforceNamingStyle !== undefined &&
+ message.enforceNamingStyle !== FeatureSet_EnforceNamingStyle.ENFORCE_NAMING_STYLE_UNKNOWN
+ ) {
+ writer.uint32(56).int32(featureSet_EnforceNamingStyleToNumber(message.enforceNamingStyle));
+ }
return writer;
},
@@ -2292,6 +2368,14 @@ export const FeatureSet: MessageFns<FeatureSet> = {
message.jsonFormat = featureSet_JsonFormatFromJSON(reader.int32());
continue;
}
+ case 7: {
+ if (tag !== 56) {
+ break;
+ }
+
+ message.enforceNamingStyle = featureSet_EnforceNamingStyleFromJSON(reader.int32());
+ continue;
+ }
}
if ((tag & 7) === 4 || tag === 0) {
break;
@@ -2321,6 +2405,9 @@ export const FeatureSet: MessageFns<FeatureSet> = {
jsonFormat: isSet(object.jsonFormat)
? featureSet_JsonFormatFromJSON(object.jsonFormat)
: FeatureSet_JsonFormat.JSON_FORMAT_UNKNOWN,
+ enforceNamingStyle: isSet(object.enforceNamingStyle)
+ ? featureSet_EnforceNamingStyleFromJSON(object.enforceNamingStyle)
+ : FeatureSet_EnforceNamingStyle.ENFORCE_NAMING_STYLE_UNKNOWN,
};
},
@@ -2355,6 +2442,12 @@ export const FeatureSet: MessageFns<FeatureSet> = {
if (message.jsonFormat !== undefined && message.jsonFormat !== FeatureSet_JsonFormat.JSON_FORMAT_UNKNOWN) {
obj.jsonFormat = featureSet_JsonFormatToJSON(message.jsonFormat);
}
+ if (
+ message.enforceNamingStyle !== undefined &&
+ message.enforceNamingStyle !== FeatureSet_EnforceNamingStyle.ENFORCE_NAMING_STYLE_UNKNOWN
+ ) {
+ obj.enforceNamingStyle = featureSet_EnforceNamingStyleToJSON(message.enforceNamingStyle);
+ }
return obj;
},
@@ -2370,6 +2463,8 @@ export const FeatureSet: MessageFns<FeatureSet> = {
message.utf8Validation = object.utf8Validation ?? FeatureSet_Utf8Validation.UTF8_VALIDATION_UNKNOWN;
message.messageEncoding = object.messageEncoding ?? FeatureSet_MessageEncoding.MESSAGE_ENCODING_UNKNOWN;
message.jsonFormat = object.jsonFormat ?? FeatureSet_JsonFormat.JSON_FORMAT_UNKNOWN;
+ message.enforceNamingStyle = object.enforceNamingStyle ??
+ FeatureSet_EnforceNamingStyle.ENFORCE_NAMING_STYLE_UNKNOWN;
return message;
},
};
diff --git a/frontend/src/types/proto/v1/project_service.ts b/frontend/src/types/proto/v1/project_service.ts
index 39b7fec592..a2896caaf7 100644
--- a/frontend/src/types/proto/v1/project_service.ts
+++ b/frontend/src/types/proto/v1/project_service.ts
@@ -201,7 +201,7 @@ export interface Project {
skipBackupErrors: boolean;
/**
* Whether to enable the database tenant mode for PostgreSQL.
- * If enabled, the issue will be created with the pre-appended "set role <db_owner>" statement.
+ * If enabled, the issue will be created with the prepend "set role <db_owner>" statement.
*/
postgresDatabaseTenantMode: boolean;
/** Whether to allow the issue creator to self-approve the issue. */
diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yaml
index be7d0e4186..98c6ac1607 100644
--- a/proto/gen/grpc-doc/openapi.yaml
+++ b/proto/gen/grpc-doc/openapi.yaml
@@ -11398,7 +11398,7 @@ components:
type: boolean
description: |-
Whether to enable the database tenant mode for PostgreSQL.
- If enabled, the issue will be created with the pre-appended "set role <db_owner>" statement.
+ If enabled, the issue will be created with the prepend "set role <db_owner>" statement.
allowSelfApproval:
type: boolean
description: Whether to allow the issue creator to self-approve the issue.
diff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.md
index 15c229bc6b..92f2149e8f 100644
--- a/proto/gen/grpc-doc/store/README.md
+++ b/proto/gen/grpc-doc/store/README.md
@@ -3541,7 +3541,7 @@ RestrictIssueCreationForSQLReviewPolicy is the policy configuration for restrict
| enforce_issue_title | [bool](#bool) | | Enforce issue title created by user instead of generated by Bytebase. |
| auto_enable_backup | [bool](#bool) | | Whether to automatically enable backup. |
| skip_backup_errors | [bool](#bool) | | Whether to skip backup errors and continue the data migration. |
-| postgres_database_tenant_mode | [bool](#bool) | | Whether to enable the database tenant mode for PostgreSQL. If enabled, the issue will be created with the pre-appended &#34;set role &lt;db_owner&gt;&#34; statement. |
+| postgres_database_tenant_mode | [bool](#bool) | | Whether to enable the database tenant mode for PostgreSQL. If enabled, the issue will be created with the prepend &#34;set role &lt;db_owner&gt;&#34; statement. |
| allow_self_approval | [bool](#bool) | | Whether to allow the issue creator to self-approve the issue. |
| execution_retry_policy | [Project.ExecutionRetryPolicy](#bytebase-store-Project-ExecutionRetryPolicy) | | Execution retry policy for the task run. |
| ci_sampling_size | [int32](#int32) | | The maximum number of databases to sample during CI data validation. Without specification, sampling is disabled, resulting in a full validation. |
diff --git a/proto/gen/grpc-doc/store/index.html b/proto/gen/grpc-doc/store/index.html
index b8c060391b..633b605524 100644
--- a/proto/gen/grpc-doc/store/index.html
+++ b/proto/gen/grpc-doc/store/index.html
@@ -9554,7 +9554,7 @@ for example, the environment resource can have the sql review config tag, like &
<td><a href="#bool">bool</a></td>
<td></td>
<td><p>Whether to enable the database tenant mode for PostgreSQL.
-If enabled, the issue will be created with the pre-appended &#34;set role &lt;db_owner&gt;&#34; statement. </p></td>
+If enabled, the issue will be created with the prepend &#34;set role &lt;db_owner&gt;&#34; statement. </p></td>
</tr>
<tr>
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index ebcf172b41..782aa3c4ae 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -8049,7 +8049,7 @@ When paginating, all other parameters provided to `ListProjects` must match the
| enforce_issue_title | [bool](#bool) | | Enforce issue title created by user instead of generated by Bytebase. |
| auto_enable_backup | [bool](#bool) | | Whether to automatically enable backup. |
| skip_backup_errors | [bool](#bool) | | Whether to skip backup errors and continue the data migration. |
-| postgres_database_tenant_mode | [bool](#bool) | | Whether to enable the database tenant mode for PostgreSQL. If enabled, the issue will be created with the pre-appended &#34;set role &lt;db_owner&gt;&#34; statement. |
+| postgres_database_tenant_mode | [bool](#bool) | | Whether to enable the database tenant mode for PostgreSQL. If enabled, the issue will be created with the prepend &#34;set role &lt;db_owner&gt;&#34; statement. |
| allow_self_approval | [bool](#bool) | | Whether to allow the issue creator to self-approve the issue. |
| execution_retry_policy | [Project.ExecutionRetryPolicy](#bytebase-v1-Project-ExecutionRetryPolicy) | | Execution retry policy for the task run. |
| ci_sampling_size | [int32](#int32) | | The maximum databases of rows to sample during CI data validation. Without specification, sampling is disabled, resulting in a full validation. |
diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.html
index 6c66160b84..6b735ee8e9 100644
--- a/proto/gen/grpc-doc/v1/index.html
+++ b/proto/gen/grpc-doc/v1/index.html
@@ -22339,7 +22339,7 @@ Format: projects/{project} </p></td>
<td><a href="#bool">bool</a></td>
<td></td>
<td><p>Whether to enable the database tenant mode for PostgreSQL.
-If enabled, the issue will be created with the pre-appended &#34;set role &lt;db_owner&gt;&#34; statement. </p></td>
+If enabled, the issue will be created with the prepend &#34;set role &lt;db_owner&gt;&#34; statement. </p></td>
</tr>
<tr>
diff --git a/proto/generated-go/store/project.pb.go b/proto/generated-go/store/project.pb.go
index 039232e413..6b888d46f5 100644
--- a/proto/generated-go/store/project.pb.go
+++ b/proto/generated-go/store/project.pb.go
@@ -97,7 +97,7 @@ type Project struct {
// Whether to skip backup errors and continue the data migration.
SkipBackupErrors bool `protobuf:"varint,8,opt,name=skip_backup_errors,json=skipBackupErrors,proto3" json:"skip_backup_errors,omitempty"`
// Whether to enable the database tenant mode for PostgreSQL.
- // If enabled, the issue will be created with the pre-appended "set role <db_owner>" statement.
+ // If enabled, the issue will be created with the prepend "set role <db_owner>" statement.
PostgresDatabaseTenantMode bool `protobuf:"varint,9,opt,name=postgres_database_tenant_mode,json=postgresDatabaseTenantMode,proto3" json:"postgres_database_tenant_mode,omitempty"`
// Whether to allow the issue creator to self-approve the issue.
AllowSelfApproval bool `protobuf:"varint,10,opt,name=allow_self_approval,json=allowSelfApproval,proto3" json:"allow_self_approval,omitempty"`
diff --git a/proto/generated-go/v1/project_service.pb.go b/proto/generated-go/v1/project_service.pb.go
index e54ede5fad..541a56bc8a 100644
--- a/proto/generated-go/v1/project_service.pb.go
+++ b/proto/generated-go/v1/project_service.pb.go
@@ -952,7 +952,7 @@ type Project struct {
// Whether to skip backup errors and continue the data migration.
SkipBackupErrors bool `protobuf:"varint,19,opt,name=skip_backup_errors,json=skipBackupErrors,proto3" json:"skip_backup_errors,omitempty"`
// Whether to enable the database tenant mode for PostgreSQL.
- // If enabled, the issue will be created with the pre-appended "set role <db_owner>" statement.
+ // If enabled, the issue will be created with the prepend "set role <db_owner>" statement.
PostgresDatabaseTenantMode bool `protobuf:"varint,20,opt,name=postgres_database_tenant_mode,json=postgresDatabaseTenantMode,proto3" json:"postgres_database_tenant_mode,omitempty"`
// Whether to allow the issue creator to self-approve the issue.
AllowSelfApproval bool `protobuf:"varint,21,opt,name=allow_self_approval,json=allowSelfApproval,proto3" json:"allow_self_approval,omitempty"`
diff --git a/proto/store/store/project.proto b/proto/store/store/project.proto
index 0343f0e97e..ad50401806 100644
--- a/proto/store/store/project.proto
+++ b/proto/store/store/project.proto
@@ -30,7 +30,7 @@ message Project {
bool skip_backup_errors = 8;
// Whether to enable the database tenant mode for PostgreSQL.
- // If enabled, the issue will be created with the pre-appended "set role <db_owner>" statement.
+ // If enabled, the issue will be created with the prepend "set role <db_owner>" statement.
bool postgres_database_tenant_mode = 9;
// Whether to allow the issue creator to self-approve the issue.
diff --git a/proto/v1/v1/project_service.proto b/proto/v1/v1/project_service.proto
index a6a8231311..10ffbc07ea 100644
--- a/proto/v1/v1/project_service.proto
+++ b/proto/v1/v1/project_service.proto
@@ -326,7 +326,7 @@ message Project {
bool skip_backup_errors = 19;
// Whether to enable the database tenant mode for PostgreSQL.
- // If enabled, the issue will be created with the pre-appended "set role <db_owner>" statement.
+ // If enabled, the issue will be created with the prepend "set role <db_owner>" statement.
bool postgres_database_tenant_mode = 20;
// Whether to allow the issue creator to self-approve the issue.