forked from daneharrigan/data_migration
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
63 lines (48 loc) · 1.85 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
data_migration v0.2
==============
data_migration allows you to separate data you need to load from your
normal database migrations in a minimal way.
Example
=======
-Generate Migration
script/generate data_migration BlockedDomains
-Generate Migration in specific directory
script/generate data_migration BlockDomains PATH=db/bootstrap
-Outputs:
exists db/data
create db/data/20090915161242_settings.rb
-db/data/20090915161242_settings.rb:
class BlockedDomains < ActiveRecord::Migration
def self.up
end
end
-Add your code (with create):
def self.up
BlockedEmailDomain.create(:domain => "mailinator.com")
BlockedEmailDomain.create(:domain => "spamherelots.com")
BlockedEmailDomain.create(:domain => "disposeamail.com")
end
-Add/Remove your code (with add_data and remove_data):
def self.up
add_data(BlockedEmailDomain, :domain => "mailinator.com")
add_data(BlockedEmailDomain, :domain => "spamherelots.com")
end
def self.down
remove_data(BlockedEmailDomain, :domain => "mailinator.com")
remove_data(BlockedEmailDomain, :domain => "spamherelots.com")
end
NOTE: add_data and remove_data work well for populating individual tables.
If you need to populate relationships between tables I recommend creating
and destroying each item the standard Rails way.
-Run Migration
rake db:data:migrate
-Run Migration (from a different location)
rake db:data:migrate[db/bootstrap]
-Output
== BlockedDomains: migrating ===========================================================
== BlockedDomains: migrated (0.0020s) ==================================================
This adds the data migration version nubmer to the 'schema_migrations' table so it will not
be ran again.
Copyright (c) 2009 Knetwit Inc, released under the MIT license
Author(s): Heath Anderson
Updated by Dane Harrigan