-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WiP] global.seeds.rb prereq file support #70
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
## 0.5.0 | ||
* `db/global.seeds.rb` will always be run before all other seeds |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,13 +36,18 @@ def define_seed_task(seed_file, *args) | |
|
||
task.add_description "Load the seed data from #{relative_file}" | ||
add_environment_dependency(task) | ||
add_global_dependency(task) | ||
task.name | ||
end | ||
|
||
def original_seeds_file | ||
@_seedbank_original ||= existent(Pathname.new('../seeds.rb').expand_path(seeds_root)) | ||
end | ||
|
||
def global_seeds_file | ||
@_seedbank_global ||= existent(Pathname.new('../global.seeds.rb').expand_path(seeds_root)) | ||
end | ||
|
||
def seeds_root | ||
Pathname.new Seedbank.seeds_root | ||
end | ||
|
@@ -70,6 +75,13 @@ def add_environment_dependency(task) | |
end | ||
end | ||
|
||
def add_global_dependency(task) | ||
if global_seeds_file | ||
define_seed_task(global_seeds_file) | ||
task.enhance(['db:seed_global']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
end | ||
end | ||
|
||
def runner | ||
@_seedbank_runner ||= Seedbank::Runner.new | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ namespace :db do | |
common_dependencies.unshift('db:seed:original') | ||
end | ||
|
||
desc "Load the seed data from db/seeds.rb and db/seeds/#{Seedbank.matcher}." | ||
desc "Load the seed data from db/global.seeds.rb, db/seeds.rb and db/seeds/#{Seedbank.matcher}." | ||
task 'common' => common_dependencies | ||
|
||
# Glob through the directories under seeds_path and create a task for each adding it to the dependency list. | ||
|
@@ -24,15 +24,15 @@ namespace :db do | |
|
||
environment_dependencies = seed_tasks_matching(environment, Seedbank.matcher) | ||
|
||
desc "Load the seed data from db/seeds.rb, db/seeds/#{Seedbank.matcher} and db/seeds/#{environment}/#{Seedbank.matcher}." | ||
desc "Load the seed data from db/global.seeds.rb, db/seeds.rb, db/seeds/#{Seedbank.matcher} and db/seeds/#{environment}/#{Seedbank.matcher}." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [147/132] |
||
task environment => ['db:seed:common'] + environment_dependencies | ||
|
||
override_dependency << "db:seed:#{environment}" if defined?(Rails) && Rails.env == environment | ||
end | ||
end | ||
|
||
# Override db:seed to run all the common and environments seeds plus the original db:seed. | ||
desc %(Load the seed data from db/seeds.rb, db/seeds/#{Seedbank.matcher} and db/seeds/ENVIRONMENT/#{Seedbank.matcher}. | ||
desc %(Load the seed data from db/global.seeds.rb, db/seeds.rb, db/seeds/#{Seedbank.matcher} and db/seeds/ENVIRONMENT/#{Seedbank.matcher}. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [140/132] |
||
ENVIRONMENT is the current Rails.env.) | ||
override_seed_task seed: override_dependency | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ def self.glob_dummy_seeds | |
it 'creates all the seed tasks' do | ||
seeds = %w[db:seed:circular1 db:seed:circular2 db:seed:common db:seed:dependency db:seed:dependency2 | ||
db:seed:dependent db:seed:dependent_on_nested db:seed:dependent_on_several db:seed:development | ||
db:seed:development:users db:seed:no_block db:seed:original db:seed:reference_memos db:seed:with_block_memo db:seed:with_inline_memo] | ||
db:seed:development:users db:seed:global db:seed:no_block db:seed:original db:seed:reference_memos db:seed:with_block_memo db:seed:with_inline_memo] | ||
|
||
subject.map(&:to_s).must_equal seeds | ||
end | ||
|
@@ -35,7 +35,7 @@ def self.glob_dummy_seeds | |
subject { Rake.application.lookup(['db', 'seed', seed].join(':')) } | ||
|
||
it 'is dependent on db:abort_if_pending_migrations' do | ||
subject.prerequisites.must_equal %w[db:abort_if_pending_migrations] | ||
subject.prerequisites.must_equal %w[db:abort_if_pending_migrations db:seed:global] | ||
end | ||
end | ||
end | ||
|
@@ -66,7 +66,7 @@ def setup | |
end | ||
|
||
it 'is dependent on only the common seeds' do | ||
prerequisite_seeds = self.class.glob_dummy_seeds.sort.map do |seed_file| | ||
prerequisite_seeds = ['db:seed:global'] + self.class.glob_dummy_seeds.sort.map do |seed_file| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
['db', 'seed', File.basename(seed_file, '.seeds.rb')].join(':') | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming/MemoizedInstanceVariableName: Memoized variable @_seedbank_global does not match method name global_seeds_file. Use @global_seeds_file instead.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.