jedmund-svelte/scripts/init-db.ts
Justin Edmund 974781b685 fix: Svelte 5 migration and linting improvements (61 errors fixed)
Complete Svelte 5 runes migration and fix remaining ESLint errors:

**Svelte 5 Migration (40 errors):**
- Add $state() and $state.raw() for reactive variables and DOM refs
- Replace deprecated on:event directives with onevent syntax
- Fix closure capture issues in derived values
- Replace svelte:self with direct component imports
- Fix state initialization and reactivity issues

**TypeScript/ESLint (8 errors):**
- Replace explicit any types with proper types (Prisma.MediaWhereInput, unknown)
- Remove unused imports and rename unused variables with underscore prefix
- Convert require() to ES6 import syntax

**Other Fixes (13 errors):**
- Disable custom element props warnings for form components
- Fix self-closing textarea tags
- Add aria-labels to icon-only buttons
- Add keyboard handlers for interactive elements
- Refactor map popup to use Svelte component instead of HTML strings

Files modified: 28 components, 2 scripts, 1 utility
New file: MapPopup.svelte for geolocation popup content
2025-11-24 04:47:22 -08:00

58 lines
1.7 KiB
TypeScript

import { PrismaClient } from '@prisma/client'
import { execSync } from 'child_process'
const prisma = new PrismaClient()
async function isDatabaseInitialized(): Promise<boolean> {
try {
// Check if we have any completed migrations
const migrationCount = await prisma.$queryRaw<[{ count: bigint }]>`
SELECT COUNT(*) as count
FROM _prisma_migrations
WHERE finished_at IS NOT NULL
`
return migrationCount[0].count > 0n
} catch (error: unknown) {
// If the table doesn't exist, database is not initialized
const message = error instanceof Error ? error.message : String(error)
console.log('📊 Migration table check failed (expected on first deploy):', message)
return false
}
}
async function initializeDatabase() {
console.log('🔍 Checking database initialization status...')
// Give the database a moment to be ready
await new Promise((resolve) => setTimeout(resolve, 2000))
try {
const isInitialized = await isDatabaseInitialized()
if (!isInitialized) {
console.log('📦 First time setup detected. Initializing database...')
// Run migrations
console.log('🔄 Running database migrations...')
execSync('pnpm exec prisma migrate deploy', { stdio: 'inherit' })
// Run seeds
console.log('🌱 Seeding database...')
execSync('pnpm exec prisma db seed', { stdio: 'inherit' })
console.log('✅ Database initialization complete!')
} else {
console.log('✅ Database already initialized. Running migrations only...')
execSync('pnpm exec prisma migrate deploy', { stdio: 'inherit' })
}
} catch (error) {
console.error('❌ Database initialization failed:', error)
process.exit(1)
} finally {
await prisma.$disconnect()
}
}
// Run the initialization
initializeDatabase()