2026-05-18 08:25:24 +07:00
|
|
|
import postgres from 'postgres';
|
|
|
|
|
import { config } from '../env';
|
2026-05-21 22:31:55 +07:00
|
|
|
import { getErrorMessage } from '../utils/file';
|
2026-05-18 08:25:24 +07:00
|
|
|
import logger from '../utils/logger';
|
|
|
|
|
|
|
|
|
|
const schemaSql = await Bun.file('schema.sql').text();
|
|
|
|
|
const sql = postgres(config.databaseUrl, { max: 1 });
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await sql.unsafe(schemaSql);
|
|
|
|
|
logger.info('Database migration completed');
|
2026-05-21 22:31:55 +07:00
|
|
|
} catch (error: unknown) {
|
|
|
|
|
logger.error('Database migration failed', { error: getErrorMessage(error) });
|
2026-05-18 08:25:24 +07:00
|
|
|
process.exitCode = 1;
|
|
|
|
|
} finally {
|
|
|
|
|
await sql.end();
|
|
|
|
|
}
|