Skip to content

[db] Soft delete records in the d_b_workspace_cluster table #14351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 2, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ export class WorkspaceClusterDBImpl implements WorkspaceClusterDB {

async deleteByName(name: string, applicationCluster: string): Promise<void> {
const repo = await this.getRepo();
await repo.delete({ name, applicationCluster });
await repo.update({ name, applicationCluster }, { deleted: true });
}

async findByName(name: string, applicationCluster: string): Promise<WorkspaceCluster | undefined> {
const repo = await this.getRepo();
return repo.findOne({ name, applicationCluster });
return repo.findOne({ name, applicationCluster, deleted: false });
}

async findFiltered(predicate: WorkspaceClusterFilter): Promise<WorkspaceClusterWoTLS[]> {
Expand All @@ -58,7 +58,7 @@ export class WorkspaceClusterDBImpl implements WorkspaceClusterDB {
let qb = repo
.createQueryBuilder("wsc")
.select(Object.keys(prototype).map((k) => `wsc.${k}`))
.where("TRUE = TRUE"); // make sure andWhere works
.where("wsc.deleted = 0");
if (predicate.name !== undefined) {
qb = qb.andWhere("wsc.name = :name", predicate);
}
Expand Down
41 changes: 41 additions & 0 deletions components/gitpod-db/src/workspace-cluster-db.spec.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,47 @@ export class WorkspaceClusterDBSpec {
expect(wscs2.length).to.equal(2);
expect(wscs2).to.deep.include.members(expectedClusters2);
}

@test public async testFindFilteredExcludesDeletedClusters() {
const wsc1: DBWorkspaceCluster = dbWorkspaceCluster({
name: "eu71",
applicationCluster: "eu02",
url: "some-url",
state: "available",
score: 100,
maxScore: 100,
govern: true,
});
const wsc1a: DBWorkspaceCluster = dbWorkspaceCluster({
name: "eu71",
applicationCluster: "us02",
url: "some-url",
state: "cordoned",
score: 0,
maxScore: 0,
govern: false,
});
const wsc2: DBWorkspaceCluster = dbWorkspaceCluster({
name: "us71",
applicationCluster: "us02",
url: "some-url",
state: "available",
score: 100,
maxScore: 100,
govern: true,
});

await this.db.save(wsc1);
await this.db.save(wsc1a);
await this.db.save(wsc2);

await this.db.deleteByName("eu71", "us02");

let wscs = await this.db.findFiltered({ applicationCluster: "us02" });
expect(wscs.length).to.equal(1);
wscs = await this.db.findFiltered({ applicationCluster: "eu02" });
expect(wscs.length).to.equal(1);
}
}

function dbWorkspaceCluster(cluster: Omit<DBWorkspaceCluster, "deleted">): DBWorkspaceCluster {
Expand Down