Your SlideShare is downloading. ×
Deprecating ActiveRecord Attributes without making Zombies
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Deprecating ActiveRecord Attributes without making Zombies

363
views

Published on


0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
363
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. -Friday, May 10, 13
  • 2. YANN ARMAND-@yarmandFriday, May 10, 13
  • 3. -The Enterprise Social NetworkFriday, May 10, 13
  • 4. Friday, May 10, 13
  • 5. DELETE A DB COLUMNWITHOUT MAKING ZOMBIESFriday, May 10, 13
  • 6. DELETE A DB COLUMNWITHOUT MAKING ZOMBIESFriday, May 10, 13
  • 7. WHY DELETE A MODELATTRIBUTE ?-Friday, May 10, 13
  • 8. WHY DELETE A MODELATTRIBUTE ?• Not used anymore-Friday, May 10, 13
  • 9. WHY DELETE A MODELATTRIBUTE ?• Not used anymoreUser Payment card• card_type• card_number• Move to another model-Friday, May 10, 13
  • 10. KILLING AN ACTIVE RECORDFIELDCons-Friday, May 10, 13
  • 11. KILLING AN ACTIVE RECORDFIELD• Code dependencyCons-Friday, May 10, 13
  • 12. KILLING AN ACTIVE RECORDFIELD• Code dependencyCons• Unknown impact on the app behavior-Friday, May 10, 13
  • 13. KILLING AN ACTIVE RECORDFIELD• Code dependencyCons• Unknown impact on the app behavior-Friday, May 10, 13
  • 14. KILLING AN ACTIVE RECORDFIELD• Code dependencyCons• Unknown impact on the app behavior-Friday, May 10, 13
  • 15. KILL AN ACTIVE RECORDFIELDPros-Friday, May 10, 13
  • 16. KILL AN ACTIVE RECORDFIELDPros• ReduceTechnical Debt-Friday, May 10, 13
  • 17. KILL AN ACTIVE RECORDFIELDPros• ReduceTechnical Debt• Smaller code base• Lower barrier of entry-• Eliminate black holes• Prevent crashesFriday, May 10, 13
  • 18. BE PREPARED !!-Friday, May 10, 13
  • 19. BE PREPARED !!-Friday, May 10, 13
  • 20. BE PREPARED !!-Friday, May 10, 13
  • 21. class Userdeprecate_attribute :card_typedeprecate_attribute :card_numberend-Friday, May 10, 13
  • 22. API OUTPUTrender :json => username: rogerage: 23card_type: visacard_number: 123412341234name: rogerage: 23-Friday, May 10, 13
  • 23. API OUTPUTrender :json => username: rogerage: 23card_type: visacard_number: 123412341234name: rogerage: 23-ActiveRecord#serializable_hashFriday, May 10, 13
  • 24. API OUTPUT-class Useralias_method :super_serializable_hash, :serializable_hashdef serializable_hash(options = {})options.merge! {:only => self.attributes.keys.map(&:to_sym) -(self.class.deprecated_attributes ||[]).map(&:to_sym)}super_serializable_hash(options)endendFriday, May 10, 13
  • 25. API OUTPUT-class Useralias_method :super_serializable_hash, :serializable_hashdef serializable_hash(options = {})options.merge! {:only => self.attributes.keys.map(&:to_sym) -(self.class.deprecated_attributes ||[]).map(&:to_sym)}super_serializable_hash(options)endendFriday, May 10, 13
  • 26. API OUTPUT-class Useralias_method :super_serializable_hash, :serializable_hashdef serializable_hash(options = {})options.merge! {:only => self.attributes.keys.map(&:to_sym) -(self.class.deprecated_attributes ||[]).map(&:to_sym)}super_serializable_hash(options)endendFriday, May 10, 13
  • 27. API OUTPUT-class Useralias_method :super_serializable_hash, :serializable_hashdef serializable_hash(options = {})options.merge! {:only => self.attributes.keys.map(&:to_sym) -(self.class.deprecated_attributes ||[]).map(&:to_sym)}super_serializable_hash(options)endendFriday, May 10, 13
  • 28. ACCESSORS =[ ,=,_before_type_cast,?,_changed?,_change,_will_change!,_was]Zombie Radar-FIELD HUNTINGFriday, May 10, 13
  • 29. -def deprecate_attribute attrmsg = "You cant access atribute #{attr}, it has beendeprecated"ACCESSORS.each do |term|define_method("#{attr}#{term}") do |*args|raise DeprecatedAttributeError, msgsuperendendendFriday, May 10, 13
  • 30. -def deprecate_attribute attrmsg = "You cant access atribute #{attr}, it has beendeprecated"ACCESSORS.each do |term|define_method("#{attr}#{term}") do |*args|raise DeprecatedAttributeError, msgsuperendendendFriday, May 10, 13
  • 31. -def deprecate_attribute attrmsg = "You cant access atribute #{attr}, it has beendeprecated"ACCESSORS.each do |term|define_method("#{attr}#{term}") do |*args|raise DeprecatedAttributeError, msgsuperendendendFriday, May 10, 13
  • 32. -def deprecate_attribute attrmsg = "You cant access atribute #{attr}, it has beendeprecated"ACCESSORS.each do |term|define_method("#{attr}#{term}") do |*args|raise DeprecatedAttributeError, msgsuperendendendFriday, May 10, 13
  • 33. -def deprecate_attribute attrmsg = "You cant access atribute #{attr}, it has beendeprecated"ACCESSORS.each do |term|define_method("#{attr}#{term}") do |*args|raise DeprecatedAttributeError, msgsuperendendendFriday, May 10, 13
  • 34. -def deprecate_attribute attrmsg = "You cant access atribute #{attr}, it has beendeprecated"ACCESSORS.each do |term|define_method("#{attr}#{term}") do |*args|raise DeprecatedAttributeError, msgsuperendendendFriday, May 10, 13
  • 35. Friday, May 10, 13
  • 36. class ApplicationControllerrescue_from DeprecatedAttributeError, :with => :log_deprecateprivatedef log_deprecated edeprecated_logger.error(e.backtrace.join("n"))e.continueendendFriday, May 10, 13
  • 37. cmaruz/continuableclass ApplicationControllerrescue_from DeprecatedAttributeError, :with => :log_deprecateprivatedef log_deprecated edeprecated_logger.error(e.backtrace.join("n"))e.continueendendFriday, May 10, 13
  • 38. REFACTOR-Friday, May 10, 13
  • 39. REFACTOR-DEPLOYFriday, May 10, 13
  • 40. REFACTORNew Code-DEPLOYFriday, May 10, 13
  • 41. REFACTORMigrationNew Code-DEPLOYFriday, May 10, 13
  • 42. REFACTORMigrationNew Code-DEPLOYFriday, May 10, 13
  • 43. WHAT HAPPENS ?name: rogerage: 23card_type: visacard_number: 123412341234-TimeIn CacheFriday, May 10, 13
  • 44. WHAT HAPPENS ?name: rogerage: 23card_type: visacard_number: 123412341234Deploy-TimeIn CacheFriday, May 10, 13
  • 45. WHAT HAPPENS ?name: rogerage: 23card_type: visacard_number: 123412341234Deployname: rogerage: 24card_type: visacard_number: 123412341234-TimeIn Cache UpdateFriday, May 10, 13
  • 46. WHAT HAPPENS ?name: rogerage: 23card_type: visacard_number: 123412341234Deployname: rogerage: 24card_type: visacard_number: 123412341234Save-TimeIn Cache UpdateFriday, May 10, 13
  • 47. WHAT HAPPENS ?name: rogerage: 23card_type: visacard_number: 123412341234Deployname: rogerage: 24card_type: visacard_number: 123412341234SaveDatabase Exceptionunknown columnscard_type, card_number-TimeIn Cache UpdateFriday, May 10, 13
  • 48. WHAT HAPPENS ?name: rogerage: 23card_type: visacard_number: 123412341234Deployname: rogerage: 24card_type: visacard_number: 123412341234SaveDatabase Exceptionunknown columnscard_type, card_number-TimeIn Cache UpdateFriday, May 10, 13
  • 49. IGNORE COLUMNS-class Userdef columnsself.class.columns.reject do |c|(self.class.deprecated_attributes || []).include? c.name.to_sendendendFriday, May 10, 13
  • 50. THANK YOU !!https://github.com/yarmand/acreadAcread-Friday, May 10, 13