feat(database): manage the schema with typeorm migrations
- replace synchronize with migrations, starting with a generated initial migration that adopts databases created by synchronize - apply pending migrations in the docker container before the server, and refuse to start the server while migrations are pending - share one entity list and data source between app, migration runner, typeorm cli and tests; tests run the real migrations - add migration:run, migration:show and migration:generate scripts and a test that fails when entities and migrations differ - exit with code 1 when startup fails - bump version to 1.20.0
This commit is contained in:
1 parent
0ae807d68d
commit
95c3bd7bcb
17 files changed
+526
-80
No files matched your search
@@ -9,6 +9,7 @@ import type { NestExpressApplication } from "@nestjs/platform-express";
|
||||
import { ScheduleModule } from "@nestjs/schedule";
|
||||
|
||||
import { configureBodyParsers } from "../src/common/body-parsers";
|
||||
import { dataSourceOptions } from "../src/database/data-source";
|
||||
import { ImportModule } from "../src/import/import.module";
|
||||
|
||||
jest.mock("@nestjs/common", () => {
|
||||
@@ -42,25 +43,10 @@ import { SessionModule } from "../src/session/session.module";
|
||||
import { EnvironmentModule } from "../src/environment/environment.module";
|
||||
import { ScenarioModule } from "../src/scenario/scenario.module";
|
||||
import { McpModule } from "../src/mcp/mcp.module";
|
||||
import { SessionEntity } from "../src/session/session.entity";
|
||||
import { EnvironmentEntity } from "../src/environment/environment.entity";
|
||||
import { ScenarioEntity } from "../src/scenario/scenario.entity";
|
||||
import { ScenarioStepEntity } from "../src/scenario/scenario-step.entity";
|
||||
import { ScenarioVersionEntity } from "../src/scenario/scenario-version.entity";
|
||||
import { SnippetVersionEntity } from "../src/snippet/snippet-version.entity";
|
||||
import { ScenarioRunEntity } from "../src/scenario/scenario-run.entity";
|
||||
import { ScenarioRunStepEntity } from "../src/scenario/scenario-run-step.entity";
|
||||
import { ScenarioRunLogEntity } from "../src/scenario/scenario-run-log.entity";
|
||||
import { ScenarioCredentialEntity } from "../src/scenario/scenario-credential.entity";
|
||||
import { CredentialEntity } from "../src/credential/credential.entity";
|
||||
import { SnippetEntity } from "../src/snippet/snippet.entity";
|
||||
import { HealthController } from "../src/health/health.controller";
|
||||
import { HttpExceptionFilter } from "../src/filters/http-exception.filter";
|
||||
import { LoggingInterceptor } from "../src/interceptors/logging.interceptor";
|
||||
import { validateAppConfig } from "../src/config/app.config";
|
||||
import { FileEntity } from "../src/file/file.entity";
|
||||
import { ScenarioFileEntity } from "../src/file/scenario-file.entity";
|
||||
import { ScenarioRunFileEntity } from "../src/file/scenario-run-file.entity";
|
||||
|
||||
export async function buildTestApp(): Promise<INestApplication> {
|
||||
// Each test app stores files in its own temp dir: suites run in parallel and
|
||||
@@ -75,27 +61,10 @@ export async function buildTestApp(): Promise<INestApplication> {
|
||||
ignoreEnvFile: true,
|
||||
validate: validateAppConfig,
|
||||
}),
|
||||
// The real migrations, not synchronize, so tests use the schema production gets
|
||||
TypeOrmModule.forRoot({
|
||||
type: "better-sqlite3",
|
||||
database: ":memory:",
|
||||
entities: [
|
||||
SessionEntity,
|
||||
EnvironmentEntity,
|
||||
ScenarioEntity,
|
||||
ScenarioStepEntity,
|
||||
ScenarioVersionEntity,
|
||||
ScenarioRunEntity,
|
||||
ScenarioRunStepEntity,
|
||||
ScenarioRunLogEntity,
|
||||
ScenarioCredentialEntity,
|
||||
CredentialEntity,
|
||||
SnippetEntity,
|
||||
SnippetVersionEntity,
|
||||
FileEntity,
|
||||
ScenarioFileEntity,
|
||||
ScenarioRunFileEntity,
|
||||
],
|
||||
synchronize: true,
|
||||
...dataSourceOptions(":memory:"),
|
||||
migrationsRun: true,
|
||||
}),
|
||||
ScheduleModule.forRoot(),
|
||||
BrowserModule,
|
||||
|
||||
Reference in new issue
Block a user