From bcfb4f25fbfce822972c153d7a899deb82ad5eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Thu, 23 Oct 2025 10:49:45 +0200 Subject: [PATCH] fix: option to allow cluster migrations without relying on self hosting env --- packages/db/code-migrations/3-init-ch.ts | 6 +++--- packages/db/code-migrations/helpers.ts | 10 +++++----- packages/db/code-migrations/migrate.ts | 12 +++++++++++- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/db/code-migrations/3-init-ch.ts b/packages/db/code-migrations/3-init-ch.ts index 040c039f..56fa0f3e 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 1c095365..128a3ead 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 139f9554..5f3a0e65 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}`,