feat: migrate from SQLite to PostgreSQL - complete schema and API updates

- Remove better-sqlite3, add pg driver
- Convert schema to PostgreSQL types (serial, timestamp, boolean, jsonb)
- Generate fresh PostgreSQL migrations
- Update database connection layer with pg.Pool
- Fix all API routes: remove JSON.parse/stringify, use native timestamps and booleans
- Update drizzle.config.ts and .env.example for PostgreSQL
This commit is contained in:
Marko Djordjevic 2026-02-17 13:43:06 +01:00
parent 4605283d2b
commit 5f70f13da3
37 changed files with 1164 additions and 1825 deletions

View file

@ -85,7 +85,6 @@ export async function POST(request: NextRequest): Promise<NextResponse> {
// Create the chart
const [newChart] = await db.insert(charts).values({
name: chartName,
created_at: Math.floor(Date.now() / 1000),
}).returning();
// Parse and prepare candle data
@ -99,9 +98,10 @@ export async function POST(request: NextRequest): Promise<NextResponse> {
if (isNaN(date.getTime())) {
throw new Error(`Invalid date format: ${row.time}`);
}
timestamp = Math.floor(date.getTime() / 1000);
timestamp = date; // PostgreSQL timestamp type expects Date object or ISO string
} else if (typeof row.time === 'number') {
timestamp = row.time;
// If Unix timestamp (seconds), convert to Date
timestamp = new Date(row.time * 1000);
} else {
throw new Error(`Invalid time value: ${row.time}`);
}