Skip to content

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

Add createBackup to database backup component.

spinningbot24ea1fc1c32d
diff --git a/frontend/src/components/DatabaseBackupPanel.vue b/frontend/src/components/DatabaseBackupPanel.vue
index a11c5eb5df..cd8b352343 100644
--- a/frontend/src/components/DatabaseBackupPanel.vue
+++ b/frontend/src/components/DatabaseBackupPanel.vue
@@ -28,9 +28,9 @@
/>
</div>
<div class="sm:col-span-1">
- <label> Click </label>
+ <label> Backup </label>
<button
- @click.prevent="testConnection"
+ @click.prevent="createBackup"
type="button"
class="btn-normal whitespace-nowrap items-center"
>
@@ -52,7 +52,7 @@ import { computed, watchEffect, reactive, PropType, ComputedRef } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { v1 as uuidv1 } from "uuid";
-import { Backup, Database } from "../types";
+import { BackupCreate, Database } from "../types";
import BackupTable from "../components/BackupTable.vue";
interface LocalState {
@@ -94,10 +94,28 @@ export default {
(state as any)[field] = value;
};
+ const createBackup = () => {
+ // Create backup
+ const newBackup: BackupCreate = {
+ databaseId: props.database.id!,
+ name: state.backupName!,
+ status: "PENDING_CREATE",
+ type: "MANUAL",
+ storageBackend: "LOCAL",
+ path: state.backupPath!,
+ comment: "",
+ };
+ store.dispatch("backup/createBackup", {
+ databaseId: props.database.id,
+ newBackup: newBackup
+ });
+ };
+
return {
state,
backupList,
updateInstance,
+ createBackup,
};
},
}
diff --git a/frontend/src/store/modules/backup.ts b/frontend/src/store/modules/backup.ts
index f7e0db862b..ace63e46ed 100644
--- a/frontend/src/store/modules/backup.ts
+++ b/frontend/src/store/modules/backup.ts
@@ -1,5 +1,6 @@
import axios from "axios";
import {
+ BackupCreate,
Database,
DatabaseId,
ResourceIdentifier,
@@ -44,6 +45,33 @@ const getters = {
};
const actions = {
+ async createBackup(
+ { commit, rootGetters }: any,
+ { databaseId, newBackup }: { databaseId: DatabaseId; newBackup: BackupCreate }
+ ) {
+ const data = (
+ await axios.post(`/api/database/${newBackup.databaseId}/backup`, {
+ data: {
+ type: "BackupCreate",
+ attributes: newBackup,
+ },
+ })
+ ).data;
+ const createdBackup: Backup = convert(
+ data.data,
+ data.included,
+ rootGetters
+ );
+
+ commit("setBackupByDatabaseIdAndBackupName", {
+ databaseId: databaseId,
+ backupName: createdBackup.name,
+ backup: createdBackup
+ });
+
+ return createdBackup;
+ },
+
async fetchBackupListByDatabaseId(
{ commit, rootGetters }: any,
databaseId: DatabaseId
@@ -71,6 +99,31 @@ const mutations = {
) {
state.backupListByDatabaseId.set(databaseId, backupList);
},
+
+ setBackupByDatabaseIdAndBackupName(
+ state: BackupState,
+ {
+ databaseId,
+ backupName,
+ backup,
+ }: {
+ databaseId: DatabaseId;
+ backupName: string;
+ backup: Backup;
+ }
+ ) {
+ const list = state.backupListByDatabaseId.get(databaseId);
+ if (list) {
+ const i = list.findIndex((item: Backup) => item.name == backupName);
+ if (i != -1) {
+ list[i] = backup;
+ } else {
+ list.push(backup);
+ }
+ } else {
+ state.backupListByDatabaseId.set(databaseId, [backup]);
+ }
+ },
};
export default {
diff --git a/frontend/src/types/backup.ts b/frontend/src/types/backup.ts
index 005c710434..48385019ea 100644
--- a/frontend/src/types/backup.ts
+++ b/frontend/src/types/backup.ts
@@ -1,5 +1,5 @@
import { Database } from "./database";
-import { BackupId } from "./id";
+import { BackupId, DatabaseId } from "./id";
import { Principal } from "./principal";
// Backup
@@ -22,3 +22,16 @@ export type Backup = {
path: string;
comment: string;
};
+
+export type BackupCreate = {
+ // Related fields
+ databaseId: DatabaseId;
+
+ // Domain specific fields
+ name: string;
+ status: string;
+ type: string;
+ storageBackend: string;
+ path: string;
+ comment: string;
+};