DRYCODEWORKS
← Dev guides

Running Langfuse ClickHouse Migrations Manually with up.sh

Daniel Young
Daniel YoungFounder, DRYCodeWorks

Langfuse, the open-source LLM observability platform, keeps its traces in ClickHouse. How to run its migrations yourself with up.sh, and fix one that fails.

Langfuse is an open-source platform for debugging and evaluating applications built on large language models. Your application sends it a trace of each request, with the prompts, model calls and responses, and you search and score the traces in its web app. You can use Langfuse's cloud or host it yourself. A self-hosted Langfuse keeps traces and scores in ClickHouse, and users, projects and settings in Postgres.

A hand-pulled control lever wired to a stack of database layers; one layer in the middle is cracked in half and outlined in orange.

Some Langfuse releases change those ClickHouse tables. Each change ships as a numbered SQL file, called a migration. Every time Langfuse's web container starts (the one that serves its UI and API), it applies the migrations that haven't run yet. It does that with up.sh, a short shell script around golang-migrate, a command-line migration tool. If a migration fails, the container exits, and every later start stops at the same one until someone clears it:

langfuse-web log
error: Dirty database version 48. Fix and force version.

Dirty means migration 48 started and didn't finish. You'd run up.sh yourself to recover from an error like that, or to apply migrations as their own step before a deploy. This guide covers both. The commands use Docker and don't depend on how you run Langfuse itself; Docker Compose, ClickHouse Cloud and Kubernetes each have a short section.

The outputs below come from Langfuse 4.76.0 on ClickHouse 26.3. What I ran lists what I tested and what I didn't.

What runs the migrations

When the web container starts, its entrypoint script applies the Postgres migrations, then runs this:

web/entrypoint.sh (v4.76.0)sh
# Execute the Clickhouse migration, except when disabled.
if [ "$LANGFUSE_AUTO_CLICKHOUSE_MIGRATION_DISABLED" != "true" ]; then
    # Apply Clickhouse migrations
    cd ./packages/shared
    sh ./clickhouse/scripts/up.sh
    status=$?
    cd ../../
fi

If up.sh exits non-zero, the entrypoint prints some likely causes and exits with the same status, so the web server never starts. The worker container doesn't run ClickHouse migrations at all (worker/entrypoint.sh).

Set this variable on the web container to skip that block:

sh
LANGFUSE_AUTO_CLICKHOUSE_MIGRATION_DISABLED=true

Reasons to turn it off and run up.sh as its own step:

  • One runner at a time. golang-migrate's ClickHouse driver locks with a flag in its own process's memory (Lock()), so nothing stops two web containers that start together from running the same migration at once.
  • A failed migration stops the deploy, not the UI. The version already running keeps serving while you fix it. Langfuse issue #15344 describes the alternative: a dirty flag left by a failed upgrade sat unnoticed until an unrelated restart, and then the web service crash-looped.
  • You keep the output. A separate step has its own log and exit code. A web container that keeps restarting buries the first failure under every later attempt.

Run it from the image you deploy

The simplest place to run up.sh is the Langfuse web image itself, because it already has everything the script needs. It ships golang-migrate 4.19.1, built with only the ClickHouse driver (Dockerfile), plus Node and the migration files for that exact release. First, put your ClickHouse settings in a file. This one is for a single ClickHouse server that other containers reach as clickhouse:

langfuse.env
CLICKHOUSE_URL=http://clickhouse:8123
CLICKHOUSE_MIGRATION_URL=clickhouse://clickhouse:9000
CLICKHOUSE_USER=clickhouse
CLICKHOUSE_PASSWORD=clickhouse
CLICKHOUSE_CLUSTER_ENABLED=false

The variables up.sh reads explains each one. Then override the image's entrypoint and run the script from packages/shared, as the entrypoint does:

terminalbash
docker run --rm --entrypoint sh \
  --env-file langfuse.env \
  docker.langfuse.com/langfuse/langfuse:4.76.0 \
  -c 'cd /app/packages/shared && sh clickhouse/scripts/up.sh'

