Clickhouse handling failed migrations in self-hosted Langfuse
If you encounter a migration error, the migration tool will prevent you from running additional migrations on the same database. You’ll see an error message like “Dirty database version 1. Fix and force version” even after fixing the erred migration. This means your database has been marked as ‘dirty’. You need to investigate whether the migration was partially applied or not applied at all. After determining the actual state, force your database to the version that accurately reflects its current state. Once you’ve forced the correct version and fixed the migration, your database will be ‘clean’ again, allowing you to proceed with subsequent migrations.
Code Example to fix failed migrations
Let’s assume your migration 16 failed. You have corrected the failed migration. If you try to migrate again, migrate will STILL refuse:
error: Dirty database version 16. Fix and force version.
You will have to force your database to the last successful version, which is 15. Make sure to replace the database credentials with your own. Before running the command below, make sure you have golang-migrate installed. If you do not, please follow the guide linked in our contributing guide. Then, navigate to the root of your Langfuse project folder in your terminal. Then run the following command:
migrate -path migrations/ -database clickhouse://test:test@localhost:8123/dummy force 15
If you migrate again, the output will now be:
16/u migration_name (12.718637ms)