Add entity class

This commit is contained in:
Hongbo Wu 2022-05-27 10:41:29 +08:00
parent 5bb720c54d
commit 849adf84d4
3 changed files with 64 additions and 0 deletions

View 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
}

View 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;

View file

@ -0,0 +1,9 @@
-- Type: UNDO
-- Name: api_key
-- Description: api_key model
BEGIN;
DROP TABLE omnivore.api_key;
COMMIT;