Sha256: 6b2f8d7e08ae8e81f597151f7459f71feac76894a987b1b6be35b13afdbf5f59

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

# ZeroDowntime

[![Build Status](https://travis-ci.org/gogovan/zero_downtime.svg?branch=master)](https://travis-ci.org/gogovan/zero_downtime)

This is a minimal library to help run zero-downtime with rails and activerecord

## Deprecated Columns

The most common use case is deprecating a column.

If you just drop a column,
it will break any existing process that has cached the columns.

### Example

We have a model `Person`

It has a single column `:name`

However we want to split this up into

  * :first_name
  * :last_name

We add a migration

```
class AddFirstAndLastNamesToPeople < ActiveRecord::Migration
  class SafePersone # safe model
    self.table_name :people
  end

  def up
    add_column :people, :first_name
    add_column :people, :last_name

    SafePerson.find_each do |person|
      *first_names, last_name = person.name.split(" ")

      person.first_name = first_names.join(" ")
      person.last_name = last_name
      person.save!
    end
  end
end
```

That's fine,
but what to do with the deprecated :name column?

The answer, mark it as deprecated

```
class Person < ActiveRecord::Base
  deprecate_column :name
end
```

This will

* Let us easily find it later
* Stop anyone from using the column by accident
* Ensure that once its deployed we can safely remove the column

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
zero_downtime-0.4.0 README.md
zero_downtime-0.3.0 README.md
zero_downtime-0.2.2 README.md
zero_downtime-0.2.1 README.md