Нет описания http://j1x-huginn.herokuapp.com

20140213053001_add_event_id_at_creation_to_links.rb 599B

12345678910111213141516171819
  1. class AddEventIdAtCreationToLinks < ActiveRecord::Migration
  2. def up
  3. add_column :links, :event_id_at_creation, :integer, :null => false, :default => 0
  4. execute <<-SQL
  5. UPDATE #{ActiveRecord::Base.connection.quote_table_name('links')}
  6. SET event_id_at_creation = (
  7. SELECT #{ActiveRecord::Base.connection.quote_column_name('id')}
  8. FROM #{ActiveRecord::Base.connection.quote_table_name('events')}
  9. WHERE events.agent_id = links.source_id ORDER BY events.id DESC limit 1
  10. )
  11. SQL
  12. end
  13. def down
  14. remove_column :links, :event_id_at_creation
  15. end
  16. end