import { NextResponse } from 'next/server'
import { runAutoMigration } from '@/lib/services/auto-migration'

// This endpoint runs automatically on first API call
// It's safe to call multiple times - migrations only run once per server instance
export async function POST() {
  try {
    const result = await runAutoMigration()
    return NextResponse.json(result)
  } catch (error) {
    console.error('[API] Auto migration error:', error)
    return NextResponse.json({ 
      success: false, 
      error: 'Migration failed',
      created: 0,
      errors: 1 
    }, { status: 500 })
  }
}

// GET also triggers migration for convenience
export async function GET() {
  return POST()
}
