-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathapi-keys.ts
More file actions
25 lines (23 loc) · 785 Bytes
/
api-keys.ts
File metadata and controls
25 lines (23 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { index, pgTable, text, timestamp } from 'drizzle-orm/pg-core'
import { users } from './users.js'
export const apiKeys = pgTable(
'api_keys',
{
id: text('id').primaryKey(),
userId: text('user_id')
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
name: text('name').notNull(),
prefix: text('prefix').notNull().unique(),
hash: text('hash').notNull(),
lastUsedAt: timestamp('last_used_at'),
expiresAt: timestamp('expires_at'),
createdAt: timestamp('created_at').defaultNow().notNull(),
},
table => [
index('api_keys_prefix_idx').on(table.prefix),
index('api_keys_user_id_idx').on(table.userId),
],
)
export type ApiKey = typeof apiKeys.$inferSelect
export type NewApiKey = typeof apiKeys.$inferInsert