refactor: update DB schema for better-auth conventions
This commit is contained in:
@@ -1,55 +1,47 @@
|
||||
import { pgTable, text, timestamp, integer, boolean, primaryKey } from 'drizzle-orm/pg-core';
|
||||
import { pgTable, text, timestamp, boolean } from 'drizzle-orm/pg-core';
|
||||
|
||||
export const users = pgTable('user', {
|
||||
export const user = pgTable('user', {
|
||||
id: text('id').primaryKey(),
|
||||
name: text('name'),
|
||||
email: text('email').notNull(),
|
||||
emailVerified: timestamp('emailVerified', { mode: 'string' }),
|
||||
email: text('email').notNull().unique(),
|
||||
emailVerified: boolean('emailVerified').default(false),
|
||||
image: text('image'),
|
||||
createdAt: timestamp('createdAt').defaultNow(),
|
||||
updatedAt: timestamp('updatedAt').defaultNow(),
|
||||
});
|
||||
|
||||
export const accounts = pgTable('account', {
|
||||
userId: text('userId').notNull().references(() => users.id, { onDelete: 'cascade' }),
|
||||
type: text('type').notNull(),
|
||||
provider: text('provider').notNull(),
|
||||
providerAccountId: text('providerAccountId').notNull(),
|
||||
refresh_token: text('refresh_token'),
|
||||
access_token: text('access_token'),
|
||||
expires_at: text('expires_at'),
|
||||
token_type: text('token_type'),
|
||||
export const session = pgTable('session', {
|
||||
id: text('id').primaryKey(),
|
||||
expiresAt: timestamp('expiresAt').notNull(),
|
||||
token: text('token').notNull().unique(),
|
||||
createdAt: timestamp('createdAt').defaultNow(),
|
||||
updatedAt: timestamp('updatedAt').defaultNow(),
|
||||
ipAddress: text('ipAddress'),
|
||||
userAgent: text('userAgent'),
|
||||
userId: text('userId').notNull().references(() => user.id, { onDelete: 'cascade' }),
|
||||
});
|
||||
|
||||
export const account = pgTable('account', {
|
||||
id: text('id').primaryKey(),
|
||||
accountId: text('accountId').notNull(),
|
||||
providerId: text('providerId').notNull(),
|
||||
userId: text('userId').notNull().references(() => user.id, { onDelete: 'cascade' }),
|
||||
accessToken: text('accessToken'),
|
||||
refreshToken: text('refreshToken'),
|
||||
accessTokenExpiresAt: timestamp('accessTokenExpiresAt'),
|
||||
refreshTokenExpiresAt: timestamp('refreshTokenExpiresAt'),
|
||||
scope: text('scope'),
|
||||
id_token: text('id_token'),
|
||||
session_state: text('session_state'),
|
||||
}, (account) => ({
|
||||
compoundKey: primaryKey({ columns: [account.provider, account.providerAccountId] })
|
||||
}));
|
||||
|
||||
export const sessions = pgTable('session', {
|
||||
sessionToken: text().primaryKey().notNull(),
|
||||
userId: text().notNull().references(() => users.id, { onDelete: 'cascade' }),
|
||||
expires: timestamp({ mode: 'string' }).notNull(),
|
||||
idToken: text('idToken'),
|
||||
password: text('password'),
|
||||
createdAt: timestamp('createdAt').defaultNow(),
|
||||
updatedAt: timestamp('updatedAt').defaultNow(),
|
||||
});
|
||||
|
||||
export const verificationTokens = pgTable('verificationToken', {
|
||||
export const verification = pgTable('verification', {
|
||||
id: text('id').primaryKey(),
|
||||
identifier: text('identifier').notNull(),
|
||||
token: text('token').notNull(),
|
||||
expires: timestamp('expires', { mode: 'string' }).notNull(),
|
||||
}, (vt) => ({
|
||||
compoundKey: primaryKey({ columns: [vt.identifier, vt.token] })
|
||||
}));
|
||||
|
||||
export const authenticators = pgTable('authenticator', {
|
||||
credentialID: text('credentialID').notNull().unique(),
|
||||
userId: text('userId').notNull().references(() => users.id, { onDelete: 'cascade' }),
|
||||
providerAccountId: text('providerAccountId').notNull(),
|
||||
credentialPublicKey: text('credentialPublicKey').notNull(),
|
||||
counter: integer('counter').notNull(),
|
||||
credentialDeviceType: text('credentialDeviceType').notNull(),
|
||||
credentialBackedUp: boolean('credentialBackedUp').notNull(),
|
||||
transports: text('transports'),
|
||||
}, (authenticator) => ({
|
||||
compositePK: primaryKey({
|
||||
columns: [authenticator.credentialID, authenticator.userId],
|
||||
name: "authenticator_userId_credentialID_pk"
|
||||
})
|
||||
}));
|
||||
value: text('value').notNull(),
|
||||
expiresAt: timestamp('expiresAt').notNull(),
|
||||
createdAt: timestamp('createdAt').defaultNow(),
|
||||
updatedAt: timestamp('updatedAt').defaultNow(),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user