Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Create a separete EnvironmentPatch model
天舟757d7b1c9732
diff --git a/frontend/src/components/EnvironmentForm.vue b/frontend/src/components/EnvironmentForm.vueindex 42dfbe776d..0899985f09 100644--- a/frontend/src/components/EnvironmentForm.vue+++ b/frontend/src/components/EnvironmentForm.vue@@ -1,8 +1,5 @@<template>- <form- class="px-4 space-y-6 divide-y divide-gray-200"- @submit.prevent="$emit('submit', state.environment)"- >+ <div class="px-4 space-y-6 divide-y divide-gray-200"><div class="pt-6 grid grid-cols-1 gap-y-6 gap-x-4"><div class="col-span-1"><label for="name" class="text-lg leading-6 font-medium text-control">@@ -31,6 +28,7 @@type="submit"class="btn-primary ml-3 inline-flex justify-center py-2 px-4":disabled="!allowCreate"+ @click.prevent="createEnvironment">Create</button>@@ -58,13 +56,14 @@type="submit"class="btn-primary ml-3 inline-flex justify-center py-2 px-4":disabled="!valueChanged"+ @click.prevent="updateEnvironment">Update</button></div></div></template>- </form>+ </div></template><script lang="ts">@@ -73,16 +72,16 @@ import { useStore } from "vuex";import cloneDeep from "lodash-es/cloneDeep";import isEqual from "lodash-es/isEqual";import isEmpty from "lodash-es/isEmpty";-import { Environment, EnvironmentNew } from "../types";+import { Environment, EnvironmentNew, EnvironmentPatch } from "../types";import { isDBA } from "../utils";interface LocalState {- environment?: Environment | EnvironmentNew;+ environment: Environment | EnvironmentNew;}export default {name: "EnvironmentForm",- emits: ["submit", "cancel", "delete"],+ emits: ["create", "update", "cancel", "delete"],props: {create: {type: Boolean,@@ -98,22 +97,18 @@ export default {type: Object as PropType<Environment>,},},- setup(props, ctx) {+ setup(props, { emit }) {const store = useStore();- const state = reactive<LocalState>({});+ const state = reactive<LocalState>({+ environment: props.environment+ ? cloneDeep(props.environment)+ : {+ name: "New Env",+ },+ });const currentUser = computed(() => store.getters["auth/currentUser"]());- // [NOTE] Ternary operator doesn't trigger VS type checking, so we use a separate- // IF block.- if (props.environment) {- state.environment = cloneDeep(props.environment);- } else {- state.environment = {- name: "New Env",- };- }-const allowEdit = computed(() => {return isDBA(currentUser.value.role);});@@ -127,7 +122,20 @@ export default {});const revertEnvironment = () => {- state.environment = cloneDeep(props.environment);+ state.environment = cloneDeep(props.environment!);+ };++ const createEnvironment = () => {+ emit("create", state.environment);+ };++ const updateEnvironment = () => {+ const patchedEnvironment: EnvironmentPatch = {};++ if (state.environment.name != props.environment!.name) {+ patchedEnvironment.name = state.environment.name;+ }+ emit("update", patchedEnvironment);};return {@@ -136,6 +144,8 @@ export default {valueChanged,allowCreate,revertEnvironment,+ createEnvironment,+ updateEnvironment,};},};diff --git a/frontend/src/miragejs/factories/environmentPatch.js b/frontend/src/miragejs/factories/environmentPatch.jsnew file mode 100644index 0000000000..88f009cc18--- /dev/null+++ b/frontend/src/miragejs/factories/environmentPatch.js@@ -0,0 +1,12 @@+import { Factory } from "miragejs";++export default {+ environmentPatch: Factory.extend({+ rowStatus() {+ return "ARCHIVED";+ },+ name() {+ return "Updated environment";+ },+ }),+};diff --git a/frontend/src/miragejs/factories/index.js b/frontend/src/miragejs/factories/index.jsindex 0dea89c0c7..eb3a538e7e 100644--- a/frontend/src/miragejs/factories/index.js+++ b/frontend/src/miragejs/factories/index.js@@ -2,6 +2,7 @@ import user from "./user";import bookmark from "./bookmark";import environment from "./environment";import environmentNew from "./environmentNew";+import environmentPatch from "./environmentPatch";import instance from "./instance";import instanceNew from "./instanceNew";import dataSource from "./dataSource";@@ -32,6 +33,7 @@ export default {...bookmark,...environment,...environmentNew,+ ...environmentPatch,...instance,...instanceNew,...dataSource,diff --git a/frontend/src/miragejs/models/index.js b/frontend/src/miragejs/models/index.jsindex df59eb78de..3622782927 100644--- a/frontend/src/miragejs/models/index.js+++ b/frontend/src/miragejs/models/index.js@@ -56,6 +56,8 @@ export default {environmentNew: Model,+ environmentPatch: Model,+instance: Model.extend({workspace: belongsTo(),environment: belongsTo(),diff --git a/frontend/src/miragejs/routes/environment.js b/frontend/src/miragejs/routes/environment.jsindex c6d58670ec..02d951368d 100644--- a/frontend/src/miragejs/routes/environment.js+++ b/frontend/src/miragejs/routes/environment.js@@ -67,7 +67,7 @@ export default function configureEnvironment(route) {});route.patch("/environment/:environmentId", function (schema, request) {- const attrs = this.normalizedRequestAttrs("environment");+ const attrs = this.normalizedRequestAttrs("environment-patch");return schema.environments.find(request.params.environmentId).update(attrs);});diff --git a/frontend/src/store/modules/environment.ts b/frontend/src/store/modules/environment.tsindex c455394d6c..b1e739d606 100644--- a/frontend/src/store/modules/environment.ts+++ b/frontend/src/store/modules/environment.ts@@ -6,6 +6,7 @@ import {EnvironmentState,ResourceObject,unknown,+ EnvironmentPatch,} from "../../types";function convert(environment: ResourceObject): Environment {@@ -90,14 +91,22 @@ const actions = {return environmentList;},- async patchEnvironment({ commit }: any, environment: Environment) {- const { id, ...attrs } = environment;+ async patchEnvironment(+ { commit }: any,+ {+ environmentId,+ environmentPatch,+ }: {+ environmentId: EnvironmentId;+ environmentPatch: EnvironmentPatch;+ }+ ) {const updatedEnvironment = convert((- await axios.patch(`/api/environment/${environment.id}`, {+ await axios.patch(`/api/environment/${environmentId}`, {data: {- type: "environment",- attributes: attrs,+ type: "environmentpatch",+ attributes: environmentPatch,},})).data.datadiff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.tsindex 441bd77dc7..130d4b6c69 100644--- a/frontend/src/types/bytebase.ts+++ b/frontend/src/types/bytebase.ts@@ -594,6 +594,10 @@ export type EnvironmentNew = {name: string;};+export type EnvironmentPatch = {+ name?: string;+};+// Instanceexport type Instance = {id: InstanceId;diff --git a/frontend/src/views/EnvironmentDashboard.vue b/frontend/src/views/EnvironmentDashboard.vueindex c97e28e68a..f31d9ab29d 100644--- a/frontend/src/views/EnvironmentDashboard.vue+++ b/frontend/src/views/EnvironmentDashboard.vue@@ -45,7 +45,7 @@><EnvironmentForm:create="true"- @submit="doCreate"+ @create="doCreate"@cancel="state.showCreateModal = false"/></BBModal>diff --git a/frontend/src/views/EnvironmentDetail.vue b/frontend/src/views/EnvironmentDetail.vueindex 67cf636f97..ef537eb6be 100644--- a/frontend/src/views/EnvironmentDetail.vue+++ b/frontend/src/views/EnvironmentDetail.vue@@ -3,7 +3,7 @@v-if="state.environment":allowDelete="allowDelete":environment="state.environment"- @submit="doUpdate"+ @update="doUpdate"@delete="state.showDeleteModal = true"/><BBAlert@@ -28,7 +28,7 @@ import { reactive, PropType } from "vue";import { useStore } from "vuex";import { useRouter } from "vue-router";import EnvironmentForm from "../components/EnvironmentForm.vue";-import { Environment } from "../types";+import { Environment, EnvironmentPatch } from "../types";export default {name: "EnvironmentDetail",@@ -60,9 +60,12 @@ export default {state.environment = environment;};- const doUpdate = (updatedEnvironment: Environment) => {+ const doUpdate = (environmentPatch: EnvironmentPatch) => {store- .dispatch("environment/patchEnvironment", updatedEnvironment)+ .dispatch("environment/patchEnvironment", {+ environmentId: props.environment.id,+ environmentPatch,+ }).then((environment) => {assignEnvironment(environment);})