mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
[db] DBCodeSyncResource/-Collection: Drop deleted column (#18808)
This commit is contained in:
parent
2c7c770061
commit
3e552a3752
@ -140,13 +140,11 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider
|
||||
{
|
||||
name: "d_b_code_sync_collection",
|
||||
primaryKeys: ["userId", "collection"],
|
||||
deletionColumn: "deleted",
|
||||
timeColumn: "_lastModified",
|
||||
},
|
||||
{
|
||||
name: "d_b_code_sync_resource",
|
||||
primaryKeys: ["userId", "kind", "rev", "collection"],
|
||||
deletionColumn: "deleted",
|
||||
timeColumn: "created",
|
||||
dependencies: ["d_b_code_sync_collection"],
|
||||
},
|
||||
|
||||
@ -32,7 +32,7 @@ export class CodeSyncResourceDB {
|
||||
const resourcesResult = await connection.manager
|
||||
.createQueryBuilder(DBCodeSyncResource, "resource")
|
||||
.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,
|
||||
collection: uuid.NIL,
|
||||
@ -46,7 +46,7 @@ export class CodeSyncResourceDB {
|
||||
.addSelect("max(resource2.created)")
|
||||
.from(DBCodeSyncResource, "resource2")
|
||||
.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 },
|
||||
)
|
||||
.groupBy("resource2.kind")
|
||||
@ -63,7 +63,7 @@ export class CodeSyncResourceDB {
|
||||
const collectionsResult = await connection.manager
|
||||
.createQueryBuilder(DBCodeSyncResource, "resource")
|
||||
.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,
|
||||
collection: uuid.NIL,
|
||||
@ -78,7 +78,7 @@ export class CodeSyncResourceDB {
|
||||
.addSelect("max(resource2.created)")
|
||||
.from(DBCodeSyncResource, "resource2")
|
||||
.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 },
|
||||
)
|
||||
.groupBy("resource2.kind")
|
||||
@ -236,19 +236,21 @@ export class CodeSyncResourceDB {
|
||||
if (rev === "latest") {
|
||||
return manager
|
||||
.createQueryBuilder(DBCodeSyncResource, "resource")
|
||||
.where(
|
||||
"resource.userId = :userId AND resource.kind = :kind AND resource.collection = :collection AND resource.deleted = 0",
|
||||
{ userId, kind, collection: collection || uuid.NIL },
|
||||
)
|
||||
.where("resource.userId = :userId AND resource.kind = :kind AND resource.collection = :collection", {
|
||||
userId,
|
||||
kind,
|
||||
collection: collection || uuid.NIL,
|
||||
})
|
||||
.orderBy("resource.created", "DESC")
|
||||
.getOne();
|
||||
} else {
|
||||
return manager
|
||||
.createQueryBuilder(DBCodeSyncResource, "resource")
|
||||
.where(
|
||||
"resource.userId = :userId AND resource.kind = :kind AND resource.collection = :collection AND resource.deleted = 0",
|
||||
{ userId, kind, collection: collection || uuid.NIL },
|
||||
)
|
||||
.where("resource.userId = :userId AND resource.kind = :kind AND resource.collection = :collection", {
|
||||
userId,
|
||||
kind,
|
||||
collection: collection || uuid.NIL,
|
||||
})
|
||||
.andWhere("resource.rev = :rev", { rev })
|
||||
.getOne();
|
||||
}
|
||||
@ -263,10 +265,11 @@ export class CodeSyncResourceDB {
|
||||
return manager
|
||||
.getRepository(DBCodeSyncResource)
|
||||
.createQueryBuilder("resource")
|
||||
.where(
|
||||
"resource.userId = :userId AND resource.kind = :kind AND resource.collection = :collection AND resource.deleted = 0",
|
||||
{ userId, kind, collection: collection || uuid.NIL },
|
||||
)
|
||||
.where("resource.userId = :userId AND resource.kind = :kind AND resource.collection = :collection", {
|
||||
userId,
|
||||
kind,
|
||||
collection: collection || uuid.NIL,
|
||||
})
|
||||
.orderBy("resource.created", "DESC")
|
||||
.getMany();
|
||||
}
|
||||
@ -275,7 +278,7 @@ export class CodeSyncResourceDB {
|
||||
const connection = await this.typeORM.getConnection();
|
||||
const result = await connection.manager
|
||||
.createQueryBuilder(DBCodeSyncCollection, "collection")
|
||||
.where("collection.userId = :userId AND collection.deleted = 0", { userId })
|
||||
.where("collection.userId = :userId", { userId })
|
||||
.getMany();
|
||||
return result.map((r) => ({ id: r.collection }));
|
||||
}
|
||||
@ -284,7 +287,7 @@ export class CodeSyncResourceDB {
|
||||
const connection = await this.typeORM.getConnection();
|
||||
const result = await connection.manager
|
||||
.createQueryBuilder(DBCodeSyncCollection, "collection")
|
||||
.where("collection.userId = :userId AND collection.collection = :collection AND collection.deleted = 0", {
|
||||
.where("collection.userId = :userId AND collection.collection = :collection", {
|
||||
userId,
|
||||
collection,
|
||||
})
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
* 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";
|
||||
|
||||
@Entity()
|
||||
@ -15,7 +15,4 @@ export class DBCodeSyncCollection {
|
||||
|
||||
@PrimaryColumn(TypeORM.UUID_COLUMN_TYPE)
|
||||
collection: string;
|
||||
|
||||
@Column()
|
||||
deleted: boolean;
|
||||
}
|
||||
|
||||
@ -86,7 +86,4 @@ export class DBCodeSyncResource {
|
||||
},
|
||||
})
|
||||
created: string;
|
||||
|
||||
@Column()
|
||||
deleted: boolean;
|
||||
}
|
||||
|
||||
@ -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",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user