Skip to content

Commit c34afeb

Browse files
committed
fix: ClickHouse URL secure parameter handling in goose migrations and replication clients
1 parent d343727 commit c34afeb

3 files changed

Lines changed: 18 additions & 13 deletions

File tree

apps/webapp/app/routes/admin.api.v1.runs-replication.create.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ export async function action({ request }: ActionFunctionArgs) {
5757
}
5858

5959
function createRunReplicationService(params: CreateRunReplicationServiceParams) {
60+
const url = new URL(env.RUN_REPLICATION_CLICKHOUSE_URL);
61+
62+
// Remove secure param
63+
url.searchParams.delete("secure");
64+
6065
const clickhouse = new ClickHouse({
61-
url: env.RUN_REPLICATION_CLICKHOUSE_URL,
66+
url: url.toString(),
6267
name: params.name,
6368
keepAlive: {
6469
enabled: params.keepAliveEnabled,

apps/webapp/app/services/runsReplicationInstance.server.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ function initializeRunsReplicationInstance() {
2222

2323
console.log("🗃️ Runs replication service enabled");
2424

25+
const url = new URL(env.RUN_REPLICATION_CLICKHOUSE_URL);
26+
27+
// Remove secure param
28+
url.searchParams.delete("secure");
29+
2530
const clickhouse = new ClickHouse({
26-
url: env.RUN_REPLICATION_CLICKHOUSE_URL,
31+
url: url.toString(),
2732
name: "runs-replication",
2833
keepAlive: {
2934
enabled: env.RUN_REPLICATION_KEEP_ALIVE_ENABLED === "1",

docker/scripts/entrypoint.sh

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,12 @@ if [ -n "$CLICKHOUSE_URL" ] && [ "$SKIP_CLICKHOUSE_MIGRATIONS" != "1" ]; then
1818
echo "Running ClickHouse migrations..."
1919
export GOOSE_DRIVER=clickhouse
2020

21-
# Ensure secure=true is in the connection string
22-
if echo "$CLICKHOUSE_URL" | grep -q "secure="; then
23-
# secure parameter already exists, use as is
24-
export GOOSE_DBSTRING="$CLICKHOUSE_URL"
25-
elif echo "$CLICKHOUSE_URL" | grep -q "?"; then
26-
# URL has query parameters, append secure=true
27-
export GOOSE_DBSTRING="${CLICKHOUSE_URL}&secure=true"
28-
else
29-
# URL has no query parameters, add secure=true
30-
export GOOSE_DBSTRING="${CLICKHOUSE_URL}?secure=true"
31-
fi
21+
# Strip secure parameter from URL before passing to goose
22+
# The scheme (http:// vs https://) already encodes TLS choice, so secure param is redundant
23+
export GOOSE_DBSTRING="$(echo "$CLICKHOUSE_URL" | sed 's/[?&]secure=[^&]*//g')"
24+
25+
# Remove trailing ? or & if present after stripping secure param
26+
export GOOSE_DBSTRING="$(echo "$GOOSE_DBSTRING" | sed 's/[?&]$//')"
3227

3328
export GOOSE_MIGRATION_DIR=/triggerdotdev/internal-packages/clickhouse/schema
3429
/usr/local/bin/goose up

0 commit comments

Comments
 (0)