SlideShare a Scribd company logo
1 of 50
Download to read offline
-
Friday, May 10, 13
YANN ARMAND
-
@yarmand
Friday, May 10, 13
-
The Enterprise Social Network
Friday, May 10, 13
Friday, May 10, 13
DELETE A DB COLUMN
WITHOUT MAKING ZOMBIES
Friday, May 10, 13
DELETE A DB COLUMN
WITHOUT MAKING ZOMBIES
Friday, May 10, 13
WHY DELETE A MODEL
ATTRIBUTE ?
-
Friday, May 10, 13
WHY DELETE A MODEL
ATTRIBUTE ?
• Not used anymore
-
Friday, May 10, 13
WHY DELETE A MODEL
ATTRIBUTE ?
• Not used anymore
User Payment card
• card_type
• card_number
• Move to another model
-
Friday, May 10, 13
KILLING AN ACTIVE RECORD
FIELD
Cons
-
Friday, May 10, 13
KILLING AN ACTIVE RECORD
FIELD
• Code dependency
Cons
-
Friday, May 10, 13
KILLING AN ACTIVE RECORD
FIELD
• Code dependency
Cons
• Unknown impact on the app behavior
-
Friday, May 10, 13
KILLING AN ACTIVE RECORD
FIELD
• Code dependency
Cons
• Unknown impact on the app behavior
-
Friday, May 10, 13
KILLING AN ACTIVE RECORD
FIELD
• Code dependency
Cons
• Unknown impact on the app behavior
-
Friday, May 10, 13
KILL AN ACTIVE RECORD
FIELD
Pros
-
Friday, May 10, 13
KILL AN ACTIVE RECORD
FIELD
Pros
• ReduceTechnical Debt
-
Friday, May 10, 13
KILL AN ACTIVE RECORD
FIELD
Pros
• ReduceTechnical Debt
• Smaller code base
• Lower barrier of entry
-
• Eliminate black holes
• Prevent crashes
Friday, May 10, 13
BE PREPARED !!
-
Friday, May 10, 13
BE PREPARED !!
-
Friday, May 10, 13
BE PREPARED !!
-
Friday, May 10, 13
class User
deprecate_attribute :card_type
deprecate_attribute :card_number
end
-
Friday, May 10, 13
API OUTPUT
render :json => user
name: 'roger'
age: 23
card_type: 'visa'
card_number: 123412341234
name: 'roger'
age: 23
-
Friday, May 10, 13
API OUTPUT
render :json => user
name: 'roger'
age: 23
card_type: 'visa'
card_number: 123412341234
name: 'roger'
age: 23
-
ActiveRecord#serializable_hash
Friday, May 10, 13
API OUTPUT
-
class User
alias_method :super_serializable_hash, :serializable_hash
def serializable_hash(options = {})
options.merge! {
:only => self.attributes.keys.map(&:to_sym) -
(self.class.deprecated_attributes ||
[]).map(&:to_sym)
}
super_serializable_hash(options)
end
end
Friday, May 10, 13
API OUTPUT
-
class User
alias_method :super_serializable_hash, :serializable_hash
def serializable_hash(options = {})
options.merge! {
:only => self.attributes.keys.map(&:to_sym) -
(self.class.deprecated_attributes ||
[]).map(&:to_sym)
}
super_serializable_hash(options)
end
end
Friday, May 10, 13
API OUTPUT
-
class User
alias_method :super_serializable_hash, :serializable_hash
def serializable_hash(options = {})
options.merge! {
:only => self.attributes.keys.map(&:to_sym) -
(self.class.deprecated_attributes ||
[]).map(&:to_sym)
}
super_serializable_hash(options)
end
end
Friday, May 10, 13
API OUTPUT
-
class User
alias_method :super_serializable_hash, :serializable_hash
def serializable_hash(options = {})
options.merge! {
:only => self.attributes.keys.map(&:to_sym) -
(self.class.deprecated_attributes ||
[]).map(&:to_sym)
}
super_serializable_hash(options)
end
end
Friday, May 10, 13
ACCESSORS =
[ '',
'=',
'_before_type_cast',
'?',
'_changed?',
'_change',
'_will_change!',
'_was']
Zombie Radar
-
FIELD HUNTING
Friday, May 10, 13
-
def deprecate_attribute attr
msg = "You can't access atribute #{attr}, it has been
deprecated"
ACCESSORS.each do |term|
define_method("#{attr}#{term}") do |*args|
raise DeprecatedAttributeError, msg
super
end
end
end
Friday, May 10, 13
-
def deprecate_attribute attr
msg = "You can't access atribute #{attr}, it has been
deprecated"
ACCESSORS.each do |term|
define_method("#{attr}#{term}") do |*args|
raise DeprecatedAttributeError, msg
super
end
end
end
Friday, May 10, 13
-
def deprecate_attribute attr
msg = "You can't access atribute #{attr}, it has been
deprecated"
ACCESSORS.each do |term|
define_method("#{attr}#{term}") do |*args|
raise DeprecatedAttributeError, msg
super
end
end
end
Friday, May 10, 13
-
def deprecate_attribute attr
msg = "You can't access atribute #{attr}, it has been
deprecated"
ACCESSORS.each do |term|
define_method("#{attr}#{term}") do |*args|
raise DeprecatedAttributeError, msg
super
end
end
end
Friday, May 10, 13
-
def deprecate_attribute attr
msg = "You can't access atribute #{attr}, it has been
deprecated"
ACCESSORS.each do |term|
define_method("#{attr}#{term}") do |*args|
raise DeprecatedAttributeError, msg
super
end
end
end
Friday, May 10, 13
-
def deprecate_attribute attr
msg = "You can't access atribute #{attr}, it has been
deprecated"
ACCESSORS.each do |term|
define_method("#{attr}#{term}") do |*args|
raise DeprecatedAttributeError, msg
super
end
end
end
Friday, May 10, 13
Friday, May 10, 13
class ApplicationController
rescue_from DeprecatedAttributeError, :with => :log_deprecate
private
def log_deprecated e
deprecated_logger.error(e.backtrace.join("n"))
e.continue
end
end
Friday, May 10, 13
cmaruz/continuable
class ApplicationController
rescue_from DeprecatedAttributeError, :with => :log_deprecate
private
def log_deprecated e
deprecated_logger.error(e.backtrace.join("n"))
e.continue
end
end
Friday, May 10, 13
REFACTOR
-
Friday, May 10, 13
REFACTOR
-
DEPLOY
Friday, May 10, 13
REFACTOR
New Code
-
DEPLOY
Friday, May 10, 13
REFACTOR
MigrationNew Code
-
DEPLOY
Friday, May 10, 13
REFACTOR
MigrationNew Code
-
DEPLOY
Friday, May 10, 13
WHAT HAPPENS ?
name: 'roger'
age: 23
card_type: 'visa'
card_number: 123412341234
-
Time
In Cache
Friday, May 10, 13
WHAT HAPPENS ?
name: 'roger'
age: 23
card_type: 'visa'
card_number: 123412341234
Deploy
-
Time
In Cache
Friday, May 10, 13
WHAT HAPPENS ?
name: 'roger'
age: 23
card_type: 'visa'
card_number: 123412341234
Deploy
name: 'roger'
age: 24
card_type: 'visa'
card_number: 123412341234
-
Time
In Cache Update
Friday, May 10, 13
WHAT HAPPENS ?
name: 'roger'
age: 23
card_type: 'visa'
card_number: 123412341234
Deploy
name: 'roger'
age: 24
card_type: 'visa'
card_number: 123412341234
Save
-
Time
In Cache Update
Friday, May 10, 13
WHAT HAPPENS ?
name: 'roger'
age: 23
card_type: 'visa'
card_number: 123412341234
Deploy
name: 'roger'
age: 24
card_type: 'visa'
card_number: 123412341234
Save
Database Exception
unknown columns
card_type, card_number
-
Time
In Cache Update
Friday, May 10, 13
WHAT HAPPENS ?
name: 'roger'
age: 23
card_type: 'visa'
card_number: 123412341234
Deploy
name: 'roger'
age: 24
card_type: 'visa'
card_number: 123412341234
Save
Database Exception
unknown columns
card_type, card_number
-
Time
In Cache Update
Friday, May 10, 13
IGNORE COLUMNS
-
class User
def columns
self.class.columns.reject do |c|
(self.class.deprecated_attributes || []).include? c.name.to_s
end
end
end
Friday, May 10, 13
THANK YOU !!
https://github.com/yarmand/acread
Acread
-
Friday, May 10, 13

