Files
gongxue-base/apps/server/src/migration-runner.ts
xiong cbc04fea4f
Some checks failed
CI 检查 / lint (pull_request) Has been cancelled
CI 检查 / typecheck (pull_request) Has been cancelled
CI 检查 / test (pull_request) Has been cancelled
feat: add exam score management
2026-07-21 16:04:17 +08:00

29 lines
1000 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { DataSource } from 'typeorm';
import { InitialSchema1784520727860 } from './migrations/1784520727860-InitialSchema';
import { AddExamManagement1784600000000 } from './migrations/1784600000000-AddExamManagement';
import { config } from 'dotenv';
config();
const isMySQL = (process.env.DB_TYPE || 'sqlite') === 'mysql';
export async function runMigrationsOnStartup(): Promise<void> {
// 该迁移由 MySQL 生成SQLite 开发环境由 AppModule 中的 TypeORM synchronize 建表。
if (!isMySQL) return;
const ds = new DataSource({
type: 'mysql',
host: process.env.DB_HOST || 'localhost',
port: Number(process.env.DB_PORT || 3306),
username: process.env.DB_USERNAME || 'root',
password: process.env.DB_PASSWORD || '',
database: process.env.DB_DATABASE || 'dorm_billing',
charset: 'utf8mb4',
migrations: [InitialSchema1784520727860, AddExamManagement1784600000000],
});
await ds.initialize();
await ds.runMigrations();
await ds.destroy();
}