migrate from SQLite to PostgreSQL with Drizzle ORM

- Updated all packages to latest versions (React 19, Next.js 14.2.32)
- Replaced sqlite3 with pg and drizzle-orm dependencies
- Created complete PostgreSQL schema with relationships and indexes
- Migrated all API endpoints from SQLite to Drizzle queries
- Added database seeding with sample data
- Updated authentication to use bcrypt instead of pbkdf2
- Configured connection pooling for PostgreSQL
- Updated app version to 1.0.0
- All endpoints tested and working correctly
This commit is contained in:
2025-09-06 12:56:33 +02:00
parent 52bde64e7f
commit 860070a302
26 changed files with 2526 additions and 2403 deletions

View File

@@ -1,6 +1,6 @@
import type { NextApiRequest, NextApiResponse } from "next"
import sqlite3 from "sqlite3"
import path from "path"
import { db, schema } from '../../../lib/db/connection'
import { or, like } from 'drizzle-orm'
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method !== "GET") return res.status(405).json({ error: "Method not allowed" })
@@ -8,24 +8,21 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const { q } = req.query
if (!q) return res.status(400).json({ error: "Query required" })
const dbPath = path.join(process.cwd(), "database", "antihoax.db")
const db = new sqlite3.Database(dbPath)
try {
const results = await new Promise<any[]>((resolve, reject) => {
db.all(
"SELECT * FROM sources WHERE domain LIKE ? OR title LIKE ? LIMIT 20",
[`%${q}%`, `%${q}%`],
(err, rows) => {
if (err) reject(err)
else resolve(rows)
}
const results = await db
.select()
.from(schema.sources)
.where(
or(
like(schema.sources.domain, `%${q}%`),
like(schema.sources.title, `%${q}%`)
)
)
})
.limit(20)
res.json(results)
} catch (error) {
console.error('Search error:', error)
res.status(500).json({ error: "Database error" })
} finally {
db.close()
}
}