Initial commit: Backend with Bun.serve() + Drizzle ORM
- 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>
This commit is contained in:
39
src/db/migrate.ts
Normal file
39
src/db/migrate.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* 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)
|
||||
}
|
||||
Reference in New Issue
Block a user