import { i18n } from '../i18n' import { sdk } from '../sdk' import { dataDir, pgDataDir } from '../utils' export const resetDbState = sdk.Action.withoutInput( // id 'reset-db-state', // metadata async ({ effects }) => ({ name: i18n('Reset Database State'), description: i18n( 'Wipe /data/postgres so PostgreSQL re-initializes from scratch.', ), warning: i18n( 'This deletes all PostgreSQL data on disk. The next start will re-create an empty database. store.json (passwords + RPC credentials) is preserved.', ), allowedStatuses: 'any', group: null, visibility: 'enabled', }), // run async ({ effects }) => { const res = await sdk.SubContainer.withTemp( effects, { imageId: 'spaces' }, sdk.Mounts.of().mountVolume({ volumeId: 'main', subpath: null, mountpoint: dataDir, readonly: false, }), 'spaces-reset-db', (subc) => subc.exec(['rm', '-rf', pgDataDir], { user: 'root' }), ) if (res.exitCode !== 0) { return { version: '1', title: i18n('Failure'), message: i18n('Could not wipe PostgreSQL state: ${error}', { error: (res.stderr ?? '').toString() || `exit ${res.exitCode}`, }), result: null, } } return { version: '1', title: i18n('Success'), message: i18n( 'PostgreSQL data has been wiped. Start (or restart) the service to re-initialize the database.', ), result: null, } }, )