Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix: option to allow cluster migrations without relying on self hosting env

Carl-Gerhard Lindesvärdbcfb4f25fbfc
diff --git a/packages/db/code-migrations/3-init-ch.ts b/packages/db/code-migrations/3-init-ch.ts
index 040c039f3..56fa0f3ea 100644
--- a/packages/db/code-migrations/3-init-ch.ts
+++ b/packages/db/code-migrations/3-init-ch.ts
@@ -16,7 +16,7 @@ import {
renameTable,
runClickhouseMigrationCommands,
} from '../src/clickhouse/migration';
-import { getIsSelfHosting, printBoxMessage } from './helpers';
+import { getIsCluster, getIsSelfHosting, printBoxMessage } from './helpers';
export async function up() {
const replicatedVersion = '1';
@@ -31,7 +31,7 @@ export async function up() {
);
const isSelfHosting = getIsSelfHosting();
- const isClustered = !isSelfHosting;
+ const isClustered = getIsCluster();
const isSelfHostingPostCluster =
existingTables.includes('events_replicated') && isSelfHosting;
@@ -58,7 +58,7 @@ export async function up() {
return renameTable({
from: table,
to: `${table}_tmp`,
- isClustered: false,
+ isClustered,
});
}),
);
diff --git a/packages/db/code-migrations/helpers.ts b/packages/db/code-migrations/helpers.ts
index 1c0953659..128a3eade 100644
--- a/packages/db/code-migrations/helpers.ts
+++ b/packages/db/code-migrations/helpers.ts
@@ -16,11 +16,11 @@ export function printBoxMessage(title: string, lines: (string | unknown)[]) {
export function getIsCluster() {
const args = process.argv;
- const noClusterArg = args.includes('--no-cluster');
- if (noClusterArg) {
- return false;
- }
- return !getIsSelfHosting();
+ return (
+ args.includes('--cluster') ||
+ process.env.CLICKHOUSE_CLUSTER === 'true' ||
+ process.env.CLICKHOUSE_CLUSTER === '1'
+ );
}
export function getIsSelfHosting() {
diff --git a/packages/db/code-migrations/migrate.ts b/packages/db/code-migrations/migrate.ts
index 139f9554a..5f3a0e653 100644
--- a/packages/db/code-migrations/migrate.ts
+++ b/packages/db/code-migrations/migrate.ts
@@ -6,7 +6,12 @@ import { fileURLToPath } from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
import { db } from '../index';
-import { getIsDry, getIsSelfHosting, printBoxMessage } from './helpers';
+import {
+ getIsCluster,
+ getIsDry,
+ getIsSelfHosting,
+ printBoxMessage,
+} from './helpers';
async function migrate() {
const args = process.argv.slice(2);
@@ -39,6 +44,11 @@ async function migrate() {
.map((migration) => `\t- ${migration}`),
]);
+ printBoxMessage('🤝 Config', [
+ `isClustered: ${getIsCluster()}`,
+ `isSelfHosting: ${getIsSelfHosting()}`,
+ ]);
+
printBoxMessage('🌍 Environment', [
`POSTGRES: ${process.env.DATABASE_URL}`,
`CLICKHOUSE: ${process.env.CLICKHOUSE_URL}`,