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:
@@ -1,5 +1,4 @@
|
||||
import sqlite3 from 'sqlite3'
|
||||
import path from 'path'
|
||||
import { db, schema } from './db/connection'
|
||||
|
||||
export interface AuditLogEntry {
|
||||
user_id?: number
|
||||
@@ -11,32 +10,17 @@ export interface AuditLogEntry {
|
||||
}
|
||||
|
||||
export async function logAuditEvent(entry: AuditLogEntry): Promise<void> {
|
||||
const dbPath = path.join(process.cwd(), 'database', 'antihoax.db')
|
||||
const db = new sqlite3.Database(dbPath)
|
||||
|
||||
try {
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
db.run(
|
||||
`INSERT INTO audit_logs (user_id, action, resource_type, resource_id, details, ip_address, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, datetime('now'))`,
|
||||
[
|
||||
entry.user_id || null,
|
||||
entry.action,
|
||||
entry.resource_type,
|
||||
entry.resource_id || null,
|
||||
entry.details ? JSON.stringify(entry.details) : null,
|
||||
entry.ip_address || null
|
||||
],
|
||||
(err) => {
|
||||
if (err) reject(err)
|
||||
else resolve()
|
||||
}
|
||||
)
|
||||
await db.insert(schema.auditLogs).values({
|
||||
userId: entry.user_id || null,
|
||||
action: entry.action,
|
||||
resourceType: entry.resource_type,
|
||||
resourceId: entry.resource_id || null,
|
||||
details: entry.details ? JSON.stringify(entry.details) : null,
|
||||
ipAddress: entry.ip_address || null
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Audit logging failed:', error)
|
||||
} finally {
|
||||
db.close()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user