More Related Content

Similar to Deprecating ActiveRecord Attributes without making Zombies

Dependency management & Package management in JavaScript
Dependency management & Package management in JavaScriptDependency management & Package management in JavaScript
Dependency management & Package management in JavaScriptSebastiano Armeli
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
Intro to Ember.js
Intro to Ember.jsIntro to Ember.js
Intro to Ember.jsJay Phelps
 
JavaScript Qualitätssicherung
JavaScript QualitätssicherungJavaScript Qualitätssicherung
JavaScript QualitätssicherungSebastian Springer
 
Gon gem. For RDRC 2013, June 7
Gon gem. For RDRC 2013, June 7Gon gem. For RDRC 2013, June 7
Gon gem. For RDRC 2013, June 7Alexey Gaziev
 
"Full Stack frameworks or a story about how to reconcile Front (good) and Bac...
"Full Stack frameworks or a story about how to reconcile Front (good) and Bac..."Full Stack frameworks or a story about how to reconcile Front (good) and Bac...
"Full Stack frameworks or a story about how to reconcile Front (good) and Bac...Fwdays
 
Fixture Replacement Plugins
Fixture Replacement PluginsFixture Replacement Plugins
Fixture Replacement PluginsPaul Klipp
 
Drupal 8 configuration system for coders and site builders - DrupalCamp Balti...
Drupal 8 configuration system for coders and site builders - DrupalCamp Balti...Drupal 8 configuration system for coders and site builders - DrupalCamp Balti...
Drupal 8 configuration system for coders and site builders - DrupalCamp Balti...swentel
 
