Upgrade umami v1 to v2

How I upgraded umami docker compose from v1 to v2.

Upgrade umami v1 to v2

I am using a self-hosted analytics tool called umami. It is easy to understand, unlike Google Analytics which needs a degree to get the basics and it's on my server. So no headaches regarding GDPR and stuff.

I am running this with docker compose and sometimes the upgrade process is, let's say, a bit tricky. Therefore I waited for the big v2.x update.

Today I figured let's see what this v2.x is all about. Checking Github Issues and Discussions I saw nothing problematic, so let's do it.

I also found some docs regarding the migration from v1 to v2:

Migrating v1 to v2 | umami

Upgrading umami

I am currently running these tags:

  • ghcr.io/umami-software/umami:postgresql-v1.40.0
  • postgres:12.14-alpine

First I checked which version of PostgreSQL is supported and I am in luck, v12.14 is the minium version. Found that

Installation | umami

Create a backup

First things first: Always create a backup!

docker exec -it blog_umami-db_1 pg_dumpall -U umami > umami-All.dump


The migration needs to be run in the OLD version of the container. So in my case v1.40.0 which already was running. I found that weird, but here we go:

docker exec -it -u 0 blog_umami_1 sh

npx @umami/migrate-v1-v2@latest
Migration command

Migration output:

Need to install the following packages:
  @umami/[email protected]
Ok to proceed? (y) y
Running v0.15.0
βœ“ DATABASE_URL is defined.
βœ“ Database connection successful.
Preparing v1 tables for migration
βœ“ Dropped v1 database keys.
βœ“ Dropped v1 database indexes.
βœ“ Renamed v1 database tables.
βœ“ Database v1 tables ready for migration.
Database v2 tables not found.
Adding v2 tables...
βœ“ Ran sql file /db/postgresql/migrations/01_init/migration.sql.
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "umami", schema "public" at "umami-db"
Migration 01_init marked as applied.

βœ“ Database is ready for migration.
βœ“ Starting v2 data migration. Please do no cancel this process, it may take a while.
βœ“ Ran sql file /db/postgresql/data-migration-v2.sql.
βœ“ Data migration from V1 to V2 tables completed.
βœ” Do you want to delete V1 database tables? (Y/N) … Y
βœ“ Dropped v1 database tables.
βœ“ Migration successfully completed.
npm notice
npm notice New major version of npm available! 8.19.3 -> 9.8.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.8.1
npm notice Run npm install -g [email protected] to update!
npm notice
MIgration output


After the migration was successful I just had to update my docker image tag to the latest stable one: postgresql-v2.5.0

That was it!

Updating postgres

My current PostgreSQL container was running with the tag postgres:12.14-alpine. So I updated to the latest patch release of the version 12 which is 12.16 as of writing this.

Then I tried to update the container to the version 13.12 but that did not work. The container kept restarting. After some Google Foo, I discovered that PostgreSQL will not do the migration for you. It will actually refuse to start when there is an older database version in the database location.

You actually need to create a database dump. Start a fresh and empty PostgreSQL container and then import that dump into the new instance.

Personally, I would prefer to do the migration at startup, but hey, you can not get it all. I know it could be possible with pg_upgrade.

Here are some more info regarding this:

Since I am still in the minimum requirement for umami I will do this another time. Too lazy right now. πŸ˜‰