diff --git a/src/entity/Source.ts b/src/entity/Source.ts index ac4da2b98..d6ca73099 100644 --- a/src/entity/Source.ts +++ b/src/entity/Source.ts @@ -111,7 +111,7 @@ export class Source { @Index('IDX_source_flags_featured', { synchronize: false }) flags: SourceFlagsPublic; - @Column({ type: 'text', nullable: true, default: null }) + @Column({ type: 'text', nullable: true }) categoryId?: string; @ManyToOne(() => SourceCategory, (category) => category.id, { lazy: true }) diff --git a/src/entity/sources/SourceCategory.ts b/src/entity/sources/SourceCategory.ts index 7d0fe19d8..bfd5a2693 100644 --- a/src/entity/sources/SourceCategory.ts +++ b/src/entity/sources/SourceCategory.ts @@ -1,17 +1,23 @@ -import { Column, Entity, PrimaryColumn, UpdateDateColumn } from 'typeorm'; +import { + Column, + CreateDateColumn, + Entity, + PrimaryGeneratedColumn, + UpdateDateColumn, +} from 'typeorm'; @Entity() export class SourceCategory { - @PrimaryColumn({ type: 'text' }) + @PrimaryGeneratedColumn('uuid') id: string; @Column({ type: 'text', unique: true }) - value: string; + title: string; @Column() enabled: boolean; - @Column({ default: () => 'now()' }) + @CreateDateColumn() createdAt: Date; @UpdateDateColumn() diff --git a/src/migration/1723118739478-SourceCategory.ts b/src/migration/1723579275223-SourceCategory.ts similarity index 53% rename from src/migration/1723118739478-SourceCategory.ts rename to src/migration/1723579275223-SourceCategory.ts index 9cfcf47ee..e8a6d1e2e 100644 --- a/src/migration/1723118739478-SourceCategory.ts +++ b/src/migration/1723579275223-SourceCategory.ts @@ -1,30 +1,31 @@ import { MigrationInterface, QueryRunner } from 'typeorm'; -export class SourceCategory1723118739478 implements MigrationInterface { - name = 'SourceCategory1723118739478'; +export class SourceCategory1723579275223 implements MigrationInterface { + name = 'SourceCategory1723579275223'; public async up(queryRunner: QueryRunner): Promise { await queryRunner.query( - `CREATE TABLE "source_category" ("id" text NOT NULL, "value" text NOT NULL, "enabled" boolean NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_f130e0bac7dea92c2a4084c2f89" UNIQUE ("value"), CONSTRAINT "PK_21e4d5359f2a23fd10053f516e9" PRIMARY KEY ("id"))`, + `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" text`); + 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 NO ACTION ON UPDATE NO ACTION`, ); await queryRunner.query(` INSERT INTO "source_category" - (id, value, enabled) + (title, enabled) VALUES - ('general', 'General', true), - ('web', 'Web', true), - ('mobile', 'Mobile', true), - ('games', 'Games', true), - ('devops', 'DevOps', true), - ('cloud', 'Cloud', true), - ('career', 'Career', true), - ('data', 'Data', true), - ('fun', 'Fun', true), - ('devtools', 'DevTools', true) + ('General', true), + ('Web', true), + ('Mobile', true), + ('Games', true), + ('DevOps', true), + ('Cloud', true), + ('Career', true), + ('Data', true), + ('Fun', true), + ('DevTools', true) + ON CONFLICT DO NOTHING; `); } diff --git a/src/schema/sources.ts b/src/schema/sources.ts index 90705c29d..0a27d009e 100644 --- a/src/schema/sources.ts +++ b/src/schema/sources.ts @@ -71,7 +71,7 @@ import { SourceCategory } from '../entity/sources/SourceCategory'; export interface GQLSourceCategory { id: string; - value: string; + title: string; enabled: boolean; createdAt: Date; updatedAt: Date; @@ -127,7 +127,7 @@ export const typeDefs = /* GraphQL */ ` type SourceCategory { id: ID! - value: String! + title: String! enabled: Boolean! createdAt: DateTime! updatedAt: DateTime