mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-15 20:17:22 +00:00
hybrid: fix timing for automatic schema syncs to work with plugins
This commit is contained in:
@@ -5,7 +5,6 @@ import type { em as prototypeEm } from "data/prototype";
|
|||||||
import { Connection } from "data/connection/Connection";
|
import { Connection } from "data/connection/Connection";
|
||||||
import type { Hono } from "hono";
|
import type { Hono } from "hono";
|
||||||
import {
|
import {
|
||||||
type InitialModuleConfigs,
|
|
||||||
type ModuleConfigs,
|
type ModuleConfigs,
|
||||||
type Modules,
|
type Modules,
|
||||||
ModuleManager,
|
ModuleManager,
|
||||||
@@ -381,8 +380,10 @@ export class App<
|
|||||||
if (results.length > 0) {
|
if (results.length > 0) {
|
||||||
for (const { name, result } of results) {
|
for (const { name, result } of results) {
|
||||||
if (result) {
|
if (result) {
|
||||||
$console.log(`[Plugin:${name}] schema`);
|
|
||||||
ctx.helper.ensureSchema(result);
|
ctx.helper.ensureSchema(result);
|
||||||
|
if (ctx.flags.sync_required) {
|
||||||
|
$console.log(`[Plugin:${name}] schema, sync required`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,26 +23,17 @@ export type HybridMode<AdapterConfig extends BkndConfig> = AdapterConfig extends
|
|||||||
? BkndModeConfig<Args, Merge<BkndHybridModeOptions & AdapterConfig>>
|
? BkndModeConfig<Args, Merge<BkndHybridModeOptions & AdapterConfig>>
|
||||||
: never;
|
: never;
|
||||||
|
|
||||||
export function hybrid<Args>({
|
export function hybrid<Args>(hybridConfig: HybridBkndConfig<Args>): BkndConfig<Args> {
|
||||||
configFilePath = "bknd-config.json",
|
|
||||||
...rest
|
|
||||||
}: HybridBkndConfig<Args>): BkndConfig<Args> {
|
|
||||||
return {
|
return {
|
||||||
...rest,
|
|
||||||
config: undefined,
|
|
||||||
app: async (args) => {
|
app: async (args) => {
|
||||||
const {
|
const {
|
||||||
config: appConfig,
|
config: appConfig,
|
||||||
isProd,
|
isProd,
|
||||||
plugins,
|
plugins,
|
||||||
syncSchemaOptions,
|
syncSchemaOptions,
|
||||||
} = await makeModeConfig(
|
} = await makeModeConfig(hybridConfig, args);
|
||||||
{
|
|
||||||
...rest,
|
const configFilePath = appConfig.configFilePath ?? "bknd-config.json";
|
||||||
configFilePath,
|
|
||||||
},
|
|
||||||
args,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (appConfig?.options?.mode && appConfig?.options?.mode !== "db") {
|
if (appConfig?.options?.mode && appConfig?.options?.mode !== "db") {
|
||||||
$console.warn("You should not set a different mode than `db` when using hybrid mode");
|
$console.warn("You should not set a different mode than `db` when using hybrid mode");
|
||||||
@@ -80,6 +71,13 @@ export function hybrid<Args>({
|
|||||||
skipValidation: isProd,
|
skipValidation: isProd,
|
||||||
// secrets are required for hybrid mode
|
// secrets are required for hybrid mode
|
||||||
secrets: appConfig.secrets,
|
secrets: appConfig.secrets,
|
||||||
|
onModulesBuilt: async (ctx) => {
|
||||||
|
if (ctx.flags.sync_required && !isProd && syncSchemaOptions.force) {
|
||||||
|
$console.log("[hybrid] syncing schema");
|
||||||
|
await ctx.em.schema().sync(syncSchemaOptions);
|
||||||
|
}
|
||||||
|
await appConfig?.options?.manager?.onModulesBuilt?.(ctx);
|
||||||
|
},
|
||||||
...appConfig?.options?.manager,
|
...appConfig?.options?.manager,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -68,7 +68,7 @@
|
|||||||
"noArrayIndexKey": "off",
|
"noArrayIndexKey": "off",
|
||||||
"noImplicitAnyLet": "warn",
|
"noImplicitAnyLet": "warn",
|
||||||
"noConfusingVoidType": "off",
|
"noConfusingVoidType": "off",
|
||||||
"noConsole": { "level": "warn", "options": { "allow": ["log"] } }
|
"noConsole": { "level": "warn", "options": { "allow": ["error"] } }
|
||||||
},
|
},
|
||||||
"security": {
|
"security": {
|
||||||
"noDangerouslySetInnerHtml": "off"
|
"noDangerouslySetInnerHtml": "off"
|
||||||
|
|||||||
Reference in New Issue
Block a user