mirror of
https://github.com/movie-web/backend.git
synced 2025-09-13 18:13:26 +00:00
Add option to enable MikroORM database debug logging
This commit is contained in:
@@ -41,6 +41,10 @@ export const configSchema = z.object({
|
|||||||
// will always keep the database schema in sync with the connected database
|
// will always keep the database schema in sync with the connected database
|
||||||
// it is extremely destructive, do not use it EVER in production
|
// it is extremely destructive, do not use it EVER in production
|
||||||
syncSchema: z.coerce.boolean().default(false),
|
syncSchema: z.coerce.boolean().default(false),
|
||||||
|
|
||||||
|
// Enable debug logging for MikroORM - Outputs queries and entity management logs
|
||||||
|
// Do NOT use in production, leaks all sensitive data
|
||||||
|
debugLogging: z.coerce.boolean().default(false),
|
||||||
}),
|
}),
|
||||||
crypto: z.object({
|
crypto: z.object({
|
||||||
// session secret. used for signing session tokens
|
// session secret. used for signing session tokens
|
||||||
|
@@ -14,8 +14,10 @@ export function getORM() {
|
|||||||
|
|
||||||
export async function setupMikroORM() {
|
export async function setupMikroORM() {
|
||||||
log.info(`Connecting to postgres`, { evt: 'connecting' });
|
log.info(`Connecting to postgres`, { evt: 'connecting' });
|
||||||
const mikro = await createORM(conf.postgres.connection, (msg) =>
|
const mikro = await createORM(
|
||||||
log.info(msg),
|
conf.postgres.connection,
|
||||||
|
conf.postgres.debugLogging,
|
||||||
|
(msg) => log.info(msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (conf.postgres.syncSchema) {
|
if (conf.postgres.syncSchema) {
|
||||||
|
@@ -16,9 +16,14 @@ export function makeOrmConfig(url: string): Options<PostgreSqlDriver> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createORM(url: string, log: (msg: string) => void) {
|
export async function createORM(
|
||||||
|
url: string,
|
||||||
|
debug: boolean,
|
||||||
|
log: (msg: string) => void,
|
||||||
|
) {
|
||||||
return await MikroORM.init<PostgreSqlDriver>({
|
return await MikroORM.init<PostgreSqlDriver>({
|
||||||
...makeOrmConfig(url),
|
...makeOrmConfig(url),
|
||||||
logger: log,
|
logger: log,
|
||||||
|
debug,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user