This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
import { drizzle } from 'drizzle-orm/node-postgres';
|
||||
import * as schema from './schema';
|
||||
import 'dotenv/config';
|
||||
import dotenv from 'dotenv';
|
||||
dotenv.config({ path: ['.env.local', '.env'] });
|
||||
|
||||
export const db = drizzle(process.env.POSTGRES_URL!, { schema });
|
||||
const DATABASE_URL = process.env.POSTGRES_URL;
|
||||
if (!DATABASE_URL) {
|
||||
throw new Error('POSTGRES_URL environment variable is required');
|
||||
}
|
||||
|
||||
export const db = drizzle(DATABASE_URL, { schema });
|
||||
|
||||
// Re-export schema types for convenience
|
||||
export * from './schema';
|
||||
|
@@ -28,9 +28,7 @@ export const habits = pgTable(
|
||||
createdAt: timestamp('created_at').defaultNow().notNull(),
|
||||
archivedAt: timestamp('archived_at'),
|
||||
},
|
||||
(table) => ({
|
||||
userIdIdx: index('habits_user_id_idx').on(table.userId),
|
||||
}),
|
||||
(table) => [index('habits_user_id_idx').on(table.userId)],
|
||||
);
|
||||
|
||||
export const habitLogs = pgTable(
|
||||
@@ -43,10 +41,10 @@ export const habitLogs = pgTable(
|
||||
loggedAt: timestamp('logged_at').defaultNow().notNull(),
|
||||
note: text('note'),
|
||||
},
|
||||
(table) => ({
|
||||
habitIdIdx: index('habit_logs_habit_id_idx').on(table.habitId),
|
||||
loggedAtIdx: index('habit_logs_logged_at_idx').on(table.loggedAt),
|
||||
}),
|
||||
(table) => [
|
||||
index('habit_logs_habit_id_idx').on(table.habitId),
|
||||
index('habit_logs_logged_at_idx').on(table.loggedAt),
|
||||
],
|
||||
);
|
||||
|
||||
// Relations
|
||||
|
Reference in New Issue
Block a user