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-0.16.1 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-0.17.0 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-0.15.9 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-0.15.8 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-0.14.6 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-0.15.7 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-0.16.0 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-0.15.6 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-0.15.5 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-0.15.4 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-0.15.3 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-0.15.2 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-0.15.1 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-0.15.0 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-0.14.5 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-0.14.4 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-0.14.3 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-0.14.2 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-0.14.1 db/migrate/20180216092715_use_uuid.rb
foreman-tasks-0.14.0 db/migrate/20180216092715_use_uuid.rb