[db] DBCodeSyncResource/-Collection: Drop deleted column (#18808)

This commit is contained in:
Gero Posmyk-Leinemann 2023-09-27 09:06:05 +02:00 committed by GitHub
parent 2c7c770061
commit 3e552a3752
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 27 deletions

View File

@ -140,13 +140,11 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider
{ {
name: "d_b_code_sync_collection", name: "d_b_code_sync_collection",
primaryKeys: ["userId", "collection"], primaryKeys: ["userId", "collection"],
deletionColumn: "deleted",
timeColumn: "_lastModified", timeColumn: "_lastModified",
}, },
{ {
name: "d_b_code_sync_resource", name: "d_b_code_sync_resource",
primaryKeys: ["userId", "kind", "rev", "collection"], primaryKeys: ["userId", "kind", "rev", "collection"],
deletionColumn: "deleted",
timeColumn: "created", timeColumn: "created",
dependencies: ["d_b_code_sync_collection"], dependencies: ["d_b_code_sync_collection"],
}, },

View File

@ -32,7 +32,7 @@ export class CodeSyncResourceDB {
const resourcesResult = await connection.manager const resourcesResult = await connection.manager
.createQueryBuilder(DBCodeSyncResource, "resource") .createQueryBuilder(DBCodeSyncResource, "resource")
.where( .where(
"resource.userId = :userId AND resource.kind != 'editSessions' AND resource.collection = :collection AND resource.deleted = 0", "resource.userId = :userId AND resource.kind != 'editSessions' AND resource.collection = :collection",
{ {
userId, userId,
collection: uuid.NIL, collection: uuid.NIL,
@ -46,7 +46,7 @@ export class CodeSyncResourceDB {
.addSelect("max(resource2.created)") .addSelect("max(resource2.created)")
.from(DBCodeSyncResource, "resource2") .from(DBCodeSyncResource, "resource2")
.where( .where(
"resource2.userId = :userId AND resource2.kind != 'editSessions' AND resource2.collection = :collection AND resource2.deleted = 0", "resource2.userId = :userId AND resource2.kind != 'editSessions' AND resource2.collection = :collection",
{ userId, collection: uuid.NIL }, { userId, collection: uuid.NIL },
) )
.groupBy("resource2.kind") .groupBy("resource2.kind")
@ -63,7 +63,7 @@ export class CodeSyncResourceDB {
const collectionsResult = await connection.manager const collectionsResult = await connection.manager
.createQueryBuilder(DBCodeSyncResource, "resource") .createQueryBuilder(DBCodeSyncResource, "resource")
.where( .where(
"resource.userId = :userId AND resource.kind != 'editSessions' AND resource.collection != :collection AND resource.deleted = 0", "resource.userId = :userId AND resource.kind != 'editSessions' AND resource.collection != :collection",
{ {
userId, userId,
collection: uuid.NIL, collection: uuid.NIL,
@ -78,7 +78,7 @@ export class CodeSyncResourceDB {
.addSelect("max(resource2.created)") .addSelect("max(resource2.created)")
.from(DBCodeSyncResource, "resource2") .from(DBCodeSyncResource, "resource2")
.where( .where(
"resource2.userId = :userId AND resource2.kind != 'editSessions' AND resource2.collection != :collection AND resource2.deleted = 0", "resource2.userId = :userId AND resource2.kind != 'editSessions' AND resource2.collection != :collection",
{ userId, collection: uuid.NIL }, { userId, collection: uuid.NIL },
) )
.groupBy("resource2.kind") .groupBy("resource2.kind")
@ -236,19 +236,21 @@ export class CodeSyncResourceDB {
if (rev === "latest") { if (rev === "latest") {
return manager return manager
.createQueryBuilder(DBCodeSyncResource, "resource") .createQueryBuilder(DBCodeSyncResource, "resource")
.where( .where("resource.userId = :userId AND resource.kind = :kind AND resource.collection = :collection", {
"resource.userId = :userId AND resource.kind = :kind AND resource.collection = :collection AND resource.deleted = 0", userId,
{ userId, kind, collection: collection || uuid.NIL }, kind,
) collection: collection || uuid.NIL,
})
.orderBy("resource.created", "DESC") .orderBy("resource.created", "DESC")
.getOne(); .getOne();
} else { } else {
return manager return manager
.createQueryBuilder(DBCodeSyncResource, "resource") .createQueryBuilder(DBCodeSyncResource, "resource")
.where( .where("resource.userId = :userId AND resource.kind = :kind AND resource.collection = :collection", {
"resource.userId = :userId AND resource.kind = :kind AND resource.collection = :collection AND resource.deleted = 0", userId,
{ userId, kind, collection: collection || uuid.NIL }, kind,
) collection: collection || uuid.NIL,
})
.andWhere("resource.rev = :rev", { rev }) .andWhere("resource.rev = :rev", { rev })
.getOne(); .getOne();
} }
@ -263,10 +265,11 @@ export class CodeSyncResourceDB {
return manager return manager
.getRepository(DBCodeSyncResource) .getRepository(DBCodeSyncResource)
.createQueryBuilder("resource") .createQueryBuilder("resource")
.where( .where("resource.userId = :userId AND resource.kind = :kind AND resource.collection = :collection", {
"resource.userId = :userId AND resource.kind = :kind AND resource.collection = :collection AND resource.deleted = 0", userId,
{ userId, kind, collection: collection || uuid.NIL }, kind,
) collection: collection || uuid.NIL,
})
.orderBy("resource.created", "DESC") .orderBy("resource.created", "DESC")
.getMany(); .getMany();
} }
@ -275,7 +278,7 @@ export class CodeSyncResourceDB {
const connection = await this.typeORM.getConnection(); const connection = await this.typeORM.getConnection();
const result = await connection.manager const result = await connection.manager
.createQueryBuilder(DBCodeSyncCollection, "collection") .createQueryBuilder(DBCodeSyncCollection, "collection")
.where("collection.userId = :userId AND collection.deleted = 0", { userId }) .where("collection.userId = :userId", { userId })
.getMany(); .getMany();
return result.map((r) => ({ id: r.collection })); return result.map((r) => ({ id: r.collection }));
} }
@ -284,7 +287,7 @@ export class CodeSyncResourceDB {
const connection = await this.typeORM.getConnection(); const connection = await this.typeORM.getConnection();
const result = await connection.manager const result = await connection.manager
.createQueryBuilder(DBCodeSyncCollection, "collection") .createQueryBuilder(DBCodeSyncCollection, "collection")
.where("collection.userId = :userId AND collection.collection = :collection AND collection.deleted = 0", { .where("collection.userId = :userId AND collection.collection = :collection", {
userId, userId,
collection, collection,
}) })

View File

@ -4,7 +4,7 @@
* See License.AGPL.txt in the project root for license information. * See License.AGPL.txt in the project root for license information.
*/ */
import { Column, Entity, PrimaryColumn } from "typeorm"; import { Entity, PrimaryColumn } from "typeorm";
import { TypeORM } from "../typeorm"; import { TypeORM } from "../typeorm";
@Entity() @Entity()
@ -15,7 +15,4 @@ export class DBCodeSyncCollection {
@PrimaryColumn(TypeORM.UUID_COLUMN_TYPE) @PrimaryColumn(TypeORM.UUID_COLUMN_TYPE)
collection: string; collection: string;
@Column()
deleted: boolean;
} }

View File

@ -86,7 +86,4 @@ export class DBCodeSyncResource {
}, },
}) })
created: string; created: string;
@Column()
deleted: boolean;
} }

View File

@ -0,0 +1,32 @@
/**
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License.AGPL.txt in the project root for license information.
*/
import { MigrationInterface, QueryRunner } from "typeorm";
import { columnExists } from "./helper/helper";
export class CodeSyncDropDeleted1695733993909 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
if (await columnExists(queryRunner, "d_b_code_sync_resource", "deleted")) {
await queryRunner.query("ALTER TABLE `d_b_code_sync_resource` DROP COLUMN `deleted`, ALGORITHM=INSTANT");
}
if (await columnExists(queryRunner, "d_b_code_sync_collection", "deleted")) {
await queryRunner.query("ALTER TABLE `d_b_code_sync_collection` DROP COLUMN `deleted`, ALGORITHM=INSTANT");
}
}
public async down(queryRunner: QueryRunner): Promise<void> {
if (!(await columnExists(queryRunner, "d_b_code_sync_collection", "deleted"))) {
await queryRunner.query(
"ALTER TABLE `d_b_code_sync_collection` ADD COLUMN `deleted` tinyint(4) NOT NULL DEFAULT '0', ALGORITHM=INSTANT",
);
}
if (!(await columnExists(queryRunner, "d_b_code_sync_resource", "deleted"))) {
await queryRunner.query(
"ALTER TABLE `d_b_code_sync_resource` ADD COLUMN `deleted` tinyint(4) NOT NULL DEFAULT '0', ALGORITHM=INSTANT",
);
}
}
}