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