mirror of
https://github.com/pockethost/pockethost.git
synced 2026-03-06 00:58:49 +00:00
refactor: migration code
This commit is contained in:
@@ -9,8 +9,9 @@ import {
|
||||
import { backupInstance } from '../util/backupInstance'
|
||||
import { error } from '../util/dbg'
|
||||
import { safeCatch } from '../util/safeAsync'
|
||||
import { applyDbMigrations } from './applyDbMigrations'
|
||||
import { pexec } from './pexec'
|
||||
import { schema } from './schema'
|
||||
import { withInstance } from './withInstance'
|
||||
|
||||
const PB_BIN = resolve(DAEMON_PB_BIN_DIR, binFor('lollipop'))
|
||||
|
||||
@@ -26,7 +27,9 @@ safeCatch(`root`, async () => {
|
||||
console.log(`Upgrading`)
|
||||
await pexec(`${PB_BIN} upgrade --dir=pb_data`)
|
||||
|
||||
await applyDbMigrations(async (client) => {
|
||||
await withInstance(async (client) => {
|
||||
await client.applySchema(schema)
|
||||
|
||||
await client.updateInstances((instance) => {
|
||||
const src = resolve(DAEMON_PB_DATA_DIR, instance.subdomain)
|
||||
const dst = resolve(DAEMON_PB_DATA_DIR, instance.id)
|
||||
|
||||
@@ -12,10 +12,9 @@ import { mkInternalUrl } from '../util/internal'
|
||||
import { safeCatch } from '../util/safeAsync'
|
||||
import { spawnInstance } from '../util/spawnInstance'
|
||||
import { tryFetch } from '../util/tryFetch'
|
||||
import { schema } from './schema'
|
||||
|
||||
export const applyDbMigrations = safeCatch(
|
||||
`applyDbMigrations`,
|
||||
export const withInstance = safeCatch(
|
||||
`withInstance`,
|
||||
async (cb: (client: PocketbaseClientApi) => Promise<void>) => {
|
||||
// Add `platform` and `bin` required columns (migrate db json)
|
||||
try {
|
||||
@@ -30,7 +29,6 @@ export const applyDbMigrations = safeCatch(
|
||||
const client = createPbClient(coreInternalUrl)
|
||||
await tryFetch(coreInternalUrl)
|
||||
await client.adminAuthViaEmail(DAEMON_PB_USERNAME, DAEMON_PB_PASSWORD)
|
||||
await client.applySchema(schema)
|
||||
await cb(client)
|
||||
} catch (e) {
|
||||
console.error(
|
||||
Reference in New Issue
Block a user