diff --git a/packages/api/src/entity/search_history.ts b/packages/api/src/entity/search_history.ts new file mode 100644 index 000000000..99cf4044f --- /dev/null +++ b/packages/api/src/entity/search_history.ts @@ -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 +} diff --git a/packages/db/migrations/0097.do.search_history.sql b/packages/db/migrations/0097.do.search_history.sql new file mode 100755 index 000000000..205bb66c0 --- /dev/null +++ b/packages/db/migrations/0097.do.search_history.sql @@ -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; diff --git a/packages/db/migrations/0097.undo.search_history.sql b/packages/db/migrations/0097.undo.search_history.sql new file mode 100755 index 000000000..f6729d9dd --- /dev/null +++ b/packages/db/migrations/0097.undo.search_history.sql @@ -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;