4133052165
Integrate PostgreSQL database support, add Docker deployment configurations, and implement health check endpoints. Replit-Commit-Author: Agent Replit-Commit-Session-Id: ceced2fc-aa46-458d-ba87-ddd4b7bb1518 Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/659922a9-0087-461c-90dd-6d9a58b81d4d/ceced2fc-aa46-458d-ba87-ddd4b7bb1518/ahHWEFX
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { drizzle } from 'drizzle-orm/neon-http';
|
|
import { neon } from '@neondatabase/serverless';
|
|
import * as schema from '@shared/schema';
|
|
|
|
let db: ReturnType<typeof drizzle> | null = null;
|
|
|
|
export function getDatabase() {
|
|
if (!db) {
|
|
const databaseUrl = process.env.DATABASE_URL;
|
|
|
|
if (!databaseUrl) {
|
|
throw new Error('DATABASE_URL environment variable is not set');
|
|
}
|
|
|
|
const sql = neon(databaseUrl);
|
|
db = drizzle(sql, { schema });
|
|
}
|
|
|
|
return db;
|
|
}
|
|
|
|
export async function initializeDatabase() {
|
|
try {
|
|
const database = getDatabase();
|
|
|
|
// Create default labels if they don't exist
|
|
const existingLabels = await database.select().from(schema.labels);
|
|
|
|
if (existingLabels.length === 0) {
|
|
const defaultLabels = [
|
|
{ name: "Work", color: "#3B82F6" },
|
|
{ name: "Personal", color: "#10B981" },
|
|
{ name: "Urgent", color: "#EF4444" },
|
|
{ name: "Study", color: "#8B5CF6" },
|
|
];
|
|
|
|
await database.insert(schema.labels).values(defaultLabels);
|
|
console.log('✓ Created default labels');
|
|
}
|
|
|
|
console.log('✓ Database initialized successfully');
|
|
} catch (error) {
|
|
console.error('Failed to initialize database:', error);
|
|
throw error;
|
|
}
|
|
}
|