From d6e700bdd1efd6c10777a5f3a86cd380a947680c Mon Sep 17 00:00:00 2001 From: Ben Allfree Date: Wed, 31 Jul 2024 04:27:54 -0400 Subject: [PATCH] feat(pockethost): mothership schema dump --- .../MothershipCommand/SchemaCommand/index.ts | 11 +++++ .../MothershipCommand/SchemaCommand/schema.ts | 40 +++++++++++++++++++ .../cli/commands/MothershipCommand/index.ts | 4 +- 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 packages/pockethost/src/cli/commands/MothershipCommand/SchemaCommand/index.ts create mode 100644 packages/pockethost/src/cli/commands/MothershipCommand/SchemaCommand/schema.ts diff --git a/packages/pockethost/src/cli/commands/MothershipCommand/SchemaCommand/index.ts b/packages/pockethost/src/cli/commands/MothershipCommand/SchemaCommand/index.ts new file mode 100644 index 00000000..bee89ce3 --- /dev/null +++ b/packages/pockethost/src/cli/commands/MothershipCommand/SchemaCommand/index.ts @@ -0,0 +1,11 @@ +import { Command } from 'commander' +import { schema } from './schema' + +export const SchemaCommand = () => { + const cmd = new Command(`schema`) + .description(`Create snapshot of the current PocketHost mothership schema`) + .action(async (options) => { + await schema() + }) + return cmd +} diff --git a/packages/pockethost/src/cli/commands/MothershipCommand/SchemaCommand/schema.ts b/packages/pockethost/src/cli/commands/MothershipCommand/SchemaCommand/schema.ts new file mode 100644 index 00000000..465b6888 --- /dev/null +++ b/packages/pockethost/src/cli/commands/MothershipCommand/SchemaCommand/schema.ts @@ -0,0 +1,40 @@ +import { GobotOptions } from 'gobot' +import { + IS_DEV, + LoggerService, + MOTHERSHIP_DATA_ROOT, + MOTHERSHIP_MIGRATIONS_DIR, + MOTHERSHIP_SEMVER, +} from '../../../../../core' +import { GobotService } from '../../../../services/GobotService' + +export async function schema() { + const logger = LoggerService().create(`MothershipSchema`) + const { dbg, error, info, warn } = logger + info(`Starting`) + + const options: Partial = { + version: MOTHERSHIP_SEMVER(), + } + dbg(`gobot options`, options) + const { gobot } = GobotService() + const bot = await gobot(`pocketbase`, options) + + const args = [ + `migrate`, + `collections`, + `--automigrate`, + `0`, + `--hooksDir`, + `foo`, + `--dir`, + MOTHERSHIP_DATA_ROOT(`pb_data`), + `--migrationsDir`, + MOTHERSHIP_MIGRATIONS_DIR(), + ] + if (IS_DEV()) { + args.push(`--dev`) + } + dbg(`args`, args) + bot.run(args) +} diff --git a/packages/pockethost/src/cli/commands/MothershipCommand/index.ts b/packages/pockethost/src/cli/commands/MothershipCommand/index.ts index f80f18ae..4019eff6 100644 --- a/packages/pockethost/src/cli/commands/MothershipCommand/index.ts +++ b/packages/pockethost/src/cli/commands/MothershipCommand/index.ts @@ -1,6 +1,6 @@ import { Command } from 'commander' +import { SchemaCommand } from './SchemaCommand' import { ServeCommand } from './ServeCommand' -import { UpdateCommand } from './UpdateCommand' type Options = { debug: boolean @@ -10,6 +10,6 @@ export const MothershipCommand = () => { const cmd = new Command(`mothership`) .description(`Mothership commands`) .addCommand(ServeCommand()) - .addCommand(UpdateCommand()) + .addCommand(SchemaCommand()) return cmd }