umami: v1 to v2 migration fails on Postgres

I am running the latest v1 Umami with Postgres and wanted to update to v2.

The umami directory is /tmp/t/app.

On the first try, I got this error:

$ yarn add @umami/migrate-v1-v2
$ npx @umami/migrate-v1-v2
✓ DATABASE_URL is defined.
✓ Database connection successful.
Preparing v1 tables for migration
✓ Dropped v1 database keys.
PrismaClientKnownRequestError: 
Invalid `prisma.$executeRaw()` invocation:


Raw query failed. Code: `2BP01`. Message: `db error: ERROR: cannot drop index website_share_id_key because constraint website_share_id_key on table website requires it
HINT: You can drop constraint website_share_id_key on table website instead.`
    at fn.handleRequestError (/tmp/t/app/node_modules/@prisma/client/runtime/library.js:174:6477)
    at fn.handleAndLogRequestError (/tmp/t/app/node_modules/@prisma/client/runtime/library.js:174:5907)
    at fn.request (/tmp/t/app/node_modules/@prisma/client/runtime/library.js:174:5786)
    at async Proxy._request (/tmp/t/app/node_modules/@prisma/client/runtime/library.js:177:10477) {
  code: 'P2010',
  clientVersion: '4.12.0',
  meta: {
    code: '2BP01',
    message: 'db error: ERROR: cannot drop index website_share_id_key because constraint website_share_id_key on table website requires it\n' +
      'HINT: You can drop constraint website_share_id_key on table website instead.'
  }
}
✗ Failed to drop v1 database indexes.

After dropping the mentioned constraint manually, it now fails to find some migration sql scripts:

$ npx @umami/migrate-v1-v2
✓ 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...
[Error: ENOENT: no such file or directory, open '/tmp/t/app/node_modules/@umami/migrate-v1-v2/prisma/migrations/01_init/migration.sql'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/tmp/t/app/node_modules/@umami/migrate-v1-v2/prisma/migrations/01_init/migration.sql'
}
✗ Failed to run sql file /prisma/migrations/01_init/migration.sql.

Did I miss something?

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 18 (2 by maintainers)

Most upvoted comments

Copying manually worked fine, thank you. But unfortunately there is another error: Raw query failed. Code: 42601. Message: db error: ERROR: syntax error at or near "version"

Fix: PR #1908

The npx version of the migration skips the build step (which you run as part of the standalone migration), which moves db/postgresql/ or db/mysql/ to prisma/. That’s why it’s looking in the wrong place. You can do it manually before running the migration:

$ yarn add @umami/migrate-v1-v2
$ cp -r node_modules/@umami/migrate-v1-v2/db/postgresql node_modules/@umami/migrate-v1-v2/prisma
$ npx @umami/migrate-v1-v2

I also have similar problems, but I tried to solve them but failed. Does anyone have any ideas?

  • Node:v16.16.0
  • postgres:supabase
  • Vercel

My folder: image

 yarn start
yarn run v1.22.15
$ node index.js
Running v0.15.0
✓ DATABASE_URL is defined.
✓ Database connection successful.
Preparing v1 tables for migration
✓ Dropped v1 database keys.
✓ Dropped v1 database indexes.
PrismaClientKnownRequestError:
Invalid `prisma.$executeRaw()` invocation:


Server has closed the connection.
    at Zr.handleRequestError (D:\Github\migrate-v1-v2\node_modules\@prisma\client\runtime\library.js:171:6414)
    at Zr.handleAndLogRequestError (D:\Github\migrate-v1-v2\node_modules\@prisma\client\runtime\library.js:171:5948)
    at Zr.request (D:\Github\migrate-v1-v2\node_modules\@prisma\client\runtime\library.js:171:5786)
    at async Proxy._request (D:\Github\migrate-v1-v2\node_modules\@prisma\client\runtime\library.js:174:10455) {
  code: 'P1017',
  clientVersion: '4.11.0',
  meta: null
}
✗ Failed to rename v1 database tables.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@dyxang Restart your supabase.

This is what my prisma folder looks like: Screenshot 2023-04-20 at 11 27 32

I ran this:

$ yarn build-db
yarn run v1.22.19
$ npm-run-all copy-db-files build-db-client
$ node scripts/copy-db-files.js
Database type detected: postgresql
Copied /<path>/umami/db/postgresql to /<path>/umami/prisma
$ prisma generate
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma

✔ Generated Prisma Client (4.13.0 | library) to ./node_modules/@prisma/client in 539ms
You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client
'```
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
'```
✨  Done in 5.70s.

Afterwards I ran this:

$ npx prisma migrate resolve --applied 01_init
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "<db>", schema "public" at "<host>"
Migration 01_init marked as applied.

That looked really good and thus I tried another deploy to Heroku. Relevant build log entry:

-----> Build
       Running build (yarn)
       yarn run v1.22.19
       $ npm-run-all build-db check-db build-tracker build-geo build-app
       $ npm-run-all copy-db-files build-db-client
       $ node scripts/copy-db-files.js
       Database type detected: postgresql
       Copied /tmp/build_e89798e9/db/postgresql to /tmp/build_e89798e9/prisma
       $ prisma generate
       Prisma schema loaded from prisma/schema.prisma
       
       ✔ Generated Prisma Client (4.13.0 | library) to ./node_modules/@prisma/client in 160ms
       You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client
       ```
       import { PrismaClient } from '@prisma/client'
       const prisma = new PrismaClient()
       ```
       $ node scripts/check-db.js
       ✓ DATABASE_URL is defined.
       ✓ Database connection successful.
       ✓ Database version check successful.
       Prisma schema loaded from prisma/schema.prisma
       Datasource "db": PostgreSQL database "<db>", schema "public" at "<host>"
       
       1 migration found in prisma/migrations
     
       No pending migrations to apply.

       ✓ Database is up to date.

The deploy succeeded. I now have a working Umami install. Without any historic data, but it is running.

Update: I updated the tracking snippet code and now everything (tracking, backend, etc.) appears to work as expected. For me this issue is now closed. I hope these steps help others to get their v2 up and running.

Same error here. I was able to fix it by correcting the paths listed in line 89 & 106 of /node_modules/@umami/migrate-v1-v2/index.js

Correct paths: line 89: await runSqlFile('/db/postgresql/migrations/01_init/migration.sql');

line 106: const filePath = '/db/postgresql/data-migration-v2.sql';

This fixed the issue and I could complete the migration.

However, afterwards I run into this error while deploying to Heroku.

   $ node scripts/check-db.js
     ✓ DATABASE_URL is defined.
     ✓ Database connection successful.
     ✓ Database version check successful.
Error: P3005
The database schema is not empty. Read more about how to baseline an existing production database: https://pris.ly/d/migrate-baseline
     ✗ Command failed: prisma migrate deploy
     Error: P3005
     
     The database schema is not empty. Read more about how to baseline an existing production database: https://pris.ly/d/migrate-baseline

error Command failed with exit code 1.
     info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: "check-db" exited with 1.
error Command failed with exit code 1.
     info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

-----> Build failed

Any ideas?