SlideShare a Scribd company logo
-
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

PDF
I motion
PDF
RSpec. Part 1
PDF
KEY
Your Library Sucks, and why you should use it.
PDF
Csec Physics lab manual
PDF
A Better UJS for Rails
PDF
Keeping it small - Getting to know the Slim PHP micro framework
PDF
Slides changes symfony23
I motion
RSpec. Part 1
Your Library Sucks, and why you should use it.
Csec Physics lab manual
A Better UJS for Rails
Keeping it small - Getting to know the Slim PHP micro framework
Slides changes symfony23

Similar to Deprecating ActiveRecord Attributes without making Zombies (20)

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

Deprecating ActiveRecord Attributes without making Zombies