From 8ab1d62444ece59d36fb83a7632b04f32806d3be Mon Sep 17 00:00:00 2001 From: ssmucny Date: Sun, 16 Apr 2023 15:25:54 -0400 Subject: [PATCH] Changed DB to have events behave like polls --- packages/backend/src/models/entities/Event.ts | 11 +++++++++-- packages/backend/src/models/entities/Note.ts | 18 ++++-------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/packages/backend/src/models/entities/Event.ts b/packages/backend/src/models/entities/Event.ts index bf15838651..779c491cca 100644 --- a/packages/backend/src/models/entities/Event.ts +++ b/packages/backend/src/models/entities/Event.ts @@ -1,10 +1,17 @@ -import { Entity, Index, Column, PrimaryColumn } from 'typeorm'; +import { Entity, Index, Column, PrimaryColumn, OneToOne, JoinColumn } from 'typeorm'; import { id } from '../id.js'; +import { Note } from './Note.js'; @Entity() export class Event { @PrimaryColumn(id()) - public id: string; + public noteId: Note['id']; + + @OneToOne(type => Note, { + onDelete: 'CASCADE', + }) + @JoinColumn() + public note: Note | null; @Index() @Column('timestamp with time zone', { diff --git a/packages/backend/src/models/entities/Note.ts b/packages/backend/src/models/entities/Note.ts index ad776b73b0..4af007abc3 100644 --- a/packages/backend/src/models/entities/Note.ts +++ b/packages/backend/src/models/entities/Note.ts @@ -1,9 +1,8 @@ -import { Entity, Index, JoinColumn, Column, PrimaryColumn, ManyToOne, OneToOne } from 'typeorm'; +import { Entity, Index, JoinColumn, Column, PrimaryColumn, ManyToOne } from 'typeorm'; import { id } from '../id.js'; import { noteVisibilities } from '../../types.js'; import { User } from './User.js'; import { Channel } from './Channel.js'; -import { Event } from './Event.js'; import type { DriveFile } from './DriveFile.js'; @Entity() @@ -54,19 +53,10 @@ export class Note { }) public threadId: string | null; - @Index() - @Column({ - ...id(), - nullable: true, - comment: 'The ID of child event', + @Column('boolean', { + default: false, }) - public eventId: Event['id'] | null; - - @OneToOne(type => Event, { - onDelete: 'CASCADE', - }) - @JoinColumn() - public event: Event | null; + public isEvent: boolean; // TODO: varcharにしたい @Column('text', {