-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: source category entity (#2119)
- Introduce source category entity. - Add `categoryId` column on the source entity. - update sources query to filter by category MI-483
- Loading branch information
Showing
7 changed files
with
281 additions
and
10 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
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,25 @@ | ||
import { | ||
Column, | ||
CreateDateColumn, | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
UpdateDateColumn, | ||
} from 'typeorm'; | ||
|
||
@Entity() | ||
export class SourceCategory { | ||
@PrimaryGeneratedColumn('uuid') | ||
id: string; | ||
|
||
@Column({ type: 'text', unique: true }) | ||
title: string; | ||
|
||
@Column() | ||
enabled: boolean; | ||
|
||
@CreateDateColumn() | ||
createdAt: Date; | ||
|
||
@UpdateDateColumn() | ||
updatedAt: Date; | ||
} |
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,40 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class SourceCategory1723579275223 implements MigrationInterface { | ||
name = 'SourceCategory1723579275223'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`CREATE TABLE "source_category" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "title" text NOT NULL, "enabled" boolean NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_66d6dccf282b8104ef9c44c0fb5" UNIQUE ("title"), CONSTRAINT "PK_21e4d5359f2a23fd10053f516e9" PRIMARY KEY ("id"))`, | ||
); | ||
await queryRunner.query(`ALTER TABLE "source" ADD "categoryId" uuid`); | ||
await queryRunner.query( | ||
`ALTER TABLE "source" ADD CONSTRAINT "FK_02e1cbb6e33fa90e68dd56de2a9" FOREIGN KEY ("categoryId") REFERENCES "source_category"("id") ON DELETE SET NULL ON UPDATE NO ACTION`, | ||
); | ||
await queryRunner.query(` | ||
INSERT INTO "source_category" | ||
(title, enabled) | ||
VALUES | ||
('General', true), | ||
('Web', true), | ||
('Mobile', true), | ||
('Games', true), | ||
('DevOps', true), | ||
('Cloud', true), | ||
('Career', true), | ||
('Data', true), | ||
('Fun', true), | ||
('DevTools', true) | ||
ON CONFLICT DO NOTHING; | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`TRUNCATE "source_category"`); | ||
await queryRunner.query( | ||
`ALTER TABLE "source" DROP CONSTRAINT "FK_02e1cbb6e33fa90e68dd56de2a9"`, | ||
); | ||
await queryRunner.query(`ALTER TABLE "source" DROP COLUMN "categoryId"`); | ||
await queryRunner.query(`DROP TABLE "source_category"`); | ||
} | ||
} |
Oops, something went wrong.