Skip to content

Commit

Permalink
refactor: id to uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
sshanzel committed Aug 13, 2024
1 parent f798e72 commit 2442ec7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/entity/Source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
14 changes: 10 additions & 4 deletions src/entity/sources/SourceCategory.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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<void> {
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;
`);
}

Expand Down
4 changes: 2 additions & 2 deletions src/schema/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -127,7 +127,7 @@ export const typeDefs = /* GraphQL */ `
type SourceCategory {
id: ID!
value: String!
title: String!
enabled: Boolean!
createdAt: DateTime!
updatedAt: DateTime
Expand Down

0 comments on commit 2442ec7

Please sign in to comment.