Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use short index name for all adapters
  • Loading branch information
timfjord committed Dec 7, 2013
1 parent 8777df4 commit 76f35c9
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions db/migrate/2_create_copywriting_translation_table.rb
Expand Up @@ -13,9 +13,10 @@ def self.up
:migrate_data => true
})

with_short_sqlite_compatible_index do
rename_column Refinery::Copywriting::Phrase.translation_class.table_name, :copywriting_phrase_id, :refinery_copywriting_phrase_id
end
# to prevent long index name errors on some adapters
remove_index Refinery::Copywriting::Phrase.translation_class.table_name, [:copywriting_phrase_id]
rename_column Refinery::Copywriting::Phrase.translation_class.table_name, :copywriting_phrase_id, :refinery_copywriting_phrase_id
add_index Refinery::Copywriting::Phrase.translation_class.table_name, :refinery_copywriting_phrase_id, :name => "index_short_on_refinery_copywriting_phrase_id"

::Refinery::Copywriting::Phrase.table_name = "refinery_#{Refinery::Copywriting::Phrase.table_name}"
::Refinery::Copywriting::Phrase.module_eval do
Expand All @@ -40,15 +41,4 @@ def self.down
::Refinery::Copywriting::Phrase.translation_class.table_name = "refinery_#{Refinery::Copywriting::Phrase.translation_class.table_name}"
end


def self.with_short_sqlite_compatible_index
if ActiveRecord::Base.connection.adapter_name.downcase.to_sym == :sqlite
remove_index Refinery::Copywriting::Phrase.translation_class.table_name, [:copywriting_phrase_id]#[:index_altered_copywriting_phrase_translations_on_copywriting_phrase_id]
yield
add_index Refinery::Copywriting::Phrase.translation_class.table_name, :refinery_copywriting_phrase_id, :name => "index_short_on_refinery_copywriting_phrase_id"
else
yield
end
end

end

0 comments on commit 76f35c9

Please sign in to comment.