mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Add entity class
This commit is contained in:
parent
5bb720c54d
commit
849adf84d4
3 changed files with 64 additions and 0 deletions
37
packages/api/src/entity/api_key.ts
Normal file
37
packages/api/src/entity/api_key.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm'
|
||||
import { User } from './user'
|
||||
|
||||
@Entity()
|
||||
export class ApiKey {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id!: string
|
||||
|
||||
@ManyToOne(() => User, { onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'user_id' })
|
||||
user!: User
|
||||
|
||||
@Column('text')
|
||||
name!: string
|
||||
|
||||
@Column('text')
|
||||
key!: string
|
||||
|
||||
@Column('text', { array: true })
|
||||
scopes?: string[]
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt!: Date
|
||||
|
||||
@Column('date')
|
||||
expiresAt!: Date
|
||||
|
||||
@Column('date', { nullable: true })
|
||||
usedAt!: Date | null
|
||||
}
|
||||
18
packages/db/migrations/0084.do.api_key.sql
Executable file
18
packages/db/migrations/0084.do.api_key.sql
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
-- Type: DO
|
||||
-- Name: api_key
|
||||
-- Description: api_key model
|
||||
|
||||
BEGIN;
|
||||
|
||||
CREATE TABLE omnivore.api_key (
|
||||
id uuid PRIMARY KEY DEFAULT uuid_generate_v1mc(),
|
||||
user_id uuid NOT NULL REFERENCES omnivore.user (id) ON DELETE CASCADE,
|
||||
name text NOT NULL,
|
||||
key text NOT NULL,
|
||||
scopes text[] NOT NULL DEFAULT '{}',
|
||||
expires_at timestamptz NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT current_timestamp,
|
||||
used_at timestamptz
|
||||
);
|
||||
|
||||
COMMIT;
|
||||
9
packages/db/migrations/0084.undo.api_key.sql
Executable file
9
packages/db/migrations/0084.undo.api_key.sql
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
-- Type: UNDO
|
||||
-- Name: api_key
|
||||
-- Description: api_key model
|
||||
|
||||
BEGIN;
|
||||
|
||||
DROP TABLE omnivore.api_key;
|
||||
|
||||
COMMIT;
|
||||
Loading…
Reference in a new issue