create post table and entity

This commit is contained in:
Hongbo Wu
2024-06-15 20:17:45 +08:00
parent ba28e54f7c
commit c02f2d5036
3 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,45 @@
import {
Column,
Entity,
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
} from 'typeorm'
import { User } from './user'
@Entity({ name: 'post' })
export class Post {
@PrimaryGeneratedColumn('uuid')
id!: string
@Column('uuid')
userId!: string
@ManyToOne(() => User)
@JoinColumn({ name: 'user_id' })
user!: User
@Column('uuid', { array: true })
libraryItemIds!: string[]
@Column('uuid', { array: true })
highlightIds!: string[]
@Column('text')
title!: string
@Column('text')
content!: string
@Column('text', { nullable: true })
thumbnail?: string
@Column('text', { nullable: true })
thought?: string
@Column('timestamptz')
createdAt!: Date
@Column('timestamptz')
updatedAt!: Date
}

View File

@ -0,0 +1,24 @@
-- Type: DO
-- Name: post
-- Description: Create a post table
BEGIN;
CREATE TABLE omnivore.post (
id UUID PRIMARY KEY DEFAULT uuid_generate_v1mc(),
user_id UUID NOT NULL REFERENCES omnivore.user(id) ON DELETE CASCADE,
library_item_ids UUID[],
highlight_ids UUID[],
title TEXT NOT NULL,
content TEXT NOT NULL, -- generated from template
thumbnail TEXT,
thought TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX post_user_id_idx ON omnivore.post(user_id);
ALTER TABLE omnivore.user_profile ALTER COLUMN private SET DEFAULT true;
COMMIT;

View File

@ -0,0 +1,11 @@
-- Type: UNDO
-- Name: post
-- Description: Create a post table
BEGIN;
ALTER TABLE omnivore.user_profile ALTER COLUMN private SET DEFAULT false;
DROP TABLE omnivore.post;
COMMIT;