Fix schema: use text IDs for better-auth compatibility
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { pgTable, text, timestamp, uuid, boolean, jsonb, integer } from 'drizzle-orm/pg-core';
|
||||
import { relations } from 'drizzle-orm';
|
||||
|
||||
// Users table (managed by BetterAuth, but we define it for relations)
|
||||
// Users table (managed by BetterAuth - uses text IDs)
|
||||
export const users = pgTable('users', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
id: text('id').primaryKey(),
|
||||
email: text('email').notNull().unique(),
|
||||
name: text('name').notNull(),
|
||||
emailVerified: boolean('email_verified').default(false),
|
||||
@@ -14,8 +14,8 @@ export const users = pgTable('users', {
|
||||
|
||||
// BetterAuth session table
|
||||
export const sessions = pgTable('sessions', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
userId: uuid('user_id').references(() => users.id, { onDelete: 'cascade' }).notNull(),
|
||||
id: text('id').primaryKey(),
|
||||
userId: text('user_id').references(() => users.id, { onDelete: 'cascade' }).notNull(),
|
||||
token: text('token').notNull().unique(),
|
||||
expiresAt: timestamp('expires_at').notNull(),
|
||||
ipAddress: text('ip_address'),
|
||||
@@ -26,8 +26,8 @@ export const sessions = pgTable('sessions', {
|
||||
|
||||
// BetterAuth account table (for OAuth providers)
|
||||
export const accounts = pgTable('accounts', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
userId: uuid('user_id').references(() => users.id, { onDelete: 'cascade' }).notNull(),
|
||||
id: text('id').primaryKey(),
|
||||
userId: text('user_id').references(() => users.id, { onDelete: 'cascade' }).notNull(),
|
||||
accountId: text('account_id').notNull(),
|
||||
providerId: text('provider_id').notNull(),
|
||||
accessToken: text('access_token'),
|
||||
@@ -43,7 +43,7 @@ export const accounts = pgTable('accounts', {
|
||||
|
||||
// BetterAuth verification table
|
||||
export const verifications = pgTable('verifications', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
id: text('id').primaryKey(),
|
||||
identifier: text('identifier').notNull(),
|
||||
value: text('value').notNull(),
|
||||
expiresAt: timestamp('expires_at').notNull(),
|
||||
@@ -54,7 +54,7 @@ export const verifications = pgTable('verifications', {
|
||||
// Clients table
|
||||
export const clients = pgTable('clients', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
userId: uuid('user_id').references(() => users.id, { onDelete: 'cascade' }).notNull(),
|
||||
userId: text('user_id').references(() => users.id, { onDelete: 'cascade' }).notNull(),
|
||||
|
||||
// Basic info
|
||||
firstName: text('first_name').notNull(),
|
||||
@@ -92,7 +92,7 @@ export const clients = pgTable('clients', {
|
||||
// Events table (birthdays, anniversaries, follow-ups)
|
||||
export const events = pgTable('events', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
userId: uuid('user_id').references(() => users.id, { onDelete: 'cascade' }).notNull(),
|
||||
userId: text('user_id').references(() => users.id, { onDelete: 'cascade' }).notNull(),
|
||||
clientId: uuid('client_id').references(() => clients.id, { onDelete: 'cascade' }).notNull(),
|
||||
|
||||
type: text('type').notNull(), // 'birthday' | 'anniversary' | 'followup' | 'custom'
|
||||
@@ -108,7 +108,7 @@ export const events = pgTable('events', {
|
||||
// Communications table (emails, messages)
|
||||
export const communications = pgTable('communications', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
userId: uuid('user_id').references(() => users.id, { onDelete: 'cascade' }).notNull(),
|
||||
userId: text('user_id').references(() => users.id, { onDelete: 'cascade' }).notNull(),
|
||||
clientId: uuid('client_id').references(() => clients.id, { onDelete: 'cascade' }).notNull(),
|
||||
|
||||
type: text('type').notNull(), // 'email' | 'birthday' | 'followup'
|
||||
|
||||
Reference in New Issue
Block a user