seedbank 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -12
- data/lib/seedbank/dsl.rb +1 -1
- data/lib/tasks/seed.rake +6 -4
- data/seedbank.gemspec +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -4,7 +4,13 @@ Seedbank
|
|
4
4
|
Seedbank allows you to structure your Rails seed data instead of having it all dumped into one large file. I find my seed data tended to fall into two categories. 1. Stuff that the entire application requires. 2. Stuff to populate my development and staging environments.
|
5
5
|
|
6
6
|
Seedbank assumes common seed data is under db/seeds and any directories under db/seeds/ are specific to an environment, so db/seeds/development is contains all your development only seed data.
|
7
|
-
|
7
|
+
|
8
|
+
The reason behind Seedbank is laziness. When I checkout or re-visit a project I don't want to mess around getting my environment setup I just want the code and a database loaded with data in a known state. Since the Rails core team were good enough to give us rake db:setup it would be rude not to use it.
|
9
|
+
|
10
|
+
rake db:setup # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first)
|
11
|
+
|
12
|
+
To achieve this slothful aim Seedbank renames the original db:seed rake task to db:seed:original, makes it a dependency for all the Seedbank seeds and adds a new db:seed task that loads all the common seeds in db/seeds plus all the seeds for the current Rails environment.
|
13
|
+
|
8
14
|
Example
|
9
15
|
=======
|
10
16
|
|
@@ -18,11 +24,12 @@ Seedbank seeds follow this structure;
|
|
18
24
|
|
19
25
|
This would generate the following Rake tasks
|
20
26
|
|
21
|
-
rake db:seed #
|
22
|
-
rake db:seed:bar #
|
23
|
-
rake db:seed:
|
24
|
-
rake db:seed:development
|
25
|
-
rake db:seed:
|
27
|
+
rake db:seed # Load the seed data from db/seeds.rb, db/seeds/*.seeds.rb and db/seeds/ENVIRONMENT/*.seeds.rb. ENVIRONMENT is the current environment in Rails.env.
|
28
|
+
rake db:seed:bar # Load the seed data from db/seeds/bar.seeds.rb
|
29
|
+
rake db:seed:common # Load the seed data from db/seeds.rb and db/seeds/*.seeds.rb.
|
30
|
+
rake db:seed:development # Load the seed data from db/seeds.rb, db/seeds/*.seeds.rb and db/seeds/development/*.seeds.rb.
|
31
|
+
rake db:seed:development:users # Load the seed data from db/seeds/development/users.seeds.rb
|
32
|
+
rake db:seed:foo # Load the seed data from db/seeds/foo.seeds.rb
|
26
33
|
rake db:seed:original # Load the seed data from db/seeds.rb
|
27
34
|
|
28
35
|
Therefor assuming RAILS_ENV is not set or is 'development'
|
@@ -35,12 +42,6 @@ would load the seeds in db/seeds.rb, db/seeds/bar.seeds.rb, db/seeds/foo.seeds/r
|
|
35
42
|
|
36
43
|
would load the seeds in db/seeds.rb, db/seeds/bar.seeds.rb and db/seeds/foo.seeds/rb
|
37
44
|
|
38
|
-
The reason behind Seedbank is laziness. When I checkout or re-visit a project I don't want to mess around getting my environment setup I just want the code and a database loaded with data in a known state. Since the Rails core team were good enough to give us rake db:setup it would be rude not to use it.
|
39
|
-
|
40
|
-
rake db:setup # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first)
|
41
|
-
|
42
|
-
To achieve this slothful aim Seedbank renames the original db:seed rake task to db:seed:original, makes it a dependency for all the Seedbank seeds and adds a new db:seed task that loads all the common seeds in db/seeds plus all the seeds for the current Rails environment.
|
43
|
-
|
44
45
|
Installation
|
45
46
|
============
|
46
47
|
|
data/lib/seedbank/dsl.rb
CHANGED
@@ -17,7 +17,7 @@ module Seedbank
|
|
17
17
|
|
18
18
|
args = { fq_name => 'db:abort_if_pending_migrations' }
|
19
19
|
task = Rake::Task.define_task(args) { load(seed_file) if File.exist?(seed_file) }
|
20
|
-
task.add_description "
|
20
|
+
task.add_description "Load the seed data from #{seed_file}"
|
21
21
|
fq_name
|
22
22
|
end
|
23
23
|
|
data/lib/tasks/seed.rake
CHANGED
@@ -12,7 +12,7 @@ namespace :db do
|
|
12
12
|
common_dependencies << define_seed_task(seed_file)
|
13
13
|
end
|
14
14
|
|
15
|
-
desc "
|
15
|
+
desc "Load the seed data from db/seeds.rb and db/seeds/*.seeds.rb."
|
16
16
|
task ['seed', 'common'] => base_dependencies + common_dependencies
|
17
17
|
|
18
18
|
# Glob through the directories under seeds_path assuming they are all environments
|
@@ -26,7 +26,9 @@ namespace :db do
|
|
26
26
|
environment_dependencies << define_seed_task(seed_file)
|
27
27
|
end
|
28
28
|
|
29
|
-
desc
|
29
|
+
desc <<-EOT
|
30
|
+
Load the seed data from db/seeds.rb, db/seeds/*.seeds.rb and db/seeds/#{environment}/*.seeds.rb.
|
31
|
+
EOT
|
30
32
|
task ['seed', environment] => ['db:seed:common'] + environment_dependencies
|
31
33
|
|
32
34
|
override_dependency << "db:seed:#{environment}" if Rails.env == environment
|
@@ -34,8 +36,8 @@ namespace :db do
|
|
34
36
|
|
35
37
|
# Change db:seed task to run all the base seeds tasks defined above.
|
36
38
|
desc <<-EOT
|
37
|
-
|
38
|
-
|
39
|
+
Load the seed data from db/seeds.rb, db/seeds/*.seeds.rb and db/seeds/ENVIRONMENT/*.seeds.rb.
|
40
|
+
ENVIRONMENT is the current environment in Rails.env.
|
39
41
|
EOT
|
40
42
|
override_task :seed => ['db:seed:common'] + override_dependency
|
41
43
|
|
data/seedbank.gemspec
CHANGED