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/20190923123858_simplify_project_active_and_timestamp.rb
class SimplifyProjectActiveAndTimestamp < ActiveRecord::Migration[6.0]
  STATUS_ACTIVE     = 1
  STATUS_ARCHIVED   = 9

  class Project < ActiveRecord::Base; end

  def change
    change_project_columns

    reversible do |change|
      change.up do
        fill_active_column
      end
      change.down do
        recreate_status_column_and_information
      end
    end
  end

  private

  def change_project_columns
    change_table :projects do |table|
      table.rename :created_on, :created_at
      table.rename :updated_on, :updated_at
      table.rename :is_public, :public
    end
  end

  def fill_active_column
    add_column :projects, :active, :boolean, default: true, index: true, null: false

    Project.reset_column_information
    Project.where(status: STATUS_ARCHIVED).update_all(active: false)

    remove_column :projects, :status
  end

  def recreate_status_column_and_information
    add_column :projects, :status, :integer, default: STATUS_ACTIVE, null: false

    Project.reset_column_information
    Project.where(active: true).update_all(status: STATUS_ACTIVE)
    Project.where(active: false).update_all(status: STATUS_ARCHIVED)

    remove_column :projects, :active
  end
end