-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(platform-server): usage packs and project usage limitation
- Loading branch information
liuyi.levi
committed
Nov 22, 2022
1 parent
cf05254
commit 2277911
Showing
53 changed files
with
1,429 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm' | ||
|
||
export class foreignKeys1668670838492 implements MigrationInterface { | ||
name = 'foreignKeys1668670838492' | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
ALTER TABLE \`job\` | ||
ADD CONSTRAINT \`FK_ca5fac3e39d6e93df14903d1072\` FOREIGN KEY (\`runner_id\`) REFERENCES \`runner\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION | ||
`) | ||
await queryRunner.query(` | ||
ALTER TABLE \`page_with_competitor\` | ||
ADD CONSTRAINT \`FK_b0f452aef10b0019e00eaa927e5\` FOREIGN KEY (\`competitor_id\`) REFERENCES \`page\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION | ||
`) | ||
await queryRunner.query(` | ||
ALTER TABLE \`source_issue\` | ||
ADD CONSTRAINT \`FK_4835a8bf4d0ae06e03541edfa89\` FOREIGN KEY (\`snapshot_report_id\`) REFERENCES \`snapshot_report\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION | ||
`) | ||
await queryRunner.query(` | ||
ALTER TABLE \`user_connected_account\` | ||
ADD CONSTRAINT \`FK_e956657dfdd875f5bc44c412c17\` FOREIGN KEY (\`user_id\`) REFERENCES \`user\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION | ||
`) | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
ALTER TABLE \`user_connected_account\` DROP FOREIGN KEY \`FK_e956657dfdd875f5bc44c412c17\` | ||
`) | ||
await queryRunner.query(` | ||
ALTER TABLE \`source_issue\` DROP FOREIGN KEY \`FK_4835a8bf4d0ae06e03541edfa89\` | ||
`) | ||
await queryRunner.query(` | ||
ALTER TABLE \`page_with_competitor\` DROP FOREIGN KEY \`FK_b0f452aef10b0019e00eaa927e5\` | ||
`) | ||
await queryRunner.query(` | ||
ALTER TABLE \`job\` DROP FOREIGN KEY \`FK_ca5fac3e39d6e93df14903d1072\` | ||
`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm' | ||
|
||
export class projectUsage1668670929409 implements MigrationInterface { | ||
name = 'projectUsage1668670929409' | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
CREATE TABLE \`usage_pack\` ( | ||
\`id\` int NOT NULL AUTO_INCREMENT, | ||
\`name\` varchar(255) NOT NULL, | ||
\`desc\` varchar(255) NOT NULL, | ||
\`is_public\` tinyint NOT NULL DEFAULT 0, | ||
\`is_default\` tinyint NOT NULL DEFAULT 0, | ||
\`job_count_monthly\` int NOT NULL, | ||
\`job_duration_monthly\` int NOT NULL, | ||
\`storage\` int NOT NULL, | ||
\`created_at\` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), | ||
\`updated_at\` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), | ||
PRIMARY KEY (\`id\`) | ||
) ENGINE = InnoDB | ||
`) | ||
await queryRunner.query(` | ||
CREATE TABLE \`project_job_usage\` ( | ||
\`id\` int NOT NULL AUTO_INCREMENT, | ||
\`project_id\` int NOT NULL, | ||
\`year\` int NOT NULL, | ||
\`month\` int NOT NULL, | ||
\`job_count\` int NOT NULL DEFAULT '0', | ||
\`job_duration\` decimal(10, 2) NOT NULL DEFAULT '0.00', | ||
\`updated_at\` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), | ||
INDEX \`idx_da16e6d19467189502a62a0d99\` (\`project_id\`), | ||
PRIMARY KEY (\`id\`) | ||
) ENGINE = InnoDB | ||
`) | ||
await queryRunner.query(` | ||
CREATE TABLE \`project_storage_usage\` ( | ||
\`id\` int NOT NULL AUTO_INCREMENT, | ||
\`project_id\` int NOT NULL, | ||
\`used\` decimal(10, 2) NOT NULL DEFAULT '0.00', | ||
\`updated_at\` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), | ||
INDEX \`idx_44711059df507f55fb11a5d68e\` (\`project_id\`), | ||
UNIQUE INDEX \`uniq_rel_44711059df507f55fb11a5d68e\` (\`project_id\`), | ||
PRIMARY KEY (\`id\`) | ||
) ENGINE = InnoDB | ||
`) | ||
await queryRunner.query(` | ||
ALTER TABLE \`artifact\` | ||
ADD \`upload_size\` int NOT NULL DEFAULT '0' | ||
`) | ||
await queryRunner.query(` | ||
ALTER TABLE \`project\` | ||
ADD \`usage_pack_id\` int NULL | ||
`) | ||
await queryRunner.query(` | ||
ALTER TABLE \`snapshot_report\` | ||
ADD \`upload_size\` int NOT NULL DEFAULT '0' | ||
`) | ||
await queryRunner.query(` | ||
ALTER TABLE \`project\` | ||
ADD CONSTRAINT \`FK_89f29f98d1c234d1db6f47b1bb2\` FOREIGN KEY (\`usage_pack_id\`) REFERENCES \`usage_pack\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION | ||
`) | ||
await queryRunner.query(` | ||
ALTER TABLE \`project_job_usage\` | ||
ADD CONSTRAINT \`FK_da16e6d19467189502a62a0d993\` FOREIGN KEY (\`project_id\`) REFERENCES \`project\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION | ||
`) | ||
await queryRunner.query(` | ||
ALTER TABLE \`project_storage_usage\` | ||
ADD CONSTRAINT \`FK_44711059df507f55fb11a5d68e3\` FOREIGN KEY (\`project_id\`) REFERENCES \`project\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION | ||
`) | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
ALTER TABLE \`project_storage_usage\` DROP FOREIGN KEY \`FK_44711059df507f55fb11a5d68e3\` | ||
`) | ||
await queryRunner.query(` | ||
ALTER TABLE \`project_job_usage\` DROP FOREIGN KEY \`FK_da16e6d19467189502a62a0d993\` | ||
`) | ||
await queryRunner.query(` | ||
ALTER TABLE \`project\` DROP FOREIGN KEY \`FK_89f29f98d1c234d1db6f47b1bb2\` | ||
`) | ||
await queryRunner.query(` | ||
ALTER TABLE \`snapshot_report\` DROP COLUMN \`upload_size\` | ||
`) | ||
await queryRunner.query(` | ||
ALTER TABLE \`project\` DROP COLUMN \`usage_pack_id\` | ||
`) | ||
await queryRunner.query(` | ||
ALTER TABLE \`artifact\` DROP COLUMN \`upload_size\` | ||
`) | ||
await queryRunner.query(` | ||
DROP INDEX \`uniq_rel_44711059df507f55fb11a5d68e\` ON \`project_storage_usage\` | ||
`) | ||
await queryRunner.query(` | ||
DROP INDEX \`idx_44711059df507f55fb11a5d68e\` ON \`project_storage_usage\` | ||
`) | ||
await queryRunner.query(` | ||
DROP TABLE \`project_storage_usage\` | ||
`) | ||
await queryRunner.query(` | ||
DROP INDEX \`idx_da16e6d19467189502a62a0d99\` ON \`project_job_usage\` | ||
`) | ||
await queryRunner.query(` | ||
DROP TABLE \`project_job_usage\` | ||
`) | ||
await queryRunner.query(` | ||
DROP TABLE \`usage_pack\` | ||
`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/platform-server/src/db/mysql/project-usage-job.entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
Copyright 2022 ByteDance and/or its affiliates. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { | ||
Entity, | ||
Column, | ||
PrimaryGeneratedColumn, | ||
BaseEntity, | ||
RelationId, | ||
Index, | ||
JoinColumn, | ||
UpdateDateColumn, | ||
ManyToOne, | ||
} from 'typeorm' | ||
|
||
import { Project } from './project.entity' | ||
|
||
@Entity() | ||
export class ProjectJobUsage extends BaseEntity { | ||
@PrimaryGeneratedColumn('increment') | ||
id!: number | ||
|
||
@Column() | ||
@Index() | ||
@RelationId('project') | ||
projectId!: number | ||
|
||
@ManyToOne(() => Project, { onDelete: 'CASCADE' }) | ||
@JoinColumn() | ||
project!: Project | ||
|
||
@Column() | ||
year!: number | ||
|
||
@Column() | ||
month!: number | ||
|
||
@Column({ default: 0 }) | ||
jobCount!: number | ||
|
||
@Column({ default: 0, type: 'decimal', precision: 10, scale: 2 }) | ||
jobDuration!: string | ||
|
||
@UpdateDateColumn({ type: 'timestamp' }) | ||
updatedAt!: Date | ||
} |
50 changes: 50 additions & 0 deletions
50
packages/platform-server/src/db/mysql/project-usage-storage.entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
Copyright 2022 ByteDance and/or its affiliates. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { | ||
Entity, | ||
Column, | ||
PrimaryGeneratedColumn, | ||
BaseEntity, | ||
RelationId, | ||
Index, | ||
OneToOne, | ||
JoinColumn, | ||
UpdateDateColumn, | ||
} from 'typeorm' | ||
|
||
import { Project } from './project.entity' | ||
|
||
@Entity() | ||
export class ProjectStorageUsage extends BaseEntity { | ||
@PrimaryGeneratedColumn('increment') | ||
id!: number | ||
|
||
@Column() | ||
@Index() | ||
@RelationId('project') | ||
projectId!: number | ||
|
||
@OneToOne(() => Project, { onDelete: 'CASCADE' }) | ||
@JoinColumn() | ||
project!: Project | ||
|
||
@Column({ default: 0, type: 'decimal', precision: 10, scale: 2 }) | ||
used!: string | ||
|
||
@UpdateDateColumn({ type: 'timestamp' }) | ||
updatedAt!: Date | ||
} |
Oops, something went wrong.