Skip to content

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

Implement change repository

天舟6aaa76463a57
diff --git a/frontend/src/components/ProjectVersionControlPanel.vue b/frontend/src/components/ProjectVersionControlPanel.vue
index 0fc5dead74..c69e20617b 100644
--- a/frontend/src/components/ProjectVersionControlPanel.vue
+++ b/frontend/src/components/ProjectVersionControlPanel.vue
@@ -1,6 +1,7 @@
<template>
- <template v-if="state.showWizard">
+ <template v-if="state.showWizardForCreate || state.showWizardForChange">
<RepositorySetupWizard
+ :create="state.showWizardForCreate"
:project="project"
@cancel="cancelWizard"
@finish="finishWizard"
@@ -59,9 +60,9 @@
<button
type="button"
class="btn-primary inline-flex justify-center py-2 px-2"
- @click.prevent="enterWizard"
+ @click.prevent="enterWizard(true)"
>
- Config workflow
+ Configure version control
<svg
class="ml-1 w-5 h-5"
fill="none"
@@ -81,7 +82,11 @@
</template>
</template>
<template v-else-if="project.workflowType == 'VCS'">
- <RepositoryDetail :project="project" :repository="repository" />
+ <RepositoryDetail
+ :project="project"
+ :repository="repository"
+ @change-repository="enterWizard(false)"
+ />
</template>
</template>
</template>
@@ -96,7 +101,8 @@ import { useStore } from "vuex";
interface LocalState {
workflowType: ProjectWorkflowType;
- showWizard: boolean;
+ showWizardForCreate: boolean;
+ showWizardForChange: boolean;
}
export default {
@@ -115,7 +121,8 @@ export default {
const store = useStore();
const state = reactive<LocalState>({
workflowType: props.project.workflowType,
- showWizard: false,
+ showWizardForCreate: false,
+ showWizardForChange: false,
});
const prepareRepository = () => {
@@ -137,22 +144,30 @@ export default {
);
});
- const enterWizard = () => {
- state.showWizard = true;
+ const enterWizard = (create: boolean) => {
+ if (create) {
+ state.showWizardForCreate = true;
+ } else {
+ state.showWizardForChange = true;
+ }
};
const cancelWizard = () => {
state.workflowType = "UI";
- state.showWizard = false;
+ state.showWizardForCreate = false;
+ state.showWizardForChange = false;
};
const finishWizard = () => {
- state.showWizard = false;
store.dispatch("notification/pushNotification", {
module: "bytebase",
style: "SUCCESS",
- title: `Successfully enabled version control workflow for '${props.project.name}'`,
+ title: state.showWizardForCreate
+ ? `Successfully enabled version control workflow for '${props.project.name}'`
+ : `Successfully changed repository for '${props.project.name}'`,
});
+ state.showWizardForCreate = false;
+ state.showWizardForChange = false;
};
return {
diff --git a/frontend/src/components/RepositoryConfigPanel.vue b/frontend/src/components/RepositoryConfigPanel.vue
index b3488f1141..d65e43840f 100644
--- a/frontend/src/components/RepositoryConfigPanel.vue
+++ b/frontend/src/components/RepositoryConfigPanel.vue
@@ -1,5 +1,6 @@
<template>
<RepositoryForm
+ :create="true"
:vcsType="config.vcs.type"
:vcsName="config.vcs.name"
:repositoryInfo="config.repositoryInfo"
diff --git a/frontend/src/components/RepositoryDetail.vue b/frontend/src/components/RepositoryDetail.vue
index b4bda7e1ff..fb336a9a82 100644
--- a/frontend/src/components/RepositoryDetail.vue
+++ b/frontend/src/components/RepositoryDetail.vue
@@ -1,18 +1,24 @@
<template>
<div class="text-lg leading-6 font-medium text-main">
- Version control is enabled
+ Version control is <span class="text-success">enabled</span>
</div>
- <div class="mt-1 textinfolabel">
+ <div class="mt-2 textinfolabel">
Database migration scripts are stored in
<a class="normal-link" :href="repository.webURL" target="_blank">{{
repository.fullPath
}}</a
>. To make schema changes, a developer would create a migration script under
- base directory <span class="text-main">/{{ repository.baseDirectory }}</span
- >. After the script is review approved and merged into the branch matching
- pattern <span class="text-main">{{ repository.branchFilter }}</span
- >, Bytebase will automatically kicks off the task to apply the new schema
- change.
+ base directory
+ <span class="font-medium text-main">/{{ repository.baseDirectory }}</span
+ >. After the script is review approved and merged into the
+ <template v-if="repository.branchFilter"
+ >branch matching pattern
+ <span class="font-medium text-main">{{
+ repository.branchFilter
+ }}</span></template
+ >
+ <span v-else class="font-medium text-main">default branch</span>, Bytebase
+ will automatically kicks off the task to apply the new schema change.
</div>
<RepositoryForm
class="mt-4"
@@ -20,6 +26,7 @@
:vcsName="repository.vcs.name"
:repositoryInfo="repositoryInfo"
:repositoryConfig="state.repositoryConfig"
+ @change-repository="$emit('change-repository')"
/>
<div class="mt-4 pt-4 flex border-t justify-between">
<BBButtonConfirm
@@ -62,6 +69,7 @@ interface LocalState {
export default {
name: "RepositoryDetail",
+ emits: ["change-repository"],
components: { RepositoryForm },
props: {
project: {
diff --git a/frontend/src/components/RepositoryForm.vue b/frontend/src/components/RepositoryForm.vue
index 8ab9a890db..804a92d0a4 100644
--- a/frontend/src/components/RepositoryForm.vue
+++ b/frontend/src/components/RepositoryForm.vue
@@ -19,25 +19,13 @@
<div>
<div class="flex flex-row space-x-2 items-center">
<label for="repository" class="textlabel"> Repository </label>
- <button
- class="ml-1 btn-icon"
- @click.prevent="window.open(urlfy(repositoryInfo.webURL), '_blank')"
+ <div
+ v-if="!create"
+ class="ml-1 normal-link text-sm"
+ @click.prevent="$emit('change-repository')"
>
- <svg
- class="w-4 h-4"
- fill="none"
- stroke="currentColor"
- viewBox="0 0 24 24"
- xmlns="http://www.w3.org/2000/svg"
- >
- <path
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"
- ></path>
- </svg>
- </button>
+ Change
+ </div>
</div>
<input
id="repository"
@@ -66,8 +54,8 @@
<div>
<div class="textlabel">Branch</div>
<div class="mt-1 textinfolabel">
- The branch where Bytebase will observe the SQL file (.sql) change. If
- empty, then Bytebase will observe the default branch (normally it's the
+ The branch where Bytebase observes the SQL file (.sql) change. If empty,
+ then Bytebase will observe the default branch (normally it's the
'master' or 'main' branch).
</div>
<input
@@ -94,7 +82,12 @@ interface LocalState {}
export default {
name: "RepositoryForm",
+ emits: ["change-repository"],
props: {
+ create: {
+ type: Boolean,
+ default: false,
+ },
vcsType: {
required: true,
type: String as PropType<VCSType>,
diff --git a/frontend/src/components/RepositorySelectionPanel.vue b/frontend/src/components/RepositorySelectionPanel.vue
index 2b18613dd1..2d257cd128 100644
--- a/frontend/src/components/RepositorySelectionPanel.vue
+++ b/frontend/src/components/RepositorySelectionPanel.vue
@@ -100,7 +100,7 @@ export default {
const attentionText = computed((): string => {
if (props.config.vcs.type == "GITLAB_SELF_HOST") {
- return "Bytebase only lists GitLab projects where you have at least the maintainer role, which allows to configure the project webhook to observe the code push event.";
+ return "Bytebase only lists GitLab projects granting you at least the 'Maintainer' role, which allows to configure the project webhook to observe the code push event.";
}
return "";
});
diff --git a/frontend/src/components/RepositorySetupWizard.vue b/frontend/src/components/RepositorySetupWizard.vue
index eaef5bcf86..a4e9865132 100644
--- a/frontend/src/components/RepositorySetupWizard.vue
+++ b/frontend/src/components/RepositorySetupWizard.vue
@@ -25,14 +25,12 @@ import { PropType } from "@vue/runtime-core";
import { BBStepTabItem } from "../bbkit/types";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
-import isEmpty from "lodash-es/isEmpty";
import RepositoryVCSPanel from "./RepositoryVCSPanel.vue";
import RepositorySelectionPanel from "./RepositorySelectionPanel.vue";
import RepositoryConfigPanel from "./RepositoryConfigPanel.vue";
import {
Project,
ProjectRepositoryConfig,
- Repository,
RepositoryCreate,
unknown,
VCS,
@@ -64,6 +62,11 @@ export default {
RepositoryConfigPanel,
},
props: {
+ // If false, then we intend to change the existing linked repository intead of just linking a new repository.
+ create: {
+ type: Boolean,
+ default: false,
+ },
project: {
required: true,
type: Object as PropType<Project>,
@@ -105,33 +108,47 @@ export default {
};
const tryFinishSetup = (allowFinishCallback: () => void) => {
- store
- .dispatch("gitlab/createWebhook", {
- vcs: state.config.vcs,
- projectId: state.config.repositoryInfo.externalId,
- branchFilter: state.config.repositoryConfig.branchFilter,
- token: state.config.token.accessToken,
- })
- .then((webhook: WebhookInfo) => {
- const repositoryCreate: RepositoryCreate = {
- vcsId: state.config.vcs.id,
- projectId: props.project.id,
- name: state.config.repositoryInfo.name,
- fullPath: state.config.repositoryInfo.fullPath,
- webURL: state.config.repositoryInfo.webURL,
- baseDirectory: state.config.repositoryConfig.baseDirectory,
+ const createFunc = () => {
+ store
+ .dispatch("gitlab/createWebhook", {
+ vcs: state.config.vcs,
+ projectId: state.config.repositoryInfo.externalId,
branchFilter: state.config.repositoryConfig.branchFilter,
- externalId: state.config.repositoryInfo.externalId,
- webhookId: webhook.id,
- webhookURL: webhook.url,
- };
- store
- .dispatch("repository/createRepository", repositoryCreate)
- .then(() => {
- allowFinishCallback();
- emit("finish");
- });
- });
+ token: state.config.token.accessToken,
+ })
+ .then((webhook: WebhookInfo) => {
+ const repositoryCreate: RepositoryCreate = {
+ vcsId: state.config.vcs.id,
+ projectId: props.project.id,
+ name: state.config.repositoryInfo.name,
+ fullPath: state.config.repositoryInfo.fullPath,
+ webURL: state.config.repositoryInfo.webURL,
+ baseDirectory: state.config.repositoryConfig.baseDirectory,
+ branchFilter: state.config.repositoryConfig.branchFilter,
+ externalId: state.config.repositoryInfo.externalId,
+ webhookId: webhook.id,
+ webhookURL: webhook.url,
+ };
+ store
+ .dispatch("repository/createRepository", repositoryCreate)
+ .then(() => {
+ allowFinishCallback();
+ emit("finish");
+ });
+ });
+ };
+ if (props.create) {
+ createFunc();
+ } else {
+ // It's simple to implement change behavior as delete followed by create.
+ // Though the delete can succeed while the create fails, this is rare, and
+ // even it happens, user can still configure it again.
+ store
+ .dispatch("repository/deleteRepositoryByProjectId", props.project.id)
+ .then(() => {
+ createFunc();
+ });
+ }
};
const cancel = () => {
diff --git a/frontend/src/components/RepositoryVCSPanel.vue b/frontend/src/components/RepositoryVCSPanel.vue
index dbe0ba28cb..438fcbb1ef 100644
--- a/frontend/src/components/RepositoryVCSPanel.vue
+++ b/frontend/src/components/RepositoryVCSPanel.vue
@@ -1,7 +1,7 @@
<template>
<div class="textlabel">
Choose the Git provider where your database schema scripts (.sql) are
- hosted. When you push the scripts change to the Git repository, Bytebase
+ hosted. When you push the changed script to the Git repository, Bytebase
will automatically applies the script change to the database.
</div>
<div class="mt-4 flex flex-wrap">