feat(pockethost): mothership schema dump

This commit is contained in:
Ben Allfree 2024-07-31 04:27:54 -04:00
parent 21c663fe73
commit d6e700bdd1
3 changed files with 53 additions and 2 deletions

View File

@ -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
}

View File

@ -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<GobotOptions> = {
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)
}

View File

@ -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
}