Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/collections/backup/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import {
BackupCreateResponse,
BackupCreateStatusResponse,
BackupListResponse,
BackupRestoreResponse,
} from '../../openapi/types.js';
import {
Expand Down Expand Up @@ -47,6 +48,8 @@ export const backup = (connection: Connection): Backup => {
error: res.error,
path: res.path,
status: res.status,
incrementalBaseBackupId:
'incremental_base_backup_id' in res ? res.incremental_base_backup_id : undefined,
};
};
const parseResponse = (res: BackupCreateResponse | BackupRestoreResponse): BackupReturn => {
Expand Down Expand Up @@ -213,7 +216,12 @@ export const backup = (connection: Connection): Backup => {
if (opts?.startedAtAsc) {
url += '?order=asc';
}
return connection.get<BackupReturn[]>(url);
return connection.get<BackupListResponse>(url).then((backups) =>
(backups ?? []).map((backup) => ({
...(backup as unknown as BackupReturn),
incrementalBaseBackupId: backup.incremental_base_backup_id,
}))
);
},
};
};
Expand Down
2 changes: 2 additions & 0 deletions src/collections/backup/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export type BackupStatusReturn = {
status: BackupStatus;
/** Size of the backup in Gibs */
size?: number;
/** The ID of the base backup this incremental backup was built on; absent when the backup is not incremental. */
incrementalBaseBackupId?: string;
};

/** The return type of a backup creation or restoration operation */
Expand Down
1 change: 1 addition & 0 deletions src/openapi/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type BackupCreateStatusResponse = definitions['BackupCreateStatusResponse
export type BackupRestoreRequest = definitions['BackupRestoreRequest'];
export type BackupRestoreResponse = definitions['BackupRestoreResponse'];
export type BackupRestoreStatusResponse = definitions['BackupRestoreStatusResponse'];
export type BackupListResponse = definitions['BackupListResponse'];
export type BackupConfig = definitions['BackupConfig'];
export type RestoreConfig = definitions['RestoreConfig'];
export type WeaviateBackupStatus =
Expand Down
25 changes: 25 additions & 0 deletions test/collections/backup/mock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,23 @@ class CancelMock {
backend: BACKEND,
path: 'path/to/backup',
status: CancelMock.status,
incremental_base_backup_id: 'base-backup-001',
})
);

// Backup list endpoint
httpApp.get(`/v1/backups/${BACKEND}`, (req, res) =>
res.send([
{ id: 'full-backup', classes: ['A'], status: 'SUCCESS' },
{
id: 'incremental-backup',
classes: ['A'],
status: 'SUCCESS',
incremental_base_backup_id: 'full-backup',
},
])
);

// Backup restoration endpoint
httpApp.post(
`/v1/backups/${BACKEND}/${BACKUP_ID}/restore`,
Expand Down Expand Up @@ -184,5 +198,16 @@ describe('Mock testing of backup cancellation', () => {
expect(success).toBe(false);
});

it('should surface incrementalBaseBackupId from the creation status', async () => {
const status = await client.backup.getCreateStatus({ backupId: BACKUP_ID, backend: BACKEND });
expect(status.incrementalBaseBackupId).toBe('base-backup-001');
});

it('should surface incrementalBaseBackupId when listing backups', async () => {
const backups = await client.backup.list(BACKEND);
expect(backups.find((b) => b.id === 'full-backup')?.incrementalBaseBackupId).toBeUndefined();
expect(backups.find((b) => b.id === 'incremental-backup')?.incrementalBaseBackupId).toBe('full-backup');
});

afterAll(() => mock.close());
});