Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ridgepoleで定義するindex名をhashのランダム名で定義する(古いRailsっぽい挙動)
# Schemafileから
# require_relative './lib/ridgepole_hashed_index_name'
# して使う
module RidgepoleHashedIndexName
def index_name(table_name, options)
if options.is_a?(Hash) && options[:column]
identifier = super
hashed_identifier = Digest::SHA256.hexdigest(identifier).first(10)
"index_rails_#{hashed_identifier}"
else
super
end
end
ActiveRecord::Base.connection.class.prepend(self)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment