2024-06-26 17:15:38 +00:00
|
|
|
import { createId } from '@paralleldrive/cuid2';
|
|
|
|
|
import { pgTable, text, timestamp } from 'drizzle-orm/pg-core';
|
|
|
|
|
import { relations } from 'drizzle-orm';
|
|
|
|
|
import { usersTable } from './users.table';
|
2024-09-02 04:36:41 +00:00
|
|
|
import { timestamps } from '../../../common/utils/table';
|
2024-06-26 17:15:38 +00:00
|
|
|
|
|
|
|
|
export const emailVerificationsTable = pgTable('email_verifications', {
|
|
|
|
|
id: text('id')
|
|
|
|
|
.primaryKey()
|
|
|
|
|
.$defaultFn(() => createId()),
|
|
|
|
|
hashedToken: text('hashed_token').notNull(),
|
|
|
|
|
userId: text('user_id')
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => usersTable.id).unique(),
|
|
|
|
|
requestedEmail: text('requested_email').notNull(),
|
|
|
|
|
expiresAt: timestamp('expires_at', {
|
|
|
|
|
mode: 'date',
|
|
|
|
|
withTimezone: true
|
|
|
|
|
}).notNull(),
|
|
|
|
|
...timestamps
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const emailVerificationsRelations = relations(emailVerificationsTable, ({ one }) => ({
|
|
|
|
|
user: one(usersTable, {
|
|
|
|
|
fields: [emailVerificationsTable.userId],
|
|
|
|
|
references: [usersTable.id]
|
|
|
|
|
})
|
|
|
|
|
}));
|