Sha256: da8d0ce1732cb349a91aebbc3904832e904a8c2fdfb3d622cf0b1a8bf4139908

Contents?: true

Size: 1.17 KB

Versions: 9

Compression:

Stored size: 1.17 KB

Contents

class AddRuleIndices < ActiveRecord::Migration
  def change
    ['gemini_my_rules',  'g_array',    :array,
     'gemini_my_rules',  'g_single',   :scalar,
     'gemini_my_rules',  'g_string',   :scalar,
     'gemini_my_rules',  'g_bool',     :scalar,
     'gemini_my_rules',  'g_integer',  :scalar,
     'gemini_my_rules',  'g_range',    :range,
     'gemini_xyz_rules', 'flavors',    :array,
     'gemini_xyz_rules', 'guard_two',  :scalar,
     'gemini_xyz_rules', 'g_date',     :scalar,
     'gemini_xyz_rules', 'g_datetime', :scalar,
     'gemini_xyz_rules', 'g_bool',     :scalar,
     'gemini_xyz_rules', 'g_integer',  :scalar,
     'gemini_xyz_rules', 'g_range1',   :range,
     'gemini_xyz_rules', 'g_range2',   :range,
    ].in_groups_of(3).each do |table, field, type|
      index = { array: "GIN",
                scalar: "BTREE",
                range: "GIST" }[type]
      case type
      when :array, :scalar
        col="(simple_guards->'#{field}')"
      when :range
        col="(to_numrange(simple_guards->>'#{field}'))"
      end
      sql =<<-SQL
        CREATE INDEX idx_#{table}_#{field} ON #{table} USING #{index}
        (#{col});
      SQL
      execute sql
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
marty-1.2.9 spec/dummy/db/migrate/20171222150100_add_rule_indices.rb
marty-1.2.8 spec/dummy/db/migrate/20171222150100_add_rule_indices.rb
marty-1.2.7 spec/dummy/db/migrate/20171222150100_add_rule_indices.rb
marty-1.2.6 spec/dummy/db/migrate/20171222150100_add_rule_indices.rb
marty-1.2.5 spec/dummy/db/migrate/20171222150100_add_rule_indices.rb
marty-1.2.4 spec/dummy/db/migrate/20171222150100_add_rule_indices.rb
marty-1.2.3 spec/dummy/db/migrate/20171222150100_add_rule_indices.rb
marty-1.2.2 spec/dummy/db/migrate/20171222150100_add_rule_indices.rb
marty-1.2.1 spec/dummy/db/migrate/20171222150100_add_rule_indices.rb