feat: Docker Compose deployment + auto migration on startup

- docker-compose.yml: 移除 MySQL 容器,连宿主机 MySQL
- main.ts: 启动前通过独立 DataSource 执行 runMigrations
- migration-runner.ts: 独立 migration 执行器
- app.module.ts: TypeORM 配置增加 migrations
- 修复 InitialSchema 中 room_expenses 和 financial_operations 重复索引
This commit is contained in:
2026-07-20 12:43:13 +08:00
parent 4c2192d85e
commit 990c0c16e6
5 changed files with 33 additions and 8 deletions

View File

@@ -1,15 +1,14 @@
import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import { AppModule } from './app.module';
import { DataSource } from 'typeorm';
import { runMigrationsOnStartup } from './migration-runner';
async function bootstrap() {
await runMigrationsOnStartup();
const app = await NestFactory.create(AppModule);
app.setGlobalPrefix('api');
app.enableCors();
const dataSource = app.get(DataSource);
await dataSource.runMigrations();
console.log('Migrations OK');
await app.listen(process.env.PORT ?? 3000);
console.log(`Server running on http://localhost:${process.env.PORT ?? 3000}`);
}