Complete implementation ready for Coolify: - Node.js 22 + Fastify + socket.io backend - PostgreSQL 16 + Redis 7 services - Docker Compose configuration - Deployment scripts and documentation Co-Authored-By: Paperclip <noreply@paperclip.ing>
33 lines
917 B
TypeScript
33 lines
917 B
TypeScript
import { drizzle } from 'drizzle-orm/node-postgres';
|
|
import { migrate } from 'drizzle-orm/node-postgres/migrator';
|
|
import { Pool } from 'pg';
|
|
|
|
async function main() {
|
|
const pool = new Pool({
|
|
host: process.env.POSTGRES_HOST || 'localhost',
|
|
port: Number(process.env.POSTGRES_PORT) || 5432,
|
|
user: process.env.POSTGRES_USER || 'agenthub',
|
|
password: process.env.POSTGRES_PASSWORD || 'agenthub',
|
|
database: process.env.POSTGRES_DB || 'agenthub',
|
|
});
|
|
|
|
pool.on('connect', (client) => {
|
|
client.query("SET TIME ZONE 'UTC'");
|
|
});
|
|
|
|
const db = drizzle(pool);
|
|
|
|
console.log('[migrate] Running migrations...');
|
|
|
|
try {
|
|
await migrate(db, { migrationsFolder: './drizzle' });
|
|
console.log('[migrate] ✓ Migrations applied successfully.');
|
|
} catch (error) {
|
|
console.error('[migrate] ✗ Migration failed:', error);
|
|
process.exit(1);
|
|
} finally {
|
|
await pool.end();
|
|
}
|
|
}
|
|
|
|
main();
|