umami: can't run on v2.3.0. Err msg: migrate found failed migrations in the target database

Describe the Bug

image: docker.umami.dev/umami-software/umami:mysql-latest

SQL: mariaDB 10.3

Database

MySQL

Relevant log output

migrate found failed migrations in the target database, new migrations will not be applied. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve
The `02_report_schema_session_data` migration started at 2023-07-13 04:00:33.871 UTC failed


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.
yarn run v1.22.19
$ npm-run-all check-db update-tracker start-server
$ node scripts/check-db.js
✓ DATABASE_URL is defined.
✓ Database connection successful.
✓ Database version check successful.
✗ Command failed: prisma migrate deploy
Error: P3009

migrate found failed migrations in the target database, new migrations will not be applied. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve
The `02_report_schema_session_data` migration started at 2023-07-13 04:00:33.871 UTC failed



Error: P3009


### Which browser are you using? (if relevant)

_No response_

### How are you deploying your application? (if relevant)

docker

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 16

Most upvoted comments

@bartosjiri Definitely need to keep this in mind when prisma creates MySQL migrations. We will follow the workaround approach for any future migrations. For this one you will have to alter the existing migration like the directions above.

  1. Update the migration.sql file in 02_report_schema_session_data. Replace the rename columns code to
-- RenameColumns
ALTER TABLE `event_data` ADD COLUMN data_type INTEGER UNSIGNED AFTER event_data_type;
ALTER TABLE `event_data` ADD COLUMN date_value TIMESTAMP(0) AFTER event_date_value;
ALTER TABLE `event_data` ADD COLUMN event_data_id VARCHAR(36) AFTER event_id;
ALTER TABLE `event_data` ADD COLUMN number_value DECIMAL(19, 4) AFTER event_numeric_value;
ALTER TABLE `event_data` ADD COLUMN string_value VARCHAR(500) AFTER event_string_value;

UPDATE event_data
SET data_type = event_data_type,
    date_value = event_date_value,
    event_data_id = event_id,
    number_value = event_numeric_value,
    string_value = event_string_value;

ALTER TABLE `event_data` MODIFY data_type INTEGER UNSIGNED NOT NULL;
ALTER TABLE `event_data` MODIFY event_data_id VARCHAR(36) NOT NULL;

ALTER TABLE `event_data` DROP COLUMN event_data_type;
ALTER TABLE `event_data` DROP COLUMN event_date_value;
ALTER TABLE `event_data` DROP COLUMN event_id;
ALTER TABLE `event_data` DROP COLUMN event_numeric_value;
ALTER TABLE `event_data` DROP COLUMN event_string_value;

ALTER TABLE `event_data` ADD PRIMARY KEY(event_data_id);

  1. Run npx prisma migrate resolve --rolled-back "02_report_schema_session_data" to bypass the failed migration.
  2. Redeploy

@orilights It looks like the rename column syntax is different for mysql 5.7. You will need to update the migration script to follow this rename syntax. You can run the below steps or update your image to a later version. 5.7 support ends in October 2023.

  1. Update the migration.sql file in 02_report_schema_session_data to
ALTER TABLE `event_data` CHANGE `event_data_type` `data_type` int unsigned NOT NULL;
ALTER TABLE `event_data` CHANGE `event_date_value` `date_value` timestamp NULL;
ALTER TABLE `event_data` CHANGE `event_id` `event_data_id` varchar(36) NOT NULL;
ALTER TABLE `event_data` CHANGE `event_numeric_value` `number_value` decimal(19, 4) NULL;
ALTER TABLE `event_data` CHANGE `event_string_value` `string_value`varchar(500) NULL;
  1. Run npx prisma migrate resolve --rolled-back "02_report_schema_session_data"
  2. Redeploy

I am using docker and MySQL 5.7

below is the migration log I found in _prisma_migrations

A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve

Migration name: 02_report_schema_session_data

Database error code: 1064

Database error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'COLUMN `event_data_type` TO `data_type`;
ALTER TABLE `event_data` RENAME COLUMN ' at line 2

Please check the query number 1 from the migration file.

   0: sql_schema_connector::apply_migration::apply_script
           with migration_name="02_report_schema_session_data"
             at schema-engine/connectors/sql-schema-connector/src/apply_migration.rs:106
   1: schema_core::commands::apply_migrations::Applying migration
           with migration_name="02_report_schema_session_data"
             at schema-engine/core/src/commands/apply_migrations.rs:91
   2: schema_core::state::ApplyMigrations
             at schema-engine/core/src/state.rs:197