Skip to content

Commit 31457ad

Browse files
authored
[db] Purge all Chargebee-related DB tables (#17286)
* [db] Drop all Chargebee-related tables * [db] Drop table d_b_pending_github_event
1 parent dea3556 commit 31457ad

File tree

3 files changed

+67
-38
lines changed

3 files changed

+67
-38
lines changed

components/gitpod-db/src/tables.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,6 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider
6363
primaryKeys: ["id"],
6464
timeColumn: "_lastModified",
6565
},
66-
{
67-
name: "d_b_pending_github_event",
68-
primaryKeys: ["id"],
69-
timeColumn: "creationDate",
70-
deletionColumn: "deleted",
71-
},
7266
{
7367
name: "d_b_volume_snapshot",
7468
primaryKeys: ["id"],
@@ -81,22 +75,6 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider
8175
timeColumn: "updatedAt",
8276
deletionColumn: "deleted",
8377
},
84-
{
85-
name: "d_b_account_entry",
86-
primaryKeys: ["uid"],
87-
timeColumn: "_lastModified",
88-
},
89-
{
90-
name: "d_b_subscription",
91-
primaryKeys: ["uid"],
92-
timeColumn: "_lastModified",
93-
dependencies: ["d_b_user"],
94-
},
95-
{
96-
name: "d_b_subscription_additional_data",
97-
primaryKeys: ["paymentReference"],
98-
timeColumn: "lastModified",
99-
},
10078
{
10179
name: "d_b_identity",
10280
primaryKeys: ["authProviderId", "authId"],
@@ -165,16 +143,6 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider
165143
deletionColumn: "deleted",
166144
timeColumn: "_lastModified",
167145
},
168-
{
169-
name: "d_b_team_subscription",
170-
primaryKeys: ["id"],
171-
timeColumn: "_lastModified",
172-
},
173-
{
174-
name: "d_b_team_subscription_slot",
175-
primaryKeys: ["id"],
176-
timeColumn: "_lastModified",
177-
},
178146
{
179147
name: "d_b_user_env_var",
180148
primaryKeys: ["id", "userId"],
@@ -260,12 +228,6 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider
260228
deletionColumn: "deleted",
261229
timeColumn: "_lastModified",
262230
},
263-
{
264-
name: "d_b_team_subscription2",
265-
primaryKeys: ["id"],
266-
deletionColumn: "deleted",
267-
timeColumn: "_lastModified",
268-
},
269231
{
270232
name: "d_b_user_ssh_public_key",
271233
primaryKeys: ["id"],
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License.AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { MigrationInterface, QueryRunner } from "typeorm";
8+
import { columnExists } from "./helper/helper";
9+
10+
export class DropChargebeeSubscriptionTables1681829114367 implements MigrationInterface {
11+
public async up(queryRunner: QueryRunner): Promise<void> {
12+
await queryRunner.query("DROP TABLE IF EXISTS `d_b_account_entry`");
13+
await queryRunner.query("DROP TABLE IF EXISTS `d_b_subscription`");
14+
await queryRunner.query("DROP TABLE IF EXISTS `d_b_team_subscription`");
15+
await queryRunner.query("DROP TABLE IF EXISTS `d_b_team_subscription_slot`");
16+
await queryRunner.query("DROP TABLE IF EXISTS `d_b_team_subscription2`");
17+
if (await columnExists(queryRunner, "d_b_team_membership", "subscriptionId")) {
18+
await queryRunner.query("ALTER TABLE `d_b_team_membership` DROP COLUMN `subscriptionId`");
19+
}
20+
await queryRunner.query("DROP TABLE IF EXISTS `d_b_subscription_additional_data`");
21+
}
22+
23+
public async down(queryRunner: QueryRunner): Promise<void> {
24+
await queryRunner.query(
25+
`CREATE TABLE IF NOT EXISTS d_b_account_entry ( id int(11) DEFAULT NULL, userId char(36) NOT NULL, amount double NOT NULL, date varchar(255) NOT NULL, expiryDate varchar(255) NOT NULL DEFAULT '', kind char(7) NOT NULL, description text, uid char(36) NOT NULL, creditId char(36) DEFAULT NULL, _lastModified timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (uid), KEY ind_dbsync (_lastModified), KEY ind_expiryDate (expiryDate)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`,
26+
);
27+
await queryRunner.query(
28+
`CREATE TABLE IF NOT EXISTS d_b_subscription ( id int(11) DEFAULT NULL, userId char(36) NOT NULL, startDate varchar(255) NOT NULL, endDate varchar(255) NOT NULL DEFAULT '', amount double NOT NULL, uid char(36) NOT NULL, _lastModified timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), planId varchar(255) NOT NULL DEFAULT 'free', paymentReference varchar(255) NOT NULL DEFAULT '', deleted tinyint(4) NOT NULL DEFAULT '0', cancellationDate varchar(255) NOT NULL DEFAULT '', paymentData text, teamSubscriptionSlotId char(255) NOT NULL DEFAULT '', firstMonthAmount double DEFAULT NULL, teamMembershipId char(36) NOT NULL DEFAULT '', PRIMARY KEY (uid), KEY ind_user_paymentReference (userId,paymentReference), KEY ind_dbsync (_lastModified), KEY ind_planId (planId)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`,
29+
);
30+
await queryRunner.query(
31+
`CREATE TABLE IF NOT EXISTS d_b_team_subscription ( id varchar(255) NOT NULL, userId char(36) NOT NULL, paymentReference varchar(255) NOT NULL, startDate varchar(255) NOT NULL, endDate varchar(255) NOT NULL DEFAULT '', planId varchar(255) NOT NULL, quantity int(11) NOT NULL, cancellationDate varchar(255) NOT NULL DEFAULT '', deleted tinyint(4) NOT NULL DEFAULT '0', _lastModified timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (id), KEY ind_user_paymentReference (userId,paymentReference), KEY ind_user_startDate (userId,startDate), KEY ind_dbsync (_lastModified)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`,
32+
);
33+
await queryRunner.query(
34+
`CREATE TABLE IF NOT EXISTS d_b_team_subscription_slot ( id char(36) NOT NULL, teamSubscriptionId char(36) NOT NULL, assigneeId char(36) NOT NULL DEFAULT '', assigneeIdentifier text, subscriptionId char(36) NOT NULL DEFAULT '', cancellationDate varchar(255) NOT NULL DEFAULT '', _lastModified timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (id), KEY ind_tsid (teamSubscriptionId), KEY ind_dbsync (_lastModified)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`,
35+
);
36+
await queryRunner.query(
37+
"CREATE TABLE IF NOT EXISTS `d_b_team_subscription2` (`id` char(36) NOT NULL, `teamId` char(36) NOT NULL, `paymentReference` varchar(255) NOT NULL, `startDate` varchar(255) NOT NULL, `endDate` varchar(255) NOT NULL DEFAULT '', `planId` varchar(255) NOT NULL, `quantity` int(11) NOT NULL, `cancellationDate` varchar(255) NOT NULL DEFAULT '', `deleted` tinyint(4) NOT NULL DEFAULT '0', `_lastModified` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`), KEY `ind_team_paymentReference` (`teamId`, `paymentReference`), KEY `ind_team_startDate` (`teamId`, `startDate`), KEY `ind_dbsync` (`_lastModified`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4",
38+
);
39+
if (!(await columnExists(queryRunner, "d_b_team_membership", "subscriptionId"))) {
40+
await queryRunner.query(
41+
"ALTER TABLE `d_b_team_membership` ADD COLUMN `subscriptionId` char(36) NOT NULL DEFAULT ''",
42+
);
43+
}
44+
await queryRunner.query(
45+
`CREATE TABLE IF NOT EXISTS d_b_subscription_additional_data ( paymentReference varchar(255) NOT NULL, mrr int(11) NOT NULL, coupons text, lastInvoiceAmount int(11) NOT NULL, nextBilling varchar(255) NOT NULL DEFAULT '', lastInvoice varchar(255) NOT NULL DEFAULT '', lastUpdated varchar(255) NOT NULL DEFAULT '', lastModified timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (paymentReference)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`,
46+
);
47+
}
48+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License.AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { MigrationInterface, QueryRunner } from "typeorm";
8+
9+
export class DropPendingGitHubEvents1681829127935 implements MigrationInterface {
10+
public async up(queryRunner: QueryRunner): Promise<void> {
11+
await queryRunner.query("DROP TABLE IF EXISTS `d_b_pending_github_event`");
12+
}
13+
14+
public async down(queryRunner: QueryRunner): Promise<void> {
15+
await queryRunner.query(
16+
`CREATE TABLE IF NOT EXISTS d_b_pending_github_event ( id char(36) NOT NULL, githubUserId varchar(36) NOT NULL, creationDate timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), type varchar(128) NOT NULL, event text, deleted tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`,
17+
);
18+
}
19+
}

0 commit comments

Comments
 (0)