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

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-10-23 10:49:45 +02:00
parent 411021ee04
commit bcfb4f25fb
3 changed files with 19 additions and 9 deletions

View File

@@ -16,7 +16,7 @@ import {
renameTable, renameTable,
runClickhouseMigrationCommands, runClickhouseMigrationCommands,
} from '../src/clickhouse/migration'; } from '../src/clickhouse/migration';
import { getIsSelfHosting, printBoxMessage } from './helpers'; import { getIsCluster, getIsSelfHosting, printBoxMessage } from './helpers';
export async function up() { export async function up() {
const replicatedVersion = '1'; const replicatedVersion = '1';
@@ -31,7 +31,7 @@ export async function up() {
); );
const isSelfHosting = getIsSelfHosting(); const isSelfHosting = getIsSelfHosting();
const isClustered = !isSelfHosting; const isClustered = getIsCluster();
const isSelfHostingPostCluster = const isSelfHostingPostCluster =
existingTables.includes('events_replicated') && isSelfHosting; existingTables.includes('events_replicated') && isSelfHosting;
@@ -58,7 +58,7 @@ export async function up() {
return renameTable({ return renameTable({
from: table, from: table,
to: `${table}_tmp`, to: `${table}_tmp`,
isClustered: false, isClustered,
}); });
}), }),
); );

View File

@@ -16,11 +16,11 @@ export function printBoxMessage(title: string, lines: (string | unknown)[]) {
export function getIsCluster() { export function getIsCluster() {
const args = process.argv; const args = process.argv;
const noClusterArg = args.includes('--no-cluster'); return (
if (noClusterArg) { args.includes('--cluster') ||
return false; process.env.CLICKHOUSE_CLUSTER === 'true' ||
} process.env.CLICKHOUSE_CLUSTER === '1'
return !getIsSelfHosting(); );
} }
export function getIsSelfHosting() { export function getIsSelfHosting() {

View File

@@ -6,7 +6,12 @@ import { fileURLToPath } from 'node:url';
const __filename = fileURLToPath(import.meta.url); const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename); const __dirname = dirname(__filename);
import { db } from '../index'; import { db } from '../index';
import { getIsDry, getIsSelfHosting, printBoxMessage } from './helpers'; import {
getIsCluster,
getIsDry,
getIsSelfHosting,
printBoxMessage,
} from './helpers';
async function migrate() { async function migrate() {
const args = process.argv.slice(2); const args = process.argv.slice(2);
@@ -39,6 +44,11 @@ async function migrate() {
.map((migration) => `\t- ${migration}`), .map((migration) => `\t- ${migration}`),
]); ]);
printBoxMessage('🤝 Config', [
`isClustered: ${getIsCluster()}`,
`isSelfHosting: ${getIsSelfHosting()}`,
]);
printBoxMessage('🌍 Environment', [ printBoxMessage('🌍 Environment', [
`POSTGRES: ${process.env.DATABASE_URL}`, `POSTGRES: ${process.env.DATABASE_URL}`,
`CLICKHOUSE: ${process.env.CLICKHOUSE_URL}`, `CLICKHOUSE: ${process.env.CLICKHOUSE_URL}`,