Sha256: e4b41c95a902e0012f5e33463c75787ea5f595a4a32013a954e48e03f6f61b05

Contents?: true

Size: 1.16 KB

Versions: 108

Compression:

Stored size: 1.16 KB

Contents

class UseUuid < ActiveRecord::Migration[5.0]
  # PostgreSQL has a special column type for storing UUIDs.
  # Using this type instead of generic string should lead to having
  #  smaller DB and possibly better overall performance.
  def up
    if on_postgresql?
      change_table :foreman_tasks_tasks do |t|
        t.change :id, :uuid, :using => 'id::uuid'
        t.change :parent_task_id, :uuid, :using => 'parent_task_id::uuid'
      end

      change_table :foreman_tasks_task_group_members do |t|
        t.change :task_id, :uuid, :using => 'task_id::uuid'
      end

      change_table :foreman_tasks_locks do |t|
        t.change :task_id, :uuid, :using => 'task_id::uuid'
      end
    end
  end

  def down
    if on_postgresql?
      change_table :foreman_tasks_tasks do |t|
        t.change :id, :string
        t.change :parent_task_id, :string
      end

      change_table :foreman_tasks_task_group_members do |t|
        t.change :task_id, :string
      end

      change_table :foreman_tasks_locks do |t|
        t.change :task_id, :string
      end
    end
  end

  private

  def on_postgresql?
    ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
  end
end

Version data entries

108 entries across 108 versions & 1 rubygems

Version Path
foreman-tasks-10.0.1 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-10.0.0 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-9.2.3 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-9.2.2 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-9.2.1 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-9.2.0 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-9.1.1 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-9.0.4 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-9.1.0 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-9.0.2 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-9.0.1 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-8.3.3 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-9.0.0 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-8.2.1 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-8.1.4 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-8.3.2 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-8.3.1 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-8.1.3 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-8.3.0 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-8.2.0 db/migrate/20180216092715_use_uuid.rb