Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: support setting project `schemaMigrationType` in VCS workflow (#2457)
boojack25001833e4b9
diff --git a/frontend/src/components/RepositoryConfigPanel.vue b/frontend/src/components/RepositoryConfigPanel.vueindex 3ab19e1d89..78c96f0793 100644--- a/frontend/src/components/RepositoryConfigPanel.vue+++ b/frontend/src/components/RepositoryConfigPanel.vue@@ -5,18 +5,19 @@:vcs-name="config.vcs.name":repository-info="config.repositoryInfo":repository-config="config.repositoryConfig"+ :schema-migration-type="config.schemaMigrationType":project="project"+ @change-schema-migration-type="+ (type) => $emit('change-schema-migration-type', type)+ "/></template><script lang="ts">-import { reactive, PropType, defineComponent } from "vue";+import { PropType, defineComponent } from "vue";import RepositoryForm from "./RepositoryForm.vue";import { Project, ProjectRepositoryConfig } from "../types";-// eslint-disable-next-line @typescript-eslint/no-empty-interface-interface LocalState {}-export default defineComponent({name: "RepositoryConfigPanel",components: { RepositoryForm },@@ -30,13 +31,6 @@ export default defineComponent({type: Object as PropType<Project>,},},- emits: ["next"],- setup() {- const state = reactive<LocalState>({});-- return {- state,- };- },+ emits: ["change-schema-migration-type"],});</script>diff --git a/frontend/src/components/RepositoryForm.vue b/frontend/src/components/RepositoryForm.vueindex 9e9ff7b969..4f76d56d12 100644--- a/frontend/src/components/RepositoryForm.vue+++ b/frontend/src/components/RepositoryForm.vue@@ -71,7 +71,33 @@:disabled="!allowEdit"/></div>- <div>+ <!-- Project schemaMigrationType selector -->+ <div v-if="isDev">+ <div class="textlabel">+ {{ $t("project.settings.schema-migration-type") }}+ <span class="text-red-600">*</span>+ </div>+ <BBSelect+ id="schemamigrationtype"+ :selected-item="schemaMigrationType"+ :item-list="['DDL', 'SDL']"+ class="mt-1"+ @select-item="+ (type) => {+ $emit('change-schema-migration-type', type);+ }+ "+ >+ <template #menuItem="{ item }">+ {{+ $t(+ `project.settings.select-schema-migration-type-${item.toLowerCase()}`+ )+ }}+ </template>+ </BBSelect>+ </div>+ <div v-if="schemaMigrationType === 'DDL'"><div class="textlabel">{{ $t("repository.file-path-template") }}<span class="text-red-600">*</span>@@ -138,10 +164,15 @@></div><div class="mt-1 textinfolabel">- {{ $t("repository.schema-writeback-description") }}- <span class="font-medium text-main">{{- $t("repository.schema-writeback-protected-branch")- }}</span>+ <template v-if="schemaMigrationType === 'DDL'">+ {{ $t("repository.schema-writeback-description") }}+ <span class="font-medium text-main">{{+ $t("repository.schema-writeback-protected-branch")+ }}</span>+ </template>+ <template v-else>+ {{ $t("project.settings.schema-path-template-sdl-description") }}+ </template></div><inputid="schemapathtemplate"@@ -173,7 +204,7 @@}}</div></div>- <div>+ <div v-if="schemaMigrationType === 'DDL'"><div class="textlabel">{{ $t("repository.sheet-path-template") }}</div><div class="mt-1 textinfolabel">{{ $t("repository.sheet-path-template-description") }}@@ -204,6 +235,7 @@ import {ExternalRepositoryInfo,Project,RepositoryConfig,+ SchemaMigrationType,VCSType,} from "@/types";@@ -247,8 +279,12 @@ export default defineComponent({required: true,type: Object as PropType<Project>,},+ schemaMigrationType: {+ required: true,+ type: String as PropType<SchemaMigrationType>,+ },},- emits: ["change-repository"],+ emits: ["change-repository", "change-schema-migration-type"],setup(props) {const state = reactive<LocalState>({});@@ -343,9 +379,9 @@ export default defineComponent({return {FILE_REQUIRED_PLACEHOLDER,- fileOptionalPlaceholder,- FILE_OPTIONAL_DIRECTORY_WILDCARD,SCHEMA_REQUIRED_PLACEHOLDER,+ FILE_OPTIONAL_DIRECTORY_WILDCARD,+ fileOptionalPlaceholder,schemaOptionalTagPlaceholder,state,sampleFilePath,diff --git a/frontend/src/components/RepositoryPanel.vue b/frontend/src/components/RepositoryPanel.vueindex cdff122deb..d19c138a2d 100644--- a/frontend/src/components/RepositoryPanel.vue+++ b/frontend/src/components/RepositoryPanel.vue@@ -55,6 +55,8 @@:repository-info="repositoryInfo":repository-config="state.repositoryConfig":project="project"+ :schema-migration-type="state.schemaMigrationType"+ @change-schema-migration-type="(type) => (state.schemaMigrationType = type)"@change-repository="$emit('change-repository')"/><div v-if="allowEdit" class="mt-4 pt-4 flex border-t justify-between">@@ -90,12 +92,16 @@ import {ExternalRepositoryInfo,RepositoryConfig,Project,+ ProjectPatch,+ SchemaMigrationType,} from "../types";import { useI18n } from "vue-i18n";-import { pushNotification, useRepositoryStore } from "@/store";+import { pushNotification, useProjectStore, useRepositoryStore } from "@/store";+import { isDev } from "@/utils";interface LocalState {repositoryConfig: RepositoryConfig;+ schemaMigrationType: SchemaMigrationType;}export default defineComponent({@@ -127,6 +133,7 @@ export default defineComponent({schemaPathTemplate: props.repository.schemaPathTemplate,sheetPathTemplate: props.repository.sheetPathTemplate,},+ schemaMigrationType: props.project.schemaMigrationType,});watch(@@ -155,15 +162,17 @@ export default defineComponent({return (!isEmpty(state.repositoryConfig.branchFilter) &&!isEmpty(state.repositoryConfig.filePathTemplate) &&- (props.repository.branchFilter != state.repositoryConfig.branchFilter ||- props.repository.baseDirectory !=+ (props.repository.branchFilter !==+ state.repositoryConfig.branchFilter ||+ props.repository.baseDirectory !==state.repositoryConfig.baseDirectory ||- props.repository.filePathTemplate !=+ props.repository.filePathTemplate !==state.repositoryConfig.filePathTemplate ||- props.repository.schemaPathTemplate !=+ props.repository.schemaPathTemplate !==state.repositoryConfig.schemaPathTemplate ||- props.repository.sheetPathTemplate !=- state.repositoryConfig.sheetPathTemplate)+ props.repository.sheetPathTemplate !==+ state.repositoryConfig.sheetPathTemplate ||+ props.project.schemaMigrationType !== state.schemaMigrationType));});@@ -177,7 +186,7 @@ export default defineComponent({});};- const doUpdate = () => {+ const doUpdate = async () => {const repositoryPatch: RepositoryPatch = {};if (props.repository.branchFilter != state.repositoryConfig.branchFilter@@ -211,18 +220,29 @@ export default defineComponent({state.repositoryConfig.sheetPathTemplate;}- repositoryStore- .updateRepositoryByProjectId({+ // Update project schemaMigrationType field firstly.+ if (+ isDev() &&+ state.schemaMigrationType !== props.project.schemaMigrationType+ ) {+ const projectPatch: ProjectPatch = {+ schemaMigrationType: state.schemaMigrationType,+ };+ await useProjectStore().patchProject({projectId: props.project.id,- repositoryPatch,- })- .then(() => {- pushNotification({- module: "bytebase",- style: "SUCCESS",- title: t("repository.update-version-control-config-success"),- });+ projectPatch,});+ }++ await repositoryStore.updateRepositoryByProjectId({+ projectId: props.project.id,+ repositoryPatch,+ });+ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("repository.update-version-control-config-success"),+ });};return {diff --git a/frontend/src/components/RepositorySetupWizard.vue b/frontend/src/components/RepositorySetupWizard.vueindex 4991c4a057..6a7f166389 100644--- a/frontend/src/components/RepositorySetupWizard.vue+++ b/frontend/src/components/RepositorySetupWizard.vue@@ -37,7 +37,13 @@/></template><template #2>- <RepositoryConfigPanel :config="state.config" :project="project" />+ <RepositoryConfigPanel+ :config="state.config"+ :project="project"+ @change-schema-migration-type="+ (type) => (state.config.schemaMigrationType = type)+ "+ /></template></BBStepTab></div>@@ -55,14 +61,15 @@ import {ExternalRepositoryInfo,OAuthToken,Project,+ ProjectPatch,ProjectRepositoryConfig,RepositoryCreate,unknown,VCS,} from "../types";-import { projectSlug } from "../utils";+import { isDev, projectSlug } from "../utils";import { useI18n } from "vue-i18n";-import { useRepositoryStore } from "@/store";+import { useProjectStore, useRepositoryStore } from "@/store";// Default file path template is to organize migration files from different environments under separate directories.const DEFAULT_FILE_PATH_TEMPLATE =@@ -151,6 +158,7 @@ export default defineComponent({? DEFAULT_TENANT_MODE_SHEET_PATH_TEMPLATE: DEFAULT_SHEET_PATH_TEMPLATE,},+ schemaMigrationType: props.project.schemaMigrationType,},currentStep: CHOOSE_PROVIDER_STEP,});@@ -175,11 +183,26 @@ export default defineComponent({};const tryFinishSetup = (allowFinishCallback: () => void) => {- const createFunc = () => {+ const createFunc = async () => {let externalId = state.config.repositoryInfo.externalId;if (state.config.vcs.type == "GITHUB_COM") {externalId = state.config.repositoryInfo.fullPath;}++ // Update project schemaMigrationType field firstly.+ if (+ isDev() &&+ state.config.schemaMigrationType !== props.project.schemaMigrationType+ ) {+ const projectPatch: ProjectPatch = {+ schemaMigrationType: state.config.schemaMigrationType,+ };+ await useProjectStore().patchProject({+ projectId: props.project.id,+ projectPatch,+ });+ }+const repositoryCreate: RepositoryCreate = {vcsId: state.config.vcs.id,name: state.config.repositoryInfo.name,@@ -195,16 +218,14 @@ export default defineComponent({expiresTs: state.config.token.expiresTs,refreshToken: state.config.token.refreshToken,};- repositoryStore- .createRepository({- projectId: props.project.id,- repositoryCreate,- })- .then(() => {- allowFinishCallback();- emit("finish");- });+ await repositoryStore.createRepository({+ projectId: props.project.id,+ repositoryCreate,+ });+ allowFinishCallback();+ emit("finish");};+if (props.create) {createFunc();} else {diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex f1249562c1..e409d546d7 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1060,7 +1060,11 @@"sync-from-vcs": "Sync from VCS","success-member-sync-prompt": "Sync member from VCS Succeeded","view-vcs-member": "View members in VCS",- "switch-role-provider-to-bytebase-success-prompt": "Successfully turning off VCS project membership sync."+ "switch-role-provider-to-bytebase-success-prompt": "Successfully turning off VCS project membership sync.",+ "schema-migration-type": "Schema migration type",+ "select-schema-migration-type-ddl": "Data Definition Language (DDL)",+ "select-schema-migration-type-sdl": "Schema Definition Language (SDL)",+ "schema-path-template-sdl-description": "The schema file that contains the desired state of the database schema. Bytebase creates new migrations for any discrepancy found between the desired state and the actual database schema."},"mode": {"standard": "Standard",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex c8065a6ad2..56f85dc68a 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1060,7 +1060,11 @@"sync-from-vcs": "从 VCS 同步","success-member-sync-prompt": "从 VCS 同步成功","view-vcs-member": "在 VCS 中查看成员",- "switch-role-provider-to-bytebase-success-prompt": "成功关闭了 VCS 项目成员同步"+ "switch-role-provider-to-bytebase-success-prompt": "成功关闭了 VCS 项目成员同步",+ "schema-migration-type": "Schema 迁移类型",+ "select-schema-migration-type-ddl": "数据定义语言(DDL)",+ "select-schema-migration-type-sdl": "Schema 定义语言(SDL)",+ "schema-path-template-sdl-description": "Schema 定义文件应该包括了数据库 Schema 所在的状态。Bytebase 将会为在 Schema 状态和实际数据库之间发现的任何差异创建新的迁移。"},"mode": {"standard": "标准",diff --git a/frontend/src/store/modules/project.ts b/frontend/src/store/modules/project.tsindex 579b6deb2a..d83638f33a 100644--- a/frontend/src/store/modules/project.ts+++ b/frontend/src/store/modules/project.ts@@ -51,6 +51,7 @@ function convert(tenantMode: attrs.tenantMode,dbNameTemplate: attrs.dbNameTemplate,roleProvider: attrs.roleProvider,+ schemaMigrationType: attrs.schemaMigrationType,};const memberList: ProjectMember[] = [];diff --git a/frontend/src/types/project.ts b/frontend/src/types/project.tsindex 876455a56b..a20ef84cd6 100644--- a/frontend/src/types/project.ts+++ b/frontend/src/types/project.ts@@ -18,6 +18,8 @@ export type ProjectRoleProvider =| "GITHUB_COM"| "BYTEBASE";+export type SchemaMigrationType = "DDL" | "SDL";+export type ProjectRoleProviderPayload = {vcsRole: string;lastSyncTs: number;@@ -50,6 +52,7 @@ export type Project = {tenantMode: ProjectTenantMode;dbNameTemplate: string;roleProvider: ProjectRoleProvider;+ schemaMigrationType: SchemaMigrationType;};export type ProjectCreate = {@@ -59,6 +62,7 @@ export type ProjectCreate = {tenantMode: ProjectTenantMode;dbNameTemplate: string;roleProvider: ProjectRoleProvider;+ schemaMigrationType: SchemaMigrationType;};export type ProjectPatch = {@@ -69,6 +73,7 @@ export type ProjectPatch = {name?: string;key?: string;roleProvider?: ProjectRoleProvider;+ schemaMigrationType?: SchemaMigrationType;};// Project Member@@ -111,4 +116,5 @@ export type ProjectRepositoryConfig = {code: string;repositoryInfo: ExternalRepositoryInfo;repositoryConfig: RepositoryConfig;+ schemaMigrationType: SchemaMigrationType;};diff --git a/frontend/src/types/repository.ts b/frontend/src/types/repository.tsindex d074cc491b..c15520f34e 100644--- a/frontend/src/types/repository.ts+++ b/frontend/src/types/repository.ts@@ -1,5 +1,5 @@import isEmpty from "lodash-es/isEmpty";-import { ProjectId, RepositoryId, VCSId } from "./id";+import { RepositoryId, VCSId } from "./id";import { Principal } from "./principal";import { Project } from "./project";import { VCS } from "./vcs";