diff --git a/packages/core/cli/src/commands/dev.js b/packages/core/cli/src/commands/dev.js index 1e17dec81..480567d18 100644 --- a/packages/core/cli/src/commands/dev.js +++ b/packages/core/cli/src/commands/dev.js @@ -46,9 +46,9 @@ module.exports = (cli) => { }); } await runAppCommand('install', ['--silent']); - if (opts.dbSync) { - await runAppCommand('db:sync'); - } + // if (opts.dbSync) { + // await runAppCommand('db:sync'); + // } if (server || !client) { console.log('starting server', serverPort); const argv = [ @@ -61,6 +61,9 @@ module.exports = (cli) => { ...process.argv.slice(3), `--port=${serverPort}`, ]; + if (opts.dbSync) { + argv.push('--db-sync'); + } run('ts-node-dev', argv, { env: { APP_PORT: serverPort, diff --git a/packages/core/client/src/collection-manager/Configuration/schemas/collections.ts b/packages/core/client/src/collection-manager/Configuration/schemas/collections.ts index a3d942816..15c2ed055 100644 --- a/packages/core/client/src/collection-manager/Configuration/schemas/collections.ts +++ b/packages/core/client/src/collection-manager/Configuration/schemas/collections.ts @@ -62,12 +62,7 @@ export const collectionSchema: ISchema = { params: { pageSize: 50, filter: { - inherit: false, - options: { - // filter auto create through collections - autoCreate: { $not: true }, - isThrough: { $not: true }, - }, + 'hidden.$isFalsy': true, }, sort: ['sort'], appends: [], diff --git a/packages/core/server/src/application.ts b/packages/core/server/src/application.ts index b55bd8a89..a29de2e66 100644 --- a/packages/core/server/src/application.ts +++ b/packages/core/server/src/application.ts @@ -83,6 +83,7 @@ interface ListenOptions { interface StartOptions { cliArgs?: any[]; + dbSync?: boolean; listen?: ListenOptions; } @@ -352,6 +353,11 @@ export class Application exten await this.db.reconnect(); } + if (options.dbSync) { + console.log('db sync...'); + await this.db.sync(); + } + await this.emitAsync('beforeStart', this, options); if (options?.listen?.port) { diff --git a/packages/core/server/src/commands/db-sync.ts b/packages/core/server/src/commands/db-sync.ts index d744144dc..8e91d9b1c 100644 --- a/packages/core/server/src/commands/db-sync.ts +++ b/packages/core/server/src/commands/db-sync.ts @@ -4,7 +4,6 @@ export default (app: Application) => { app.command('db:sync').action(async (...cliArgs) => { const [opts] = cliArgs; console.log('db sync...'); - await app.emitAsync('cli.beforeDbSync', ...cliArgs); const force = false; await app.db.sync({ force, diff --git a/packages/core/server/src/commands/start.ts b/packages/core/server/src/commands/start.ts index 5e76046b7..605e2963d 100644 --- a/packages/core/server/src/commands/start.ts +++ b/packages/core/server/src/commands/start.ts @@ -6,12 +6,14 @@ export default (app: Application) => { .option('-s, --silent') .option('-p, --port [post]') .option('-h, --host [host]') + .option('--db-sync') .action(async (...cliArgs) => { const [opts] = cliArgs; const port = opts.port || process.env.APP_PORT || 13000; const host = opts.host || process.env.APP_HOST || '0.0.0.0'; await app.start({ + dbSync: opts?.dbSync, cliArgs, listen: { port, diff --git a/packages/plugins/collection-manager/src/collections/collections.ts b/packages/plugins/collection-manager/src/collections/collections.ts index 1c4ae1007..2b08305ba 100644 --- a/packages/plugins/collection-manager/src/collections/collections.ts +++ b/packages/plugins/collection-manager/src/collections/collections.ts @@ -31,6 +31,11 @@ export default { name: 'inherit', defaultValue: false, }, + { + type: 'boolean', + name: 'hidden', + defaultValue: false, + }, { type: 'json', name: 'options', diff --git a/packages/plugins/collection-manager/src/hooks/afterCreateForForeignKeyField.ts b/packages/plugins/collection-manager/src/hooks/afterCreateForForeignKeyField.ts index 81b6a171e..afe353a13 100644 --- a/packages/plugins/collection-manager/src/hooks/afterCreateForForeignKeyField.ts +++ b/packages/plugins/collection-manager/src/hooks/afterCreateForForeignKeyField.ts @@ -140,6 +140,7 @@ export function afterCreateForForeignKeyField(db: Database) { title: through, timestamps: false, autoGenId: false, + hidden: true, autoCreate: true, isThrough: true, }, diff --git a/packages/plugins/collection-manager/src/server.ts b/packages/plugins/collection-manager/src/server.ts index d133f5f4b..663fbfad6 100644 --- a/packages/plugins/collection-manager/src/server.ts +++ b/packages/plugins/collection-manager/src/server.ts @@ -13,7 +13,7 @@ import { beforeCreateForChildrenCollection, beforeCreateForReverseField, beforeDestroyForeignKey, - beforeInitOptions, + beforeInitOptions } from './hooks'; import { CollectionModel, FieldModel } from './models'; @@ -130,7 +130,16 @@ export class CollectionManagerPlugin extends Plugin { } const exists = await this.app.db.collectionExistsInDb('collections'); if (exists) { - await this.app.db.getRepository('collections').load(); + try { + await this.app.db.getRepository('collections').load(); + } catch (error) { + await this.app.db.sync(); + try { + await this.app.db.getRepository('collections').load(); + } catch (error) { + throw error; + } + } } });