mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Create search_history table and entity class
This commit is contained in:
parent
9b64299c6b
commit
cd13e5874a
3 changed files with 55 additions and 0 deletions
29
packages/api/src/entity/search_history.ts
Normal file
29
packages/api/src/entity/search_history.ts
Normal 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
|
||||
}
|
||||
17
packages/db/migrations/0097.do.search_history.sql
Executable file
17
packages/db/migrations/0097.do.search_history.sql
Executable 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;
|
||||
9
packages/db/migrations/0097.undo.search_history.sql
Executable file
9
packages/db/migrations/0097.undo.search_history.sql
Executable 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;
|
||||
Loading…
Reference in a new issue