Skip to content

Commit 2b667cb

Browse files
committed
Migration log enabled by default
1 parent d1b02f1 commit 2b667cb

4 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/migrations/Migrations.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Logger, { ConsoleLogger } from "../common/Logger.js";
12
import { modelSymbol } from "../common/symbols/symbols.js";
23
import type QueryCompiler from "../compiler/QueryCompiler.js";
34
import ICheckConstraint from "../decorators/ICheckConstraint.js";
@@ -11,28 +12,34 @@ import type EntityQuery from "../model/EntityQuery.js";
1112

1213
export default abstract class Migrations {
1314

15+
logger: Logger;
16+
1417
constructor(
1518
private context: EntityContext,
1619
private connection: BaseConnection = context.connection,
1720
protected compiler: QueryCompiler = context.driver.compiler
18-
) {}
21+
) {
22+
23+
}
1924

2025
public async migrate({
2126
version,
2227
name = "default",
2328
historyTableName = "migrations",
29+
log = new ConsoleLogger(false),
2430
seed,
2531
createIndexForForeignKeys = true
2632
}: {
2733
version?: string,
2834
name?: string,
29-
historyTableName?:
30-
string,
35+
historyTableName?: string,
36+
log?: Logger,
3137
seed?: (c: EntityContext) => Promise<any>,
3238
createIndexForForeignKeys?: boolean
3339
} = {} ) {
3440
const { context } = this;
3541
const { model } = context;
42+
this.logger = log ?? context.logger;
3643
const postMigration = [] as (() => Promise<void>)[];
3744

3845
if (version) {
@@ -194,7 +201,7 @@ export default abstract class Migrations {
194201

195202
protected executeQuery(command: IQuery, signal?: AbortSignal): Promise<IQueryResult> {
196203
const text = typeof command === "string" ? command : command.text;
197-
this.context.logger?.log(text);
204+
this.logger?.log(text);
198205
return this.connection.executeQuery(command, signal);
199206
}
200207

src/tests/db-tests/tests/version-history.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ async function migrate(this: TestConfig) {
2020

2121
await context.connection.ensureDatabase();
2222

23-
return await context.connection.automaticMigrations(context).migrate({ version: "v1" });
23+
return await context.connection.automaticMigrations(context).migrate({ log: null, version: "v1" });
2424
}

src/tests/model/createContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export async function createContext(driver: BaseDriver, events?: ContextEvents)
1414

1515
await context.connection.ensureDatabase();
1616

17-
await context.connection.automaticMigrations(context).migrate();
17+
await context.connection.automaticMigrations(context).migrate({ log: null });
1818

1919
await seed(context);
2020

src/workflows/WorkflowStorage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export default class WorkflowStorage {
234234
async seed(version?) {
235235
const db = new WorkflowDbContext(this.driver);
236236
await db.connection.ensureDatabase();
237-
await db.connection.automaticMigrations(db).migrate({ version, name: "workflows" });
237+
await db.connection.automaticMigrations(db).migrate({ log: null, version, name: "workflows" });
238238
}
239239

240240
}

0 commit comments

Comments
 (0)