Skip to content

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

feat: disallow baseline migration initiated from VCS (#2253)

tianzhoue667d4a8ea8a
diff --git a/frontend/src/components/RepositoryForm.vue b/frontend/src/components/RepositoryForm.vue
index 9c39414d15..7c55a428f9 100644
--- a/frontend/src/components/RepositoryForm.vue
+++ b/frontend/src/components/RepositoryForm.vue
@@ -107,7 +107,7 @@
</template>
</div>
<div class="mt-2 textinfolabel">
- • {{ $t("repository.file-path-example-normal-migration") }}:
+ • {{ $t("repository.file-path-example-schema-migration") }}:
{{
sampleFilePath(
repositoryConfig.baseDirectory,
@@ -117,12 +117,12 @@
}}
</div>
<div class="mt-2 textinfolabel">
- • {{ $t("repository.file-path-example-baseline-migration") }}:
+ • {{ $t("repository.file-path-example-data-migration") }}:
{{
sampleFilePath(
repositoryConfig.baseDirectory,
repositoryConfig.filePathTemplate,
- "baseline"
+ "data"
)
}}
</div>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index cbf66b946c..27b11eefb6 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -869,8 +869,8 @@
"base-directory-description": "The root directory where Bytebase observes the file change. If empty, then it observes the entire repository.",
"file-path-template": "File path template",
"file-path-template-description": "Bytebase only observes the file path name matching the template pattern relative to the base directory.",
- "file-path-example-normal-migration": "File path example for normal migration type",
- "file-path-example-baseline-migration": "File path example for baseline migration type",
+ "file-path-example-schema-migration": "File path example for schema migration type",
+ "file-path-example-data-migration": "File path example for data migration type",
"schema-path-template": "Schema path template",
"schema-writeback-description": "When specified, after each migration, Bytebase will write the latest schema to the schema path relative to the base directory in the same branch as the original commit triggering the migration. Leave empty if you don't want Bytebase to do this.",
"schema-writeback-protected-branch": "Make sure the changed branch is not protected or allow repository maintainer to push to that protected branch.",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 038c27f98d..130514f767 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -870,8 +870,8 @@
"base-directory-description": "Bytebase 跟踪文件变更的根目录。如果为空,则他会跟踪整个仓库。",
"file-path-template": "文件路径模版",
"file-path-template-description": "Bytebase 仅会跟踪那些文件路径匹配模版 (相对于指定根目录)的文件。",
- "file-path-example-normal-migration": "针对普通变更类型的文件路径样例",
- "file-path-example-baseline-migration": "针对基线变更类型的文件路径样例",
+ "file-path-example-schema-migration": "针对 schema 变更类型的文件路径样例",
+ "file-path-example-data-migration": "针对数据变更类型的文件路径样例",
"schema-path-template": "Schema 路径模版",
"schema-writeback-description": "如果指定,在每一次变更之后,Bytebase 将把最新的 Schema 回写到本来触发变更的提交分支,回写的具体路径则是相对于前面指定的根目录。如果您不希望 Bytebase 这样做,则置为空。",
"schema-writeback-protected-branch": "请保证被变更的分支不是处于保护 (protected) 状态,或者仓库允许他的 maintainer 可以推送变更到保护分支。",
diff --git a/plugin/db/driver.go b/plugin/db/driver.go
index 7fe7e8a6d1..26475fda9c 100644
--- a/plugin/db/driver.go
+++ b/plugin/db/driver.go
@@ -283,14 +283,12 @@ func ParseMigrationInfo(filePath string, filePathTemplate string) (*MigrationInf
mi.Database = matchList[index]
case "TYPE":
switch matchList[index] {
- case "baseline":
- mi.Type = Baseline
case "data":
mi.Type = Data
case "migrate":
mi.Type = Migrate
default:
- return nil, fmt.Errorf("file path %q contains invalid migration type %q, must be 'baseline', 'migrate' or 'data'", filePath, matchList[index])
+ return nil, fmt.Errorf("file path %q contains invalid migration type %q, must be 'migrate' or 'data'", filePath, matchList[index])
}
case "DESCRIPTION":
mi.Description = matchList[index]
diff --git a/plugin/db/driver_test.go b/plugin/db/driver_test.go
index 9d49c8099b..990453121e 100644
--- a/plugin/db/driver_test.go
+++ b/plugin/db/driver_test.go
@@ -106,51 +106,6 @@ func TestParseMigrationInfo(t *testing.T) {
},
wantErr: "",
},
- {
- filePath: "db1__001foo__baseline",
- filePathTemplate: "{{DB_NAME}}__{{VERSION}}__{{TYPE}}",
- want: MigrationInfo{
- Version: "001foo",
- Namespace: "db1",
- Database: "db1",
- Environment: "",
- Source: VCS,
- Type: Baseline,
- Description: "Create db1 baseline",
- Creator: "",
- },
- wantErr: "",
- },
- {
- filePath: "db1__001foo__baseline__create_t1",
- filePathTemplate: "{{DB_NAME}}__{{VERSION}}__{{TYPE}}__{{DESCRIPTION}}",
- want: MigrationInfo{
- Version: "001foo",
- Namespace: "db1",
- Database: "db1",
- Environment: "",
- Source: VCS,
- Type: Baseline,
- Description: "Create t1",
- Creator: "",
- },
- wantErr: "",
- },
- {
- filePath: "db_shop1__001foo__baseline__create_t1",
- filePathTemplate: "{{DB_NAME}}__{{VERSION}}__{{TYPE}}__{{DESCRIPTION}}",
- want: MigrationInfo{
- Version: "001foo",
- Namespace: "db_shop1",
- Database: "db_shop1",
- Environment: "",
- Source: VCS,
- Type: Baseline,
- Description: "Create t1",
- Creator: "",
- },
- wantErr: "",
- },
{
filePath: "db_shop1__001foo__data",
filePathTemplate: "{{DB_NAME}}__{{VERSION}}__{{TYPE}}",
@@ -196,7 +151,21 @@ func TestParseMigrationInfo(t *testing.T) {
},
wantErr: "",
},
-
+ {
+ filePath: "db1__001foo__baseline",
+ filePathTemplate: "{{DB_NAME}}__{{VERSION}}__{{TYPE}}",
+ want: MigrationInfo{
+ Version: "001foo",
+ Namespace: "db1",
+ Database: "db1",
+ Environment: "",
+ Source: VCS,
+ Type: Baseline,
+ Description: "Create db1 baseline",
+ Creator: "",
+ },
+ wantErr: "contains invalid migration type \"baseline\"",
+ },
{
filePath: "db",
filePathTemplate: "{{DB_NAME}}__{{VERSION}}",