Skip to content

Instantly share code, notes, and snippets.

@alpaca-tc
Created May 23, 2021 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alpaca-tc/2ad519e91be5eb5067c8ff06c6c8a3d2 to your computer and use it in GitHub Desktop.
Save alpaca-tc/2ad519e91be5eb5067c8ff06c6c8a3d2 to your computer and use it in GitHub Desktop.
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