Create search_history table and entity class

This commit is contained in:
Hongbo Wu 2022-10-10 17:44:55 +08:00
parent 9b64299c6b
commit cd13e5874a
3 changed files with 55 additions and 0 deletions

View file

@ -0,0 +1,29 @@
import {
Column,
CreateDateColumn,
Entity,
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm'
import { User } from './user'
@Entity({ name: 'search_history' })
export class SearchHistory {
@PrimaryGeneratedColumn('uuid')
id!: string
@ManyToOne(() => User, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'user_id' })
user!: User
@Column('varchar', { length: 255 })
keyword!: string
@CreateDateColumn({ default: () => 'CURRENT_TIMESTAMP' })
createdAt!: Date
@UpdateDateColumn({ default: () => 'CURRENT_TIMESTAMP' })
updatedAt!: Date
}

View file

@ -0,0 +1,17 @@
-- Type: DO
-- Name: search_history
-- Description: Create search_history table which contains searched keyword and timestamp
BEGIN;
CREATE TABLE omnivore.search_history (
id uuid PRIMARY KEY DEFAULT uuid_generate_v1mc(),
user_id uuid NOT NULL REFERENCES omnivore.user ON DELETE CASCADE,
keyword VARCHAR(255) NOT NULL,
created_at timestamptz NOT NULL DEFAULT current_timestamp,
updated_at timestamptz NOT NULL DEFAULT current_timestamp
);
CREATE TRIGGER search_history_modtime BEFORE UPDATE ON omnivore.search_history FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column();
COMMIT;

View file

@ -0,0 +1,9 @@
-- Type: UNDO
-- Name: search_history
-- Description: Create search_history table which contains searched keyword and timestamp
BEGIN;
DROP TABLE IF EXISTS omnivore.search_history;
COMMIT;