HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux vmi1674223.contaboserver.net 5.4.0-182-generic #202-Ubuntu SMP Fri Apr 26 12:29:36 UTC 2024 x86_64
User: root (0)
PHP: 7.4.3-4ubuntu2.22
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //opt/openproject/db/migrate/20200326102408_rename_fixed_version.rb
class RenameFixedVersion < ActiveRecord::Migration[6.0]
  def up
    rename_column :work_packages, :fixed_version_id, :version_id
    rename_column :work_package_journals, :fixed_version_id, :version_id

    rename_query_attributes('fixed_version', 'version')
  end

  def down
    rename_column :work_packages, :version_id, :fixed_version_id
    rename_column :work_package_journals, :version_id, :fixed_version_id

    rename_query_attributes('version', 'fixed_version')
  end

  def rename_query_attributes(from, to)
    ActiveRecord::Base.connection.exec_query(
      <<-SQL
        UPDATE
          queries q_sink
        SET
          filters = regexp_replace(q_source.filters, '(\n)#{from}_id:(\n)', '\\1#{to}_id:\\2'),
          column_names = regexp_replace(q_source.column_names, ':#{from}', ':#{to}'),
          sort_criteria = regexp_replace(q_source.sort_criteria, '#{from}', '#{to}'),
          group_by = regexp_replace(q_source.group_by, '#{from}', '#{to}')
        FROM
          queries q_source
        WHERE
          (q_source.filters LIKE '%#{from}_id:%'
          OR q_source.column_names LIKE '%#{from}%'
          OR q_source.sort_criteria LIKE '%#{from}%'
          OR q_source.group_by = '#{from}')
          AND q_sink.id = q_source.id
    SQL
    )
  end
end