Skip to content

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

Post message after deleting an instance.

天舟d4a0adfd59e0
diff --git a/frontend/src/miragejs/factories/utils.js b/frontend/src/miragejs/factories/utils.js
index 8283fab0c8..3460d1d2cc 100644
--- a/frontend/src/miragejs/factories/utils.js
+++ b/frontend/src/miragejs/factories/utils.js
@@ -1 +1,29 @@
-export const randomNumber = quantity => Math.floor(Math.random() * quantity) + 1;
+export const randomNumber = (quantity) =>
+ Math.floor(Math.random() * quantity) + 1;
+
+export const postMessageToOwnerAndDBA = function (
+ schema,
+ creatorId,
+ messageTemplate
+) {
+ const allOwnerAndDBAs = schema.roleMappings.where((roleMapping) => {
+ return (
+ roleMapping.workspaceId == WORKSPACE_ID &&
+ (roleMapping.role == "OWNER" || roleMapping.role == "DBA")
+ );
+ }).models;
+
+ allOwnerAndDBAs.forEach((roleMapping) => {
+ messageList.push({
+ ...messageTemplate,
+ receiverId: roleMapping.principalId,
+ });
+ });
+
+ for (const message of messageList) {
+ // We only send out message if it's NOT destined to self.
+ if (creatorId != message.receiverId) {
+ schema.messages.create(message);
+ }
+ }
+};
diff --git a/frontend/src/miragejs/routes/index.js b/frontend/src/miragejs/routes/index.js
index 95ac10773b..0badcafc7b 100644
--- a/frontend/src/miragejs/routes/index.js
+++ b/frontend/src/miragejs/routes/index.js
@@ -15,6 +15,8 @@ import configureDataSource from "./dataSource";
export const WORKSPACE_ID = 1;
+export const OWNER_ID = 1;
+
export default function routes() {
// Change this value to simulate response delay.
// By default development environment has a 400ms delay.
diff --git a/frontend/src/miragejs/routes/instance.js b/frontend/src/miragejs/routes/instance.js
index 855865dab0..6ad71e8823 100644
--- a/frontend/src/miragejs/routes/instance.js
+++ b/frontend/src/miragejs/routes/instance.js
@@ -1,4 +1,5 @@
-import { WORKSPACE_ID } from "./index";
+import { postMessageToOwnerAndDBA } from "../utils";
+import { WORKSPACE_ID, OWNER_ID } from "./index";
export default function configurInstance(route) {
route.get("/instance", function (schema, request) {
@@ -37,7 +38,6 @@ export default function configurInstance(route) {
port: newInstance.port,
});
- const messageList = [];
const messageTemplate = {
containerId: createdInstance.id,
createdTs: ts,
@@ -50,27 +50,7 @@ export default function configurInstance(route) {
instanceName: createdInstance.name,
},
};
-
- const allOwnerAndDBAs = schema.roleMappings.where((roleMapping) => {
- return (
- roleMapping.workspaceId == WORKSPACE_ID &&
- (roleMapping.role == "OWNER" || roleMapping.role == "DBA")
- );
- }).models;
-
- allOwnerAndDBAs.forEach((roleMapping) => {
- messageList.push({
- ...messageTemplate,
- receiverId: roleMapping.principalId,
- });
- });
-
- for (const message of messageList) {
- // We only send out message if it's NOT destined to self.
- if (newInstance.creatorId != message.receiverId) {
- schema.messages.create(message);
- }
- }
+ postMessageToOwnerAndDBA(schema, newInstance.creatorId, messageTemplate);
return createdInstance;
});
@@ -81,6 +61,8 @@ export default function configurInstance(route) {
});
route.delete("/instance/:instanceId", function (schema, request) {
+ // NOTE, in actual implementation, we need to fetch the user from the auth context.
+ const callerId = OWNER_ID;
// Delete data source and database before instance itself.
// Otherwise, the instanceId will be set to null.
const dataSourceList = schema.dataSources.where({
@@ -93,6 +75,25 @@ export default function configurInstance(route) {
});
databaseList.models.forEach((item) => item.destroy());
- return schema.instances.find(request.params.instanceId).destroy();
+ const instance = schema.instances.find(request.params.instanceId);
+
+ if (instance) {
+ instance.destroy();
+
+ const ts = Date.now();
+ const messageTemplate = {
+ containerId: instance.id,
+ createdTs: ts,
+ lastUpdatedTs: ts,
+ type: "bb.msg.instance.delete",
+ status: "DELIVERED",
+ creatorId: callerId,
+ workspaceId: WORKSPACE_ID,
+ payload: {
+ instanceName: instance.name,
+ },
+ };
+ postMessageToOwnerAndDBA(schema, callerId, messageTemplate);
+ }
});
}
diff --git a/frontend/src/miragejs/utils.js b/frontend/src/miragejs/utils.js
new file mode 100644
index 0000000000..3ce070eefb
--- /dev/null
+++ b/frontend/src/miragejs/utils.js
@@ -0,0 +1,32 @@
+import { WORKSPACE_ID } from "./routes/index";
+
+export const randomNumber = (quantity) =>
+ Math.floor(Math.random() * quantity) + 1;
+
+export const postMessageToOwnerAndDBA = function (
+ schema,
+ creatorId,
+ messageTemplate
+) {
+ const messageList = [];
+ const allOwnerAndDBAs = schema.roleMappings.where((roleMapping) => {
+ return (
+ roleMapping.workspaceId == WORKSPACE_ID &&
+ (roleMapping.role == "OWNER" || roleMapping.role == "DBA")
+ );
+ }).models;
+
+ allOwnerAndDBAs.forEach((roleMapping) => {
+ messageList.push({
+ ...messageTemplate,
+ receiverId: roleMapping.principalId,
+ });
+ });
+
+ for (const message of messageList) {
+ // We only send out message if it's NOT destined to self.
+ if (creatorId != message.receiverId) {
+ schema.messages.create(message);
+ }
+ }
+};
diff --git a/frontend/src/views/Inbox.vue b/frontend/src/views/Inbox.vue
index fb7a6052d8..d4c1007b89 100644
--- a/frontend/src/views/Inbox.vue
+++ b/frontend/src/views/Inbox.vue
@@ -133,6 +133,12 @@
{{ message.payload.instanceName }}
</router-link>
</template>
+ <template v-else-if="message.type == 'bb.msg.instance.delete'">
+ <span class="ml-1"> deleted instance</span>
+ <span class="font-medium text-main ml-1">
+ {{ message.payload.instanceName }}
+ </span>
+ </template>
<span
v-if="message.status == 'DELIVERED'"
class="ml-2 mt-1 h-3 w-3 rounded-full bg-accent"