diff --git a/db/migrate/20240920152544_set_versions_name_collation.rb b/db/migrate/20240920152544_set_versions_name_collation.rb index 1109bf9eec4f..cbfb9541b8cb 100644 --- a/db/migrate/20240920152544_set_versions_name_collation.rb +++ b/db/migrate/20240920152544_set_versions_name_collation.rb @@ -1,8 +1,23 @@ class SetVersionsNameCollation < ActiveRecord::Migration[7.1] def up - execute <<-SQL.squish - CREATE COLLATION IF NOT EXISTS versions_name (provider = icu, locale = 'und-u-kn-true'); - SQL + begin + execute <<-SQL.squish + CREATE COLLATION IF NOT EXISTS versions_name (provider = icu, locale = 'und-u-kn-true'); + SQL + rescue StandardError => e + raise unless e.message.include?("encoding") + + abort <<~MESSAGE + \e[31mERROR:\e[0m Failed to create an ICU collation with current database encoding. + You need to change the database encoding before proceeding. + + Please check the instructions on how to do it: + https://www.openproject.org/docs/installation-and-operations/misc/changing-database-encoding/ + + Original error: + #{e.message} + MESSAGE + end change_column :versions, :name, :string, collation: "versions_name" end