Skip to content

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

feat: add `sheetPathTemplate` for repository in frontend (#1076)

STEVENe82b1e0ddcca
diff --git a/frontend/src/components/RepositoryForm.vue b/frontend/src/components/RepositoryForm.vue
index ec84461bd7..cfd5d606ce 100644
--- a/frontend/src/components/RepositoryForm.vue
+++ b/frontend/src/components/RepositoryForm.vue
@@ -127,7 +127,8 @@
}}
</div>
</div>
- <div>
+ <!-- TODO(Steven): remove the isDev flag when release v1.1.0 -->
+ <div v-if="isDev()">
<div class="textlabel">
{{ $t("repository.schema-path-template") }}
<a
@@ -174,6 +175,28 @@
}}
</div>
</div>
+ <div>
+ <div class="textlabel">{{ $t("repository.sheet-path-template") }}</div>
+ <div class="mt-1 textinfolabel">
+ {{ $t("repository.sheet-path-template-description") }}
+ </div>
+ <input
+ id="sheetpathtemplate"
+ v-model="repositoryConfig.sheetPathTemplate"
+ name="sheetpathtemplate"
+ type="text"
+ class="textfield mt-2 w-full"
+ :disabled="!allowEdit"
+ />
+ <div class="mt-2 textinfolabel capitalize">
+ <span class="text-red-600">*</span>
+ {{ $t("common.required-placeholder") }}: {{ "\{\{NAME\}\}" }};
+ <template v-if="schemaOptionalTagPlaceholder.length > 0">
+ {{ $t("common.optional-placeholder") }}: {{ "\{\{ENV_NAME\}\}" }},
+ {{ "\{\{DB_NAME\}\}" }}
+ </template>
+ </div>
+ </div>
</div>
</template>
@@ -184,7 +207,8 @@ import {
Project,
RepositoryConfig,
VCSType,
-} from "../types";
+} from "@/types";
+import { isDev } from "@/utils";
const FILE_REQUIRED_PLACEHOLDER = "{{DB_NAME}}, {{VERSION}}, {{TYPE}}";
const SCHEMA_REQUIRED_PLACEHOLDER = "{{DB_NAME}}";
@@ -320,6 +344,7 @@ export default defineComponent({
state,
sampleFilePath,
sampleSchemaPath,
+ isDev,
};
},
});
diff --git a/frontend/src/components/RepositoryPanel.vue b/frontend/src/components/RepositoryPanel.vue
index c51c1ed6db..cdff122deb 100644
--- a/frontend/src/components/RepositoryPanel.vue
+++ b/frontend/src/components/RepositoryPanel.vue
@@ -125,6 +125,7 @@ export default defineComponent({
branchFilter: props.repository.branchFilter,
filePathTemplate: props.repository.filePathTemplate,
schemaPathTemplate: props.repository.schemaPathTemplate,
+ sheetPathTemplate: props.repository.sheetPathTemplate,
},
});
@@ -136,6 +137,7 @@ export default defineComponent({
branchFilter: cur.branchFilter,
filePathTemplate: cur.filePathTemplate,
schemaPathTemplate: cur.schemaPathTemplate,
+ sheetPathTemplate: cur.sheetPathTemplate,
};
}
);
@@ -159,7 +161,9 @@ export default defineComponent({
props.repository.filePathTemplate !=
state.repositoryConfig.filePathTemplate ||
props.repository.schemaPathTemplate !=
- state.repositoryConfig.schemaPathTemplate)
+ state.repositoryConfig.schemaPathTemplate ||
+ props.repository.sheetPathTemplate !=
+ state.repositoryConfig.sheetPathTemplate)
);
});
@@ -199,6 +203,14 @@ export default defineComponent({
repositoryPatch.schemaPathTemplate =
state.repositoryConfig.schemaPathTemplate;
}
+ if (
+ props.repository.sheetPathTemplate !=
+ state.repositoryConfig.sheetPathTemplate
+ ) {
+ repositoryPatch.sheetPathTemplate =
+ state.repositoryConfig.sheetPathTemplate;
+ }
+
repositoryStore
.updateRepositoryByProjectId({
projectId: props.project.id,
diff --git a/frontend/src/components/RepositorySetupWizard.vue b/frontend/src/components/RepositorySetupWizard.vue
index 97ef79a90d..07b84fe644 100644
--- a/frontend/src/components/RepositorySetupWizard.vue
+++ b/frontend/src/components/RepositorySetupWizard.vue
@@ -69,11 +69,15 @@ const DEFAULT_FILE_PATH_TEMPLATE =
"{{ENV_NAME}}/{{DB_NAME}}__{{VERSION}}__{{TYPE}}__{{DESCRIPTION}}.sql";
// Default schema path template is co-locate with the corresponding db's migration files and use .(dot) to appear the first.
const DEFAULT_SCHEMA_PATH_TEMPLATE = "{{ENV_NAME}}/.{{DB_NAME}}__LATEST.sql";
+// Default sheet path tempalte is to organize script files for SQL Editor.
+const DEFAULT_SHEET_PATH_TEMPLATE =
+ "script/{{ENV_NAME}}__{{DB_NAME}}__{{NAME}}.sql";
// For tenant mode projects, {{ENV_NAME}} is not supported.
const DEFAULT_TENANT_MODE_FILE_PATH_TEMPLATE =
"{{DB_NAME}}__{{VERSION}}__{{TYPE}}__{{DESCRIPTION}}.sql";
const DEFAULT_TENANT_MODE_SCHEMA_PATH_TEMPLATE = ".{{DB_NAME}}__LATEST.sql";
+const DEFAULT_TENANT_MODE_SHEET_PATH_TEMPLATE = "script/{{NAME}}.sql";
const CHOOSE_PROVIDER_STEP = 0;
// const CHOOSE_REPOSITORY_STEP = 1;
@@ -143,6 +147,9 @@ export default defineComponent({
schemaPathTemplate: isTenantProject.value
? DEFAULT_TENANT_MODE_SCHEMA_PATH_TEMPLATE
: DEFAULT_SCHEMA_PATH_TEMPLATE,
+ sheetPathTemplate: isTenantProject.value
+ ? DEFAULT_TENANT_MODE_SHEET_PATH_TEMPLATE
+ : DEFAULT_SHEET_PATH_TEMPLATE,
},
},
currentStep: CHOOSE_PROVIDER_STEP,
@@ -178,6 +185,7 @@ export default defineComponent({
baseDirectory: state.config.repositoryConfig.baseDirectory,
filePathTemplate: state.config.repositoryConfig.filePathTemplate,
schemaPathTemplate: state.config.repositoryConfig.schemaPathTemplate,
+ sheetPathTemplate: state.config.repositoryConfig.sheetPathTemplate,
externalId: state.config.repositoryInfo.externalId,
accessToken: state.config.token.accessToken,
expiresTs: state.config.token.expiresTs,
diff --git a/frontend/src/locales/en.yml b/frontend/src/locales/en.yml
index 4f2afb4e6e..55b966998c 100644
--- a/frontend/src/locales/en.yml
+++ b/frontend/src/locales/en.yml
@@ -817,6 +817,9 @@ repository:
to push to that protected branch.
if-specified: If specified
schema-path-example: Schema path example
+ sheet-path-template: Sheet path template
+ sheet-path-template-description: >-
+ Bytebase only observes files with pathnames matching the template pattern relative to the base directory. The matched files will be synchronized to the SQL Editor for usage there.
git-provider: Git provider
version-control-status: "@.capitalize:common.version-control is {status}"
version-control-description-file-path: >-
diff --git a/frontend/src/locales/zh-CN.yml b/frontend/src/locales/zh-CN.yml
index 16260af2e9..4fcfa48e88 100644
--- a/frontend/src/locales/zh-CN.yml
+++ b/frontend/src/locales/zh-CN.yml
@@ -735,6 +735,8 @@ repository:
schema-writeback-protected-branch: 请保证被变更的分支不是处于保护 (protected) 状态,或者仓库允许他的 maintainer 可以推送变更到保护分支。
if-specified: 如果指定
schema-path-example: Schema 路径样例
+ sheet-path-template: 工作表路径模板
+ sheet-path-template-description: Bytebase 仅跟踪文件路径匹配模版 (相对于指定根目录)的文件。匹配的文件将被同步到 SQL Editor 以供使用。
git-provider: Git 提供方
version-control-status: "@.capitalize:common.version-control 已{status}"
version-control-description-file-path: 数据库迁移脚本存放在 {fullPath}。为了进行一次变更,开发者需要创建一个匹配 {fullPathTemplate} 文件路径格式的迁移脚本。
diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.ts
index 60719104cf..5ab474b11a 100644
--- a/frontend/src/types/common.ts
+++ b/frontend/src/types/common.ts
@@ -435,6 +435,7 @@ const makeUnknown = (type: ResourceType) => {
branchFilter: "",
filePathTemplate: "",
schemaPathTemplate: "",
+ sheetPathTemplate: "",
externalId: UNKNOWN_ID.toString(),
};
@@ -805,6 +806,7 @@ const makeEmpty = (type: ResourceType) => {
branchFilter: "",
filePathTemplate: "",
schemaPathTemplate: "",
+ sheetPathTemplate: "",
externalId: EMPTY_ID.toString(),
};
diff --git a/frontend/src/types/repository.ts b/frontend/src/types/repository.ts
index d7bbaf94cb..17695b937e 100644
--- a/frontend/src/types/repository.ts
+++ b/frontend/src/types/repository.ts
@@ -28,6 +28,7 @@ export type Repository = {
branchFilter: string;
filePathTemplate: string;
schemaPathTemplate: string;
+ sheetPathTemplate: string;
// e.g. In GitLab, this is the corresponding project id.
externalId: string;
};
@@ -44,6 +45,7 @@ export type RepositoryCreate = {
baseDirectory: string;
filePathTemplate: string;
schemaPathTemplate: string;
+ sheetPathTemplate: string;
externalId: string;
accessToken: string;
expiresTs: number;
@@ -55,6 +57,7 @@ export type RepositoryPatch = {
branchFilter?: string;
filePathTemplate?: string;
schemaPathTemplate?: string;
+ sheetPathTemplate?: string;
};
export type RepositoryConfig = {
@@ -62,6 +65,7 @@ export type RepositoryConfig = {
branchFilter: string;
filePathTemplate: string;
schemaPathTemplate: string;
+ sheetPathTemplate: string;
};
export type ExternalRepositoryInfo = {
diff --git a/store/demo/dev/10180__repository.sql b/store/demo/dev/10180__repository.sql
index 0daf1bec99..9f480de32e 100644
--- a/store/demo/dev/10180__repository.sql
+++ b/store/demo/dev/10180__repository.sql
@@ -13,6 +13,7 @@ INSERT INTO
base_directory,
file_path_template,
schema_path_template,
+ sheet_path_template,
external_id,
external_webhook_id,
webhook_url_host,
@@ -36,6 +37,7 @@ VALUES
'bytebase',
'{{ENV_NAME}}/{{DB_NAME}}__{{VERSION}}__{{TYPE}}__{{DESCRIPTION}}.sql',
'{{ENV_NAME}}/.{{DB_NAME}}__LATEST.sql',
+ 'script/{{NAME}}.sql',
-- Refers to the bytebase-demo/blog
'13',
-- Refers to the webhook in bytebase-demo/blog
@@ -62,6 +64,7 @@ INSERT INTO
base_directory,
file_path_template,
schema_path_template,
+ sheet_path_template,
external_id,
external_webhook_id,
webhook_url_host,
@@ -85,6 +88,7 @@ VALUES
'bytebase',
'{{ENV_NAME}}/{{DB_NAME}}__{{VERSION}}__{{TYPE}}__{{DESCRIPTION}}.sql',
'{{ENV_NAME}}/.{{DB_NAME}}__LATEST.sql',
+ 'script/{{ENV_NAME}}__{{DB_NAME}}__{{NAME}}.sql',
-- Refers to the bytebase-demo/shop
'14',
-- Refers to the webhook in bytebase-demo/shop