OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
self-hosting: openpanel reset replaces danger_wipe_everything
Carl-Gerhard Lindesvärdc6b5ec3aa674
diff --git a/self-hosting/cli/src/commands/reset.ts b/self-hosting/cli/src/commands/reset.tsnew file mode 100644index 000000000..afde23d18--- /dev/null+++ b/self-hosting/cli/src/commands/reset.ts@@ -0,0 +1,41 @@+import { basename } from 'node:path';+import { cancel, log as clackLog, isCancel, text } from '@clack/prompts';+import { isInstallDir } from '../install';+import { run } from '../run';+import { bold, red } from '../ui';++export interface ResetFlags {+ dir: string;+ yes: boolean;+}++// Scoped to this install's compose project on purpose. The old script also ran+// host-wide `docker volume prune` / `image prune`, which deletes other projects'+// data; `down --volumes` removes only what this stack created.+export const reset = async ({ dir, yes }: ResetFlags): Promise<number> => {+ if (!isInstallDir(dir)) {+ clackLog.error(`No install in ${dir}.`);+ return 1;+ }++ const confirmation = basename(dir);+ clackLog.warn(+ `${red(bold('This deletes all OpenPanel data in this install'))}: Postgres, ClickHouse, Redis and Redpanda volumes.\nYour docker-compose.yml and .env are kept. Export first if you need the events: openpanel export`+ );+ if (!yes) {+ const typed = await text({ message: `Type "${confirmation}" to continue` });+ if (isCancel(typed) || typed !== confirmation) {+ cancel('Nothing was deleted.');+ return 1;+ }+ }++ const { code } = await run(+ ['docker', 'compose', 'down', '--volumes', '--remove-orphans'],+ { cwd: dir, inherit: true }+ );+ if (code === 0) {+ clackLog.success('Wiped. Start fresh with: openpanel up');+ }+ return code;+};diff --git a/self-hosting/cli/src/main.ts b/self-hosting/cli/src/main.tsindex 7d21932f1..c2beb054d 100644--- a/self-hosting/cli/src/main.ts+++ b/self-hosting/cli/src/main.ts@@ -5,6 +5,7 @@ import { compose, isComposeCommand } from './commands/compose';import { doctor } from './commands/doctor';import { exportData } from './commands/export';import { init } from './commands/init';+import { reset } from './commands/reset';import { upgrade } from './commands/upgrade';import { isInstallDir } from './install';import { log, red } from './ui';@@ -20,6 +21,7 @@ Commands:init Interactive setup (--yes --domain <url> to skip prompts)upgrade [--yes] Update the CLI, repair the install, pull images, restartexport [--out <dir>] Dump ClickHouse data as JSONL (e.g. to move to Cloud)+ reset [--yes] Delete this install's data volumes (asks first)doctor [--fix] [--check] Check the host and your install; --fix repairs itup | down | restart Start, stop, or recreate the stacklogs [service] Follow logs@@ -119,6 +121,9 @@ const main = async (): Promise<number> => {noGzip: values['no-gzip'],});}+ if (command === 'reset') {+ return reset({ dir, yes: values.yes });+ }if (command === 'upgrade') {return upgrade({dir,