Skip to content

Commit

Permalink
[db] DBProjectUsage: drop deleted column (unused)
Browse files Browse the repository at this point in the history
  • Loading branch information
geropl committed Oct 4, 2023
1 parent 93ad9cf commit 0547c25
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
3 changes: 0 additions & 3 deletions components/gitpod-db/go/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ type Project struct {
UserID sql.NullString `gorm:"column:userId;type:char;size:36;" json:"userId"`

MarkedDeleted bool `gorm:"column:markedDeleted;type:tinyint;default:0;" json:"markedDeleted"`

// deleted is reserved for use by periodic deleter
_ bool `gorm:"column:deleted;type:tinyint;default:0;" json:"deleted"`
}

// TableName sets the insert table name for this struct type
Expand Down
3 changes: 1 addition & 2 deletions components/gitpod-db/go/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ var projectJSON = map[string]interface{}{
"teamId": "0e433063-1358-4892-9ed2-68e273d17d07",
"appInstallationId": "20446411",
"creationTime": "2021-11-01T19:36:07.532Z",
"deleted": 0,
"_lastModified": "2021-11-02 10:49:12.473658",
"name": "gptest1-repo1-private",
"markedDeleted": 1,
Expand All @@ -49,7 +48,7 @@ func TestProject_ReadExistingRecords(t *testing.T) {

func insertRawProject(t *testing.T, conn *gorm.DB, obj map[string]interface{}) uuid.UUID {
columns := []string{
"id", "cloneUrl", "teamId", "appInstallationId", "creationTime", "deleted", "_lastModified", "name", "markedDeleted", "userId", "slug", "settings",
"id", "cloneUrl", "teamId", "appInstallationId", "creationTime", "_lastModified", "name", "markedDeleted", "userId", "slug", "settings",
}
statement := fmt.Sprintf(`INSERT INTO d_b_project (%s) VALUES ?;`, strings.Join(columns, ", "))
id := uuid.MustParse(obj["id"].(string))
Expand Down
6 changes: 0 additions & 6 deletions components/gitpod-db/src/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider
deletionColumn: "deleted",
timeColumn: "_lastModified",
},
{
name: "d_b_project_usage",
primaryKeys: ["projectId"],
deletionColumn: "deleted",
timeColumn: "_lastModified",
},
{
name: "d_b_user_ssh_public_key",
primaryKeys: ["id"],
Expand Down
4 changes: 0 additions & 4 deletions components/gitpod-db/src/typeorm/entity/db-project-usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,4 @@ export class DBProjectUsage {

@Column("varchar")
lastWorkspaceStart: string;

// This column triggers the periodic deleter deletion mechanism. It's not intended for public consumption.
@Column()
deleted: boolean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* 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";

const TABLE_NAME = "d_b_project_usage";
const COLUMN_NAME = "deleted";

export class ProjectUsageDropDeleted1695821957148 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
if (await columnExists(queryRunner, TABLE_NAME, COLUMN_NAME)) {
await queryRunner.query(`ALTER TABLE \`${TABLE_NAME}\` DROP COLUMN \`${COLUMN_NAME}\`, ALGORITHM=INSTANT`);
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
if (!(await columnExists(queryRunner, TABLE_NAME, COLUMN_NAME))) {
await queryRunner.query(
`ALTER TABLE \`${TABLE_NAME}\` ADD COLUMN \`${COLUMN_NAME}\` tinyint(4) NOT NULL DEFAULT '0', ALGORITHM=INSTANT`,
);
}
}
}

0 comments on commit 0547c25

Please sign in to comment.