create post table and entity
This commit is contained in:
45
packages/api/src/entity/post.ts
Normal file
45
packages/api/src/entity/post.ts
Normal 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
|
||||
}
|
||||
24
packages/db/migrations/0183.do.post.sql
Executable file
24
packages/db/migrations/0183.do.post.sql
Executable 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;
|
||||
11
packages/db/migrations/0183.undo.post.sql
Executable file
11
packages/db/migrations/0183.undo.post.sql
Executable 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;
|
||||
Reference in New Issue
Block a user