- Bun 1.3.6 server setup - MariaDB schema (projects, agents, tasks) - Auto-migrations on startup - WebSocket support - Health check endpoint Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
40 lines
976 B
TypeScript
40 lines
976 B
TypeScript
/**
|
|
* Database Migrations Runner
|
|
* Runs automatically on app startup
|
|
*/
|
|
|
|
import { drizzle } from 'drizzle-orm/mysql2'
|
|
import { migrate } from 'drizzle-orm/mysql2/migrator'
|
|
import mysql from 'mysql2/promise'
|
|
|
|
export async function runMigrations() {
|
|
console.log('🔄 Running database migrations...')
|
|
|
|
const connection = await mysql.createConnection({
|
|
host: process.env.DB_HOST,
|
|
port: parseInt(process.env.DB_PORT || '3306'),
|
|
user: process.env.DB_USER,
|
|
password: process.env.DB_PASSWORD,
|
|
database: process.env.DB_NAME,
|
|
})
|
|
|
|
const db = drizzle(connection)
|
|
|
|
try {
|
|
await migrate(db, { migrationsFolder: './drizzle/migrations' })
|
|
console.log('✅ Migrations completed successfully')
|
|
await connection.end()
|
|
return true
|
|
} catch (error) {
|
|
console.error('❌ Migration failed:', error)
|
|
await connection.end()
|
|
throw error
|
|
}
|
|
}
|
|
|
|
// Run if executed directly
|
|
if (import.meta.main) {
|
|
await runMigrations()
|
|
process.exit(0)
|
|
}
|