gardener 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +21 -10
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
=Gardener
|
2
2
|
==A Simple Rails Plugin to help you create seed data
|
3
|
-
Easy transfer of individual records
|
3
|
+
Easy transfer of individual records between environments / databases.
|
4
|
+
|
4
5
|
Gardener is intended to be used from the rails console, although I suppose you could script it with rake or something if you really wanted to.
|
5
6
|
|
6
7
|
==Usage
|
@@ -17,20 +18,23 @@ He's there behind the scenes and you can call on him in several ways.
|
|
17
18
|
c.plant_seed
|
18
19
|
|
19
20
|
This is the use case I wrote Gardener to solve.
|
21
|
+
|
20
22
|
I found myself (any my designers) making lots of fiddly copy changes to databased content, and needed a simple way to
|
21
23
|
pick and choose individual records to move from one environment (development --> staging or staging --> production) to another.
|
24
|
+
|
22
25
|
If you're asking yourself, "Why do you need to move just a few records from one database to another?" then you are lucky and I wish I was you.
|
26
|
+
|
23
27
|
If you're saying "Oh yeah, I do that too, and boy is it a PITA" then you are me and we are very lucky too because Gardener is here to help us out.
|
24
28
|
|
25
29
|
Gardener should be pretty much database agnostic, if you can .to_yaml it, Gardener can work in whatever soil type you have.
|
26
30
|
|
27
31
|
plant_seed can plant seeds for associated objects (or any method that returns objects).
|
28
32
|
c.plant_seed(:include => :foos)
|
29
|
-
|
33
|
+
# plant seeds for foo objects associated with c
|
30
34
|
c.plant_seed(:include => [:foos, :bars])
|
31
|
-
|
35
|
+
# plant seeds for foo and bar objects associated with c
|
32
36
|
c.plant_seed(:include => {:foos => :bazs})
|
33
|
-
|
37
|
+
# plant seeds for foo objects associated with c, and plant seeds for baz objects associated with those foo objects
|
34
38
|
|
35
39
|
n.b. There is not currently a way to reconstitute associated objects in the same call as the object itself.
|
36
40
|
To rebuild the associations in the example above you would call Content.reap, Foo.reap and Bar.reap.
|
@@ -69,7 +73,11 @@ You will encounter this if you have conflicting IDs during a reaping cycle, and
|
|
69
73
|
==Class Methods
|
70
74
|
|
71
75
|
===reap
|
76
|
+
User.reap
|
77
|
+
Content.reap
|
78
|
+
|
72
79
|
"[...] whatsoever a man soweth, that shall he also reap" - Galatians 6:7-8
|
80
|
+
|
73
81
|
For reaping the fruits of your labor.
|
74
82
|
|
75
83
|
This is how you get records out of your garden and back into your database.
|
@@ -78,8 +86,11 @@ It is not unusual when transfering a couple records from one database to another
|
|
78
86
|
When Gardener determines you are trying to sprout a record with an ID that already exists, it will prompt you to take one of several actions.
|
79
87
|
|
80
88
|
'y' will overwrite the database record with the attributes of the garden record.
|
89
|
+
|
81
90
|
'n' will make no changes to the database record.
|
91
|
+
|
82
92
|
'i' will give the garden record a new id, so that it doesn't conflict anymore. Database record stays the same, garden record gets a new identity.
|
93
|
+
|
83
94
|
'a' will raise an error and abort the whole procedure, making no changes to anything. This is your failsafe for when you realize you weren't done sowing your wild oats.
|
84
95
|
|
85
96
|
You can add 'z' to any of the above responses and Gardener will apply that response to the remainder of the records being reaped. Most often used like 'iz'.
|
@@ -87,14 +98,14 @@ You can add 'z' to any of the above responses and Gardener will apply that respo
|
|
87
98
|
|
88
99
|
===sow
|
89
100
|
User.sow
|
90
|
-
|
101
|
+
Will plant all the User records in the garden, which you can commit to your (D)VCS and deploy wherever.
|
102
|
+
|
103
|
+
|
104
|
+
==Things To Note
|
91
105
|
|
92
|
-
|
93
|
-
or just go into the rails console :D
|
94
|
-
and call
|
95
|
-
User.reap
|
96
|
-
to pull the records up out of the file and into your database.
|
106
|
+
Class.sow and instance.plant_seed both append yaml to a file. The practical implication of this is that you have to delete the file and then sow or plant_seed if you don't want the old stuff to come along with the new when you call reap. Be mindful of this.
|
97
107
|
|
108
|
+
It also means calling plant_seed repeatedly on the same object will put multiple copies of that object in your garden, and that reap will try and put multiple copies in your database. This will most likely fail spectacularly, and at least insidiously.
|
98
109
|
|
99
110
|
|
100
111
|
|