-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example_data:generate task and run on deploying review apps
- Loading branch information
1 parent
341c20a
commit ac3cb1b
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace :example_data do | ||
desc "Create example data for testing" | ||
task generate: :environment do | ||
if HostingEnvironment.production? | ||
raise "THIS TASK CANNOT BE RUN IN PRODUCTION" | ||
end | ||
|
||
if ChildrensBarredListEntry.any? | ||
puts "Noop as DB already contains data" | ||
exit | ||
end | ||
|
||
# Running `bundle exec rails db:migrate example_data:generate` can sometimes | ||
# use cached column information. This forces rails to reload column | ||
# information before attempting to generate factories | ||
ChildrensBarredListEntry.reset_column_information | ||
|
||
FactoryBot.create(:childrens_barred_list_entry, date_of_birth: Date.new(1980, 1, 1)) | ||
end | ||
end |