Created
May 23, 2021 13:10
-
-
Save alpaca-tc/2ad519e91be5eb5067c8ff06c6c8a3d2 to your computer and use it in GitHub Desktop.
ridgepoleで定義するindex名をhashのランダム名で定義する(古いRailsっぽい挙動)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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