-
Notifications
You must be signed in to change notification settings - Fork 4
/
README
47 lines (31 loc) · 1.33 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
=LegacyMigrations
This plugin implements a simple, expressive syntax for migrating data from one data
structure to another. Here's a simple example:
require 'legacy_migrations'
transfer_from Person, :to => Animal do
from :name, :to => :pet_name
end
This transfers data from the people table to the animals table,
mapping the people's _name_ column to animals' _pet\_name_ column.
But that's just the beginning. This plugin also:
* Reports invalid data by using your application's own validation errors for easy data cleanup
(just use ActiveRecord validations and after running the script from
the command line, the output will give you helpful details about validation errors.)
* Maps foreign keys between the databases (currently not implemented)
* Gives you a bunch of options for mapping fields between tables.
== Example
In some file in your rails app (perhaps db/seeds.rb?)
require 'legacy_migrations'
transfer_from Person, :to => Animal do
from :name, :to => :pet_name
from :sex, :to => :gender do |sex|
sex == 'm' ? 'male' : 'female'
end
end
OR, copy all columns with the same name
transfer_from Person, :to => Animal do
match_same_name_attributes
end
Here's a slightly more thorough blog post about it:
http://frontended.com/?p=89
Copyright (c) 2010 Bernie Telles, released under the MIT license