GameSlap demo
GameSlap demoGameSlap demo
GameSlap demoAmy Ton
 
Elasticsearch in 15 minutes
Elasticsearch in 15 minutesElasticsearch in 15 minutes
Elasticsearch in 15 minutesDavid Pilato
 
Hotcode 2013: Javascript in a database (Part 2)
Hotcode 2013: Javascript in a database (Part 2)Hotcode 2013: Javascript in a database (Part 2)
Hotcode 2013: Javascript in a database (Part 2)ArangoDB Database
 
Nomethoderror talk
Nomethoderror talkNomethoderror talk
Nomethoderror talkJan Berdajs
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the FinishYehuda Katz
 
Teaching Programming Online
Teaching Programming OnlineTeaching Programming Online
Teaching Programming OnlinePamela Fox
 
Your own (little) gem: building an online business with Ruby
Your own (little) gem: building an online business with RubyYour own (little) gem: building an online business with Ruby
Your own (little) gem: building an online business with RubyLindsay Holmwood
 

Similar to Deprecating ActiveRecord Attributes without making Zombies (20)

Dependency management & Package management in JavaScript
Dependency management & Package management in JavaScriptDependency management & Package management in JavaScript
Dependency management & Package management in JavaScript
 
RequireJS
RequireJSRequireJS
RequireJS
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Intro to Ember.js
Intro to Ember.jsIntro to Ember.js
Intro to Ember.js
 
Storyplayer
StoryplayerStoryplayer
Storyplayer
 
JavaScript Qualitätssicherung
JavaScript QualitätssicherungJavaScript Qualitätssicherung
JavaScript Qualitätssicherung
 
Gon gem. For RDRC 2013, June 7
Gon gem. For RDRC 2013, June 7Gon gem. For RDRC 2013, June 7
Gon gem. For RDRC 2013, June 7
 
"Full Stack frameworks or a story about how to reconcile Front (good) and Bac...
"Full Stack frameworks or a story about how to reconcile Front (good) and Bac..."Full Stack frameworks or a story about how to reconcile Front (good) and Bac...
"Full Stack frameworks or a story about how to reconcile Front (good) and Bac...
 
minne の API 改善
minne の API 改善minne の API 改善
minne の API 改善
 
Fixture Replacement Plugins
Fixture Replacement PluginsFixture Replacement Plugins
Fixture Replacement Plugins
 
Drupal 8 configuration system for coders and site builders - DrupalCamp Balti...
Drupal 8 configuration system for coders and site builders - DrupalCamp Balti...Drupal 8 configuration system for coders and site builders - DrupalCamp Balti...
Drupal 8 configuration system for coders and site builders - DrupalCamp Balti...
 
Caching tips
Caching tipsCaching tips
Caching tips
 
GameSlap demo
GameSlap demoGameSlap demo
GameSlap demo
 
Elasticsearch in 15 minutes
Elasticsearch in 15 minutesElasticsearch in 15 minutes
Elasticsearch in 15 minutes
 
Hotcode 2013: Javascript in a database (Part 2)
Hotcode 2013: Javascript in a database (Part 2)Hotcode 2013: Javascript in a database (Part 2)
Hotcode 2013: Javascript in a database (Part 2)
 
Rails3 changesets
Rails3 changesetsRails3 changesets
Rails3 changesets
 
Nomethoderror talk
Nomethoderror talkNomethoderror talk
Nomethoderror talk
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Teaching Programming Online
Teaching Programming OnlineTeaching Programming Online
Teaching Programming Online
 
Your own (little) gem: building an online business with Ruby
Your own (little) gem: building an online business with RubyYour own (little) gem: building an online business with Ruby
Your own (little) gem: building an online business with Ruby
 

Deprecating ActiveRecord Attributes without making Zombies