Rail Migration and Column Modification

works with sqlite3 for local developer. Prod DB - MySql.

Have a migration file to modify the column.

class ChangeDateToOrders < ActiveRecord::Migration def self.up change_column(:orders, :closed_date, :datetime) end def self.down change_column(:orders, :closed_date, :date) end end 

Errors index name 'temp_index_altered_orders_on_closed_location_id_and_parent_company_id' on table 'altered_orders' is too long; the limit is 64 characters index name 'temp_index_altered_orders_on_closed_location_id_and_parent_company_id' on table 'altered_orders' is too long; the limit is 64 characters

Know there is a restriction on the index name with sqlite, but is there a workaround for this?

EDIT The workaround I used.

 class ChangeDateToOrders < ActiveRecord::Migration def self.up remove_index(:orders, [:closed_location_id, :parent_company_id]) change_column(:orders, :closed_date, :datetime) add_index(:orders, [:closed_location_id, :parent_company_id], :name => "add_index_to_orders_cli_pci") end def self.down remove_index(:orders, :name => "add_index_to_orders_cli_pci") change_column(:orders, :closed_date, :date) add_index(:orders, [:closed_location_id, :parent_company_id]) end end 
+7
source share
2 answers

Personally, I like it when my development and development environments fit as much as possible. It helps avoid gotchas. If I were deploying MySQL, I would also run the development environment with MySQL. In addition, I am also not very good at SQLite, so this approach addresses my lazy side - I only need to know the inputs and outputs of one db.

+1
source

You can hack your copy of the active record; Add the following

  opts[:name] = opts[:name][0..63] # can't be more than 64 chars long 

Around line 535 (in version 3.2.9) from $ GEM_HOME / gems / activerecord-3.2.9 / lib / active_record / connection_adapters / sqlite_adapter.rb

This is a hack, but it can help you overcome the obstacle. If I had more time, I would try to write a test and send a request for traction to the main rails command.

0
source

All Articles