Project

acread

0.01
No commit activity in last 3 years
No release in over 3 years
An ActiveRecord Extension to deprecate attributes
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.0.0
>= 1.8.4
>= 3.12

Runtime

 Project Readme

acread

Build Status

acread is a gem that helps you deprecating ActiveRecord attributes.

When you deprecate an attribute, acread can helps you in 3 ways :

  1. helps you finding where you are using this attribute by creating glue to raise a DeprecatedAttributeError.
  2. ignore this atribute when serializing the object through to_json, to_xml ...
  3. helps your zero downtime migration by ignoring the attribute for objects already in memory when saving to database.

Have a look at this London Ruby Group Lightning talk for a quick description of that 3 steps.

Usage

Installation

add to your Gemfile :

gem 'acread'

deprecate an attribute

class Person < ActiveRecord::Base
  ...
  deprecate_attribute :long_name
  ...
end

find attribute usage

you can catch the DeprecatedAttributeError exception and for example put a backtrace in a specific logger.

If you are using ruby > 1.9, Acread use the gem continuable (https://github.com/cmaruz/continuable). The DeprecatedAttributeError can then be continued, this mean you can catch it and continue normal ActiveRecord behavior. You're code hunting can then be done without any effect on your datas by simply catching the exception, logging and continuing.

class ApplicationController
	rescue_from DeprecatedAttributeError, :with => :log_deprecate

	private

	def deprecated_logger
		@@deprecated_logger ||= Logger.new("#{Rails.root}/log/deprecated_calls.log")
	end

	def log_deprecated e
		deprecated_logger.error(e.backtrace.join("\n"))
    e.continue
	end
end

zero downtime migration

When you are done with cleaning your code from any usage of deprecated attributes, you can prepare a migration including some drop_columns.

example :

class RemoveLongNames < ActiveRecord::Migration
  def self.up
    remove_column :Person, :long_name

  end

  def self.down
    raise ActiveRecord::IrreversibleMigration
  end
end

Then you can safely follow the steps :

  1. Deploy your code with deprecation declaration in it
  2. Run the migration
  3. Remove deprecation declarations from your code
  4. Deploy your final clean version of code

Copyright

Copyright (c) 2012 yann ARMAND & Nick Campbell under MIT See LICENSE.txt for further details.