-
Notifications
You must be signed in to change notification settings - Fork 0
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
Chore/new seeds #479
Chore/new seeds #479
Conversation
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.
Looks great.
When do you want to load the fixtures? To set up the dev environment?
@@ -38,7 +38,7 @@ class User < ApplicationRecord | |||
# Include default devise modules. | |||
TEMP_EMAIL_REGEX = /\Achange@tmp/ | |||
PERMISSIONS = %w[operator ngo ngo_manager government] | |||
PROTECTED_NICKNAMES = %w[admin superuser about root fti otp faq contact user operator ngo].freeze | |||
|
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.
ehehe.. this thing was already there when I grabbed the project (like, a month after it started) and I always wanted to removed it and never did.
Now it's done :D
@@ -0,0 +1,85 @@ | |||
require "active_record/fixtures" |
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.
I have no idea what this file does :D
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.
Sorry, I will add additional comment why it's here. When creating and then loading fixtures, I had foreign key exceptions, but in Rails 7 the exception has no details. In rails 7.1 this is fixed and you know which object is causing those errors, the error message is a way better. That's why I took that fragment of code from Rails 7.1 in form of extension here.
|
||
private | ||
|
||
def drop_e2e_db_template |
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.
mmm.. cool.
How do the PG templates work?
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.
I would say creating a database from template is like restoring from a backup but a way way faster. I can now in frontend applications after certain tests run those rake tasks and restore db to initial state with tests data in 1 or 2 seconds.
namespace :seeds do | ||
desc "Generate fixtures to use as development or e2e database. First run db:restore_from_file or db:restore_from_server to get latest data from production." | ||
task generate_fixtures: :environment do | ||
generate_for_model "Country" |
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.
Maybe save an array of models and iterate over them calling generate_for_model
?
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.
mmm... ok, I just saw later in the code that it won't work for all.
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.
Yeah, I started as you said, with array of models, then that changed to hash, but ended with this as this is the most flexible way.
9741258
to
3db4f8a
Compare
3db4f8a
to
d2452bc
Compare
Old seeds did not work. Instead of fixing them, I decided to use a subset of anonymized production data in the form of fixtures. Why fixtures? Because loading up fixtures in Rails is very quick and well-supported.
This will also allow using better test data for e2e testing in both Portal and Observation Tool applications. For this, I also added custom e2e environment and new rake tasks (e2e.rake). Recreating database between tests is much quicker now.
To recreate fixtures, you have to load production database locally and run: