update entity

This commit is contained in:
Hongbo Wu
2022-02-21 16:20:48 +08:00
parent 966295385a
commit e74f334db9
3 changed files with 16 additions and 6 deletions

View File

@ -4,6 +4,8 @@ import {
CreateDateColumn,
Entity,
JoinColumn,
JoinTable,
ManyToMany,
ManyToOne,
PrimaryGeneratedColumn,
} from 'typeorm'
@ -22,9 +24,15 @@ export class Label extends BaseEntity {
@JoinColumn({ name: 'user_id' })
user!: User
@ManyToOne(() => Link)
@JoinColumn({ name: 'link_id' })
link!: Link
@ManyToMany(() => Link, (link) => link.labels)
@JoinTable({ name: 'link_labels' })
link?: Link
@Column('text')
color!: string
@Column('text')
description?: string
@CreateDateColumn()
createdAt!: Date

View File

@ -15,7 +15,8 @@ import {
CreateDateColumn,
Entity,
JoinColumn,
OneToMany,
JoinTable,
ManyToMany,
OneToOne,
PrimaryGeneratedColumn,
UpdateDateColumn,
@ -62,6 +63,7 @@ export class Link extends BaseEntity {
@UpdateDateColumn()
updatedAt?: Date
@OneToMany(() => Label, (label) => label.link)
@ManyToMany(() => Label, (label) => label.link)
@JoinTable({ name: 'link_labels' })
labels?: Label[]
}

View File

@ -6,7 +6,7 @@ BEGIN;
ALTER TABLE omnivore.labels
DROP COLUMN link_id,
ADD COLUMN color text,
ADD COLUMN color text NOT NULL,
ADD COLUMN description text,
ADD CONSTRAINT label_name_unique UNIQUE (user_id, name);