Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## old db base
- class OldServerConnectionBase < ActiveRecord::Base
- establish_connection(
- :adapter => "mysql",
- :host => "localhost",
- :username => "user",
- :password => "somepwd",
- :database => "old_db_name"
- )
- class MethodNotAvailable<StandardError; end;
- def delete(id)
- raise MethodNotAvailable
- end
- def delete_all(conditions =nil)
- raise MethodNotAvailable
- end
- def destroy(id)
- raise MethodNotAvailable
- end
- def destroy_all(conditions = nil)
- raise MethodNotAvailable
- end
- def create_or_update
- raise MethodNotAvailable
- end
- def update_attribute(name, value)
- raise MethodNotAvailable
- end
- def update_attributes(attributes)
- raise MethodNotAvailable
- end
- end
- ## some old db model
- class OldBook < OldServerConnectionBase
- set_table_name 'my_app_book_table'
- set_primary_key 'id_book'
- def self.migrate_all
- find(:all).each(&:migrate_me)
- end
- def migrate_me
- new_book = Book.new()
- new_book.isbn_10 = self.isbn
- new_book.isbn_13 = convert_to_isbn_13(self.isbn)
- new_book.save!
- end
- end
- ## in your console you just call
- OldBook.migrate_all
Add Comment
Please, Sign In to add comment