From 6c3c5c319dc629e81979d44991118c6b781c38ca Mon Sep 17 00:00:00 2001 From: alexfriesen Date: Thu, 2 Jan 2025 17:45:33 +0100 Subject: [PATCH] feature(database): add user credential schema --- apps/timer/server/database/schema.ts | 1 + apps/timer/server/database/user-credential.ts | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 apps/timer/server/database/user-credential.ts diff --git a/apps/timer/server/database/schema.ts b/apps/timer/server/database/schema.ts index 71001ae..117e607 100644 --- a/apps/timer/server/database/schema.ts +++ b/apps/timer/server/database/schema.ts @@ -1,5 +1,6 @@ export { sessions } from './session'; export { users } from './user'; +export { userCredentials } from './user-credential'; export { times } from './time'; export { projects } from './project'; diff --git a/apps/timer/server/database/user-credential.ts b/apps/timer/server/database/user-credential.ts new file mode 100644 index 0000000..5df9e9f --- /dev/null +++ b/apps/timer/server/database/user-credential.ts @@ -0,0 +1,26 @@ +import { + boolean, + integer, + json, + pgTable, + text, + unique, + uuid, +} from 'drizzle-orm/pg-core'; + +import { users } from './user'; + +export const userCredentials = pgTable( + 'user_credential', + { + id: text('id').notNull().unique(), + userId: uuid('user_id') + .references(() => users.id, { onDelete: 'cascade' }) + .notNull(), + publicKey: text('public_key').notNull(), + counter: integer('counter').notNull(), + backedUp: boolean('backed_up').notNull(), + transports: json('transports').notNull().$type(), + }, + (table) => [unique().on(table.userId, table.id)] +);