Add --network if ClickHouse runs in another container. Drop the -c and add -it, and the same command gives you a shell with migrate in it, which helps when the web container keeps restarting and you can't open a shell in it. On an empty database, the output is one line per migration:

up.sh
1/u traces (124.820504ms)
2/u observations (255.296512ms)
3/u scores (384.940553ms)
…
54/u add_audit_logs_support_access (1.574047102s)
55/u update_topic_tables (1.594277549s)

Run it again and golang-migrate prints no change and exits 0.

Use the tag you're about to deploy, not a floating one. The version recorded in ClickHouse has to match migration files the web image has: Langfuse's v3 to v4 guide notes that a v3 web container exits on a database that v4 has migrated, with no migration found for version 46. Floating tags have moved under people, too: issue #16923 reports the 3 tag serving a v4 build.

With Docker Compose

Langfuse's docker-compose.yml runs ClickHouse alongside the app. To run migrations as a separate step there, put an override file next to it. It adds a one-shot clickhouse-migrate service, turns off the migrations in langfuse-web, and makes the web container wait until the migration exits 0. It reads the same LANGFUSE_IMAGE_TAG as Langfuse's services, so pin that:

docker-compose.override.ymlyaml
services:
  clickhouse:
    healthcheck:
      # The image's first-boot setup runs a server on 127.0.0.1 only, which
      # passes a localhost check before other containers can connect.
      test: wget --no-verbose --tries=1 --spider "http://$$(hostname):8123/ping" || exit 1

  clickhouse-migrate:
    image: docker.langfuse.com/langfuse/langfuse:${LANGFUSE_IMAGE_TAG:-4}
    entrypoint: ["sh", "-c", "cd /app/packages/shared && sh clickhouse/scripts/up.sh"]
    environment:
      CLICKHOUSE_URL: ${CLICKHOUSE_URL:-http://clickhouse:8123}
      CLICKHOUSE_MIGRATION_URL: ${CLICKHOUSE_MIGRATION_URL:-clickhouse://clickhouse:9000}
      CLICKHOUSE_USER: ${CLICKHOUSE_USER:-clickhouse}
      CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD:-clickhouse}
      CLICKHOUSE_CLUSTER_ENABLED: ${CLICKHOUSE_CLUSTER_ENABLED:-false}
    depends_on:
      clickhouse:
        condition: service_healthy
    restart: "no"

  langfuse-web:
    environment:
      LANGFUSE_AUTO_CLICKHOUSE_MIGRATION_DISABLED: "true"
    depends_on:
      clickhouse-migrate:
        condition: service_completed_successfully

The healthcheck override matters. When CLICKHOUSE_DB is set, as Langfuse's Compose file sets it, the ClickHouse image's entrypoint first starts a temporary server that listens only on 127.0.0.1, creates the database, then restarts. Langfuse's healthcheck pings localhost, so it can pass during that window. My first run, without the override, failed that way:

docker compose up clickhouse-migrate
clickhouse-migrate-1  | error: failed to open database: dial tcp 192.168.228.2:9000: connect: connection refused in line 0: SHOW TABLES FROM "default" LIKE 'schema_migrations'

A check against the container's own hostname passes only once the real server is listening on the network. With the override, docker compose up clickhouse-migrate applied all 55 migrations on three fresh volumes in a row. I ran ClickHouse and the migration service; I didn't start the rest of the stack.

On ClickHouse Cloud

Langfuse's docs recommend ClickHouse Cloud, or ClickHouse's bring-your-own-cloud option (BYOC), for larger deployments. Their example settings use the TLS ports and turn TLS on for the migrations:

langfuse.env
CLICKHOUSE_URL=https://<identifier>.<region>.aws.clickhouse.cloud:8443
CLICKHOUSE_MIGRATION_URL=clickhouse://<identifier>.<region>.aws.clickhouse.cloud:9440
CLICKHOUSE_USER=default
CLICKHOUSE_PASSWORD=changeme
CLICKHOUSE_MIGRATION_SSL=true

They don't set CLICKHOUSE_CLUSTER_ENABLED, so up.sh runs in clustered mode. Azure is the exception. The docs recommend false there, because Cloud on Azure can reject the clustered statements with this error:

Code: 80. DB::Exception: It's not initial query. ON CLUSTER is not allowed for Replicated database. (INCORRECT_QUERY)

If a migration fails with driver: bad connection in line 0, they say to check that CLICKHOUSE_MIGRATION_SSL is set and that the container can reach the service through any IP allowlist or private link. Since v4.88.0, Langfuse can also log in to Cloud with a JWT (CLICKHOUSE_AUTH_MODE=jwt), which makes the user and password optional. I haven't run any of this on ClickHouse Cloud.

On Kubernetes

If you installed Langfuse with its Helm chart, turn the startup migrations off in your values. The chart then sets the skip variable for you (_helpers.tpl):

values.yamlyaml
clickhouse:
  migration:
    autoMigrate: false

Then run the same command, sh -c 'cd /app/packages/shared && sh clickhouse/scripts/up.sh', as a Job or a pre-upgrade hook, using the web image and the same ClickHouse environment as langfuse-web. If your ClickHouse cluster isn't called default, the migrations README shows how to pass its name through the chart's langfuse.additionalEnv. I haven't run this on Kubernetes.

From a source checkout

You can also run up.sh from a clone of langfuse/langfuse. Check out the tag of the image you deploy, not main. You need Node, and golang-migrate on the PATH. The image builds migrate with this command, and you can do the same wherever Go is installed:

terminalbash
go install -trimpath -tags 'clickhouse' github.com/golang-migrate/migrate/v4/cmd/migrate@v4.19.1

Then run the script from packages/shared:

terminalbash
git checkout v4.76.0
cd packages/shared
sh clickhouse/scripts/up.sh

A checkout differs from the image in two ways. It contains only the canonical/ migration templates, so up.sh renders them with Node in every mode (migrations README). And up.sh sources ../../.env, the .env at the repository root, if there is one. It does that after your shell has set its variables, so values in that file win. I didn't run any of this section.

The variables up.sh reads

VariableDefaultWhat up.sh does with it
CLICKHOUSE_MIGRATION_URLrequiredThe start of the migration URL. Native protocol: clickhouse://host:9000, or port 9440 with TLS.
CLICKHOUSE_USERrequiredGoes into the URL's query string.
CLICKHOUSE_PASSWORDrequiredGoes into the query string unencoded.
CLICKHOUSE_MIGRATION_USERunsetSince v4.88.0: replaces CLICKHOUSE_USER for migrations only.
CLICKHOUSE_MIGRATION_PASSWORDunsetSince v4.88.0: replaces CLICKHOUSE_PASSWORD for migrations, when a migration user is set.
CLICKHOUSE_URLrequiredChecked, then never used. It's the HTTP endpoint the app queries.
CLICKHOUSE_DBdefaultThe database to migrate. It must already exist.
CLICKHOUSE_CLUSTER_ENABLEDunset, which means clusteredOnly the exact string false selects unclustered mode.
CLICKHOUSE_CLUSTER_NAMEdefaultThe cluster for ON CLUSTER, in clustered mode only.
CLICKHOUSE_MIGRATION_SSLunsettrue appends secure=true&skip_verify=true: TLS on, certificate verification off.

The script also needs golang-migrate's migrate binary on the PATH, and Node whenever it has to render the migration files (see a cluster that isn't called default). The URL it builds is at the end of the script. This is the v4.76.0 version, before the migration user existed:

packages/shared/clickhouse/scripts/up.sh (v4.76.0)sh
DATABASE_URL="${CLICKHOUSE_MIGRATION_URL}?username=${CLICKHOUSE_USER}&password=${CLICKHOUSE_PASSWORD}&database=${CLICKHOUSE_DB}&x-multi-statement=true"
if [ "$CLICKHOUSE_MIGRATION_SSL" = true ] ; then
  DATABASE_URL="${DATABASE_URL}&secure=true&skip_verify=true"
fi
DATABASE_URL="${DATABASE_URL}${CLICKHOUSE_CLUSTER_QUERY}&x-migrations-table-engine=${MIGRATIONS_TABLE_ENGINE}"

# Execute the up command against delivered or custom-rendered migrations.
migrate -source "file://${MIGRATIONS_DIRECTORY}" -database "$DATABASE_URL" up

Two of those variables cause trouble.

The password goes into a URL. A password containing &, =, #, ?, %, +, @ or a space breaks the query string. I created a user with the password p&ss#1 and ran up.sh with it:

up.sh
error: failed to open database: code: 516, message: pw_user: Authentication failed: password is incorrect, or there is no user with such name

With CLICKHOUSE_PASSWORD='p%26ss%231', the same run applied all 55 migrations. Don't put the encoded form in the environment Langfuse itself reads, though. The app hands CLICKHOUSE_PASSWORD to its ClickHouse client unchanged (client.ts), so it would try to log in with p%26ss%231. Since v4.88.0, the fix is to give the migration its own copy: set CLICKHOUSE_MIGRATION_USER to the same user and CLICKHOUSE_MIGRATION_PASSWORD to the encoded password (up.sh), and leave CLICKHOUSE_PASSWORD as it is. On 4.90.0, that applied all 61 migrations. Before v4.88.0, one variable feeds both, so either use a password without those characters or run up.sh yourself with an encoded copy.

The database has to exist. up.sh doesn't create CLICKHOUSE_DB:

up.sh
error: failed to open database: code: 81, message: Database langfuse does not exist in line 0: SHOW TABLES FROM "langfuse" LIKE 'schema_migrations'

Create it first, with ON CLUSTER in clustered mode.

Clustered or unclustered

ClickHouse can run as one server or as a cluster of several. In clustered mode, Langfuse's statements that create or change a table say ON CLUSTER, so every server in the cluster runs them, and ClickHouse Keeper coordinates the servers. Langfuse ships its migrations in both forms. Its Compose file runs one ClickHouse server and already sets CLICKHOUSE_CLUSTER_ENABLED to false.

up.sh assumes a cluster unless told otherwise. Only CLICKHOUSE_CLUSTER_ENABLED=false selects unclustered mode; unset, 0, no and FALSE all mean clustered. In the web image, two checks decide which migration files run:

Files it runsCLICKHOUSE_CLUSTER_ENABLEDexactly “false”?yesunclustered/CLICKHOUSE_CLUSTER_NAMEunset or “default”?yesclustered/nonocanonical/your name filled in

The two modes differ in more than ON CLUSTER:

UnclusteredClustered
DDLPlainON CLUSTER <name>
Langfuse tablesMergeTree enginesReplicated engines for most tables
schema_migrationsMergeTreeReplicatedMergeTree, created ON CLUSTER
ClickHouse needsOne serverKeeper or ZooKeeper, the cluster in remote_servers, and shard and replica macros

On a single server without Keeper, the default fails before any migration runs, while creating golang-migrate's version table:

up.sh
error: failed to open database: code: 139, message: There is no Zookeeper configuration in server config in line 0: 
			CREATE TABLE schema_migrations ON CLUSTER default (
				version    Int64,
				dirty      UInt8,
				sequence   UInt64
			) Engine=ReplicatedMergeTree ORDER BY sequence

That one is harmless. Nothing was created, so set CLICKHOUSE_CLUSTER_ENABLED=false and run it again. Choose the mode once, though. The modes create the same tables with different engines, and up.sh has no path from one to the other. Moving a running deployment from one server to a cluster means copying the data to a new instance, which Langfuse's docs cover separately.

A cluster that isn't called default

Since v4.28.1 (#17015), up.sh handles any cluster name. When CLICKHOUSE_CLUSTER_NAME is something other than default, it calls Node to render the canonical/ templates into a temporary directory with the name quoted, and passes the quoted, URL-encoded name to golang-migrate. Here's that run against a single ClickHouse server with Keeper built in and a cluster called analytics, traced with sh -x and the password masked:

sh -x up.sh
+ MIGRATIONS_DIRECTORY=/tmp/langfuse-clickhouse-clustered-migrations-ZAzKFW
+ migrate -source file:///tmp/langfuse-clickhouse-clustered-migrations-ZAzKFW -database 'clickhouse://clickhouse:9000?username=clickhouse&password=***&database=langfuse&x-multi-statement=true&x-cluster-name=%27analytics%27&x-migrations-table-engine=ReplicatedMergeTree' up
+ rm -rf -- /tmp/langfuse-clickhouse-clustered-migrations-ZAzKFW

All 55 migrations applied, each statement with the cluster clause filled in. Migration 37, for example, has six statements. Its first two render as:

0037_add_created_at_indexes.up.sqlsql
ALTER TABLE observations ON CLUSTER 'analytics' ADD INDEX IF NOT EXISTS idx_created_at created_at TYPE minmax GRANULARITY 1 SETTINGS alter_sync = 2;
ALTER TABLE observations ON CLUSTER 'analytics' MATERIALIZE INDEX IF EXISTS idx_created_at;

As of December 2026, Langfuse's ClickHouse page still says, for a cluster name other than default:

In that case, the database migrations will not apply correctly as they cannot run dynamically for different clusters.

Langfuse docs: ClickHouse (self-hosted)

It goes on to tell you to turn off automatic migrations, clone the repository, change the cluster name in each file under migrations/clustered/, and run up.sh by hand. That describes v3. In v3.227.0's up.sh, the cluster name goes to golang-migrate as it is, while all 140 ON CLUSTER clauses in the shipped clustered/ files name default. On v3, editing the files is still the way. I read the v3 script and files but didn't run them.

The grants Langfuse's docs leave out

If up.sh runs as a restricted user rather than an admin, its grants matter. Langfuse's ClickHouse page lists the ones to "Apply schema migrations on startup". I created a user with exactly the page's table and system-table grants, on a database of its own, and up.sh on v4.76.0 stopped at migration 48:

up.sh
47/u add_eval_execution_columns (1.617165631s)
error: migration failed in line 0: -- Lightweight updates (patch parts) require the persisted _block_number and _block_offset columns, as already set on events_full and events_core. Metadata-only: existing parts are not rewritten.
ALTER TABLE scores
  MODIFY SETTING enable_block_number_column = 1, enable_block_offset_column = 1; (details: code: 497, message: lf_docs_user: Not enough privileges. To execute this query, it's necessary to have the grant ALTER SETTINGS ON lf_docs.scores)

The page grants ALTER SETTINGS only on the backfill's scratch table. With it granted on the whole database, the run went on to stop at migration 50, which needs ALTER MATERIALIZE COLUMN. With both added, all 55 migrations applied:

sql
GRANT ALTER SETTINGS, ALTER MATERIALIZE COLUMN ON default.* TO 'user';

Migration 48 shipped in v4.29.0, and the MATERIALIZE COLUMN statement in migration 50 arrived in v4.73.0. That was on one server in unclustered mode. In clustered mode, the docs' CLUSTER and READ ON REMOTE grants apply as well; I ran clustered mode only as an admin user.

Both failures left a dirty version, which the next section covers.

When a migration fails: the dirty version

golang-migrate keeps its state in a ClickHouse table, schema_migrations, with three columns: version, dirty and sequence. Before it runs migration N, it inserts the row (N, dirty=1). When the migration succeeds, it inserts (N, dirty=0). The newest row by sequence is the current state (migrate.go). After a clean run:

clickhouse-client
SELECT version, dirty, sequence FROM schema_migrations ORDER BY sequence DESC LIMIT 4

   ┌─version─┬─dirty─┬────────────sequence─┐
1. │      55 │     0 │ 1796151797604952949 │
2. │      55 │     1 │ 1796151797520019377 │
3. │      54 │     0 │ 1796151797465526665 │
4. │      54 │     1 │ 1796151797395611584 │
   └─────────┴───────┴─────────────────────┘

When migration N fails, the clean row is never written, and every later run stops at the first check, before it touches anything:

up.sh
error: Dirty database version 48. Fix and force version.

The hard part is x-multi-statement=true. With it, golang-migrate splits each file on ; and sends the statements one at a time (Run()). The driver's README is plain about what that means:

The queries are not executed in any sort of transaction/batch, meaning you are responsible for fixing partial migrations.

golang-migrate ClickHouse driver README

So a failed migration may have applied some of its statements and not others, and dirty=1 doesn't say which. Langfuse's FAQ gets the order right:

After determining the actual state, force your database to the version that accurately reflects its current state.

Langfuse FAQ: ClickHouse handling failed migrations

Recovering, step by step

  1. Read the state. migrate version prints 48 (dirty); the schema_migrations query above shows the same.
  2. Find what ran. Open migration N's .up.sql, in the image under /app/packages/shared/clickhouse/migrations/unclustered/ or clustered/. The error names the statement that failed, and every statement before it ran. Check those against system.columns, system.data_skipping_indices and SHOW CREATE TABLE.
  3. Fix the cause: the grant, the disk, the Keeper connection.
  4. Force a version: N-1 or N, from the table below.
  5. Run up.sh again.
What migration N left behindForceThen
Nothing: its first statement failedN-1Run up.sh. N runs from the top.
Some statements, all safe to repeatN-1Run up.sh. The repeats change nothing.
Some statements that aren't safe to repeatN-1 after undoing them, or N after running the rest by handRun up.sh.
Every statementNRun up.sh for the migrations after it.

Forcing N skips N

golang-migrate takes your word that the forced version is done. In the example below, migration 48 fails on its first statement. I forced 48 instead of 47, without fixing the cause, and up.sh ran 49 and stopped at 50 for a different missing grant. The scores table never got 48's setting, and no message said so.

Whether a statement is safe to repeat decides which row applies. Statements with IF NOT EXISTS or IF EXISTS, and MODIFY SETTING, repeat cleanly. Many of Langfuse's older migrations don't. Migration 8 adds a column three times without IF NOT EXISTS:

0008_add_environments_column.up.sqlsql
ALTER TABLE traces ADD COLUMN environment LowCardinality(String) DEFAULT 'default' AFTER project_id;
ALTER TABLE observations ADD COLUMN environment LowCardinality(String) DEFAULT 'default' AFTER project_id;
ALTER TABLE scores ADD COLUMN environment LowCardinality(String) DEFAULT 'default' AFTER project_id;

If it had failed on observations, forcing 7 would send the traces statement again, and ClickHouse would reject it. I sent that statement a second time by hand to see the error:

clickhouse-client
Code: 15. DB::Exception: Received from localhost:9000. DB::Exception: Cannot add column `environment`: column with this name already exists. (DUPLICATE_COLUMN)

Then you either undo what ran and force N-1, or finish the rest by hand and force N. Every migration has a .down.sql beside it. Read it before you use it to undo a partial run: it reverses the whole migration, and dropping a column drops whatever was written to it.

Force with the URL up.sh uses

version and force need the URL up.sh builds, or at least the same database. golang-migrate creates schema_migrations when it doesn't find one (ensureVersionTable()), and with no database in the URL, it uses the user's default database. I left database= out to check: force 47 exited 0, created a new schema_migrations in default and wrote its version there, and the real table didn't change. In the web image, from /app/packages/shared:

sh
URL="${CLICKHOUSE_MIGRATION_URL}?username=${CLICKHOUSE_USER}&password=${CLICKHOUSE_PASSWORD}&database=${CLICKHOUSE_DB:-default}&x-multi-statement=true&x-migrations-table-engine=MergeTree"
migrate -path clickhouse/migrations/unclustered -database "$URL" version

For clustered mode, change the engine and add the cluster name, as Langfuse's rollback instructions do:

sh
URL="${CLICKHOUSE_MIGRATION_URL}?username=${CLICKHOUSE_USER}&password=${CLICKHOUSE_PASSWORD}&database=${CLICKHOUSE_DB:-default}&x-multi-statement=true&x-cluster-name=${CLICKHOUSE_CLUSTER_NAME:-default}&x-migrations-table-engine=ReplicatedMergeTree"
migrate -path clickhouse/migrations/clustered -database "$URL" version

Append &secure=true&skip_verify=true if you set CLICKHOUSE_MIGRATION_SSL=true.

Use these URLs for version and force only, and let up.sh apply migrations. The files shipped in clustered/ say ON CLUSTER default, so with a custom cluster name, any migrate command that runs them sends the wrong cluster. Only up.sh renders your name into them.

The example: migrations 48 and 50

Migration 48 failed on its first statement, and the scores table's settings didn't include enable_block_number_column: nothing had applied. That's the first row of the table. I granted ALTER SETTINGS, then forced 47 and ran up.sh again with the unclustered URL from above:

sh
migrate -path clickhouse/migrations/unclustered -database "$URL" force 47
sh clickhouse/scripts/up.sh
up.sh
48/u enable_block_columns_on_scores_and_dataset_run_items (74.04917ms)
49/u add_events_name_ngram_indexes (231.601952ms)
error: migration failed in line 0: 
ALTER TABLE scores MATERIALIZE COLUMN session_id, MATERIALIZE COLUMN dataset_run_id, MATERIALIZE INDEX idx_project_trace_observation_v2 SETTINGS mutations_sync = 2; (details: code: 497, message: lf_docs_user: Not enough privileges. To execute this query, it's necessary to have the grant ALTER MATERIALIZE COLUMN ON lf_docs.scores)

Migration 50 had already run partway. It has five statements, and the error came from the third, so the first two had run. system.data_skipping_indices listed the new index, idx_project_trace_observation_v2, and both columns still carried the temporary default that the second statement sets:

clickhouse-client
SELECT name, type, default_kind, default_expression
FROM system.columns
WHERE table = 'scores' AND name IN ('session_id', 'dataset_run_id')

   ┌─name───────────┬─type─────────────┬─default_kind─┬─default_expression─┐
1. │ session_id     │ Nullable(String) │ DEFAULT      │ NULL               │
2. │ dataset_run_id │ Nullable(String) │ DEFAULT      │ NULL               │
   └────────────────┴──────────────────┴──────────────┴────────────────────┘

Both statements are safe to repeat. The first is ADD INDEX IF NOT EXISTS, and the second sets the same type and default again. That makes it the second row of the table: force 49, not 50, and undo nothing. After granting ALTER MATERIALIZE COLUMN:

up.sh
50/u scores_trace_index_granularity (97.533663ms)
51/u add_topics (227.099503ms)
52/u create_audit_logs (356.962179ms)
53/u add_skill_observation_references (495.945459ms)
54/u add_audit_logs_support_access (610.588739ms)
55/u update_topic_tables (747.216544ms)

schema_migrations ended at version 55, clean. The temporary defaults were gone and the old index had been dropped, as the last two statements of migration 50 do.

A missing grant isn't the only thing that has stopped migration 50. If your error is different, compare it with #19394 (older data on ClickHouse 26.4) and #21013 (ClickHouse Cloud 26.6). Langfuse's fixes for them shipped in v4.73.0 and v4.89.0.

A clean version doesn't mean ClickHouse has finished. Some Langfuse migrations start background mutations without waiting for them: the unclustered MATERIALIZE INDEX in migration 37 is one. golang-migrate records the version as soon as ClickHouse accepts the statement. Before you call the run done, check SELECT database, table, mutation_id, latest_fail_reason FROM system.mutations WHERE NOT is_done. Why that matters is in ClickHouse migrations that wait for mutations.

What I ran

The outputs in this guide come from the Langfuse web image 4.76.0 (sha256:59abb54f…) against ClickHouse 26.3.62.3: a single server for unclustered mode, and a single node with embedded ClickHouse Keeper for clustered mode. The failures and the recoveries are real. I didn't run the Kubernetes or source-checkout steps, and nothing here ran on ClickHouse Cloud, a multi-node cluster or a v3 image. Where the guide covers those, it says so and links the source. On 2026-12-01 I reran two tests on 4.90.0, also on one server in unclustered mode: the grants test stopped at the same two migrations, and the password that failed on 4.76.0 failed the same way. 4.90.0 has 61 migrations.

Make it a deploy step

Running up.sh yourself adds one step to a deploy. In return, the migrations run once, from the image you're about to ship, and a failure stops the rollout instead of taking down the UI. For ClickHouse schemas of your own, the same thinking is behind ch-migrate, the migration tool I build in the open. And if you're running Langfuse on your own ClickHouse cluster and want a hand with the migration path, get in touch.