Skip to content
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

Fix seeding #822

Merged
merged 4 commits into from
Aug 14, 2022
Merged

Fix seeding #822

merged 4 commits into from
Aug 14, 2022

Conversation

Taeir
Copy link
Contributor

@Taeir Taeir commented Aug 10, 2022

Previously, seeding the database runs into multiple issues.

  1. It does not seed models in the correct order, so some don't get added because their dependencies were not seeded yet.
  2. It does not create a "Question" post type because it fails validations. "Question" post type sets has_answer to true, and needs to refer to the "Answer" post type, so we need to first create the answer post type before we can create the "Question" post type.
  3. Creating a user succeeds, but an error is reported.
  4. The initially seeded categories do not have tag sets associated with them.

For the first, I have added a bit of code to prioritize models on which others depend.

For the second, I have flipped the order of the Post types in the file and added ids. The import scripts (and potentially some code) rely on the fact that id for the "Question" post type is 1 and that the id for the "Answer" post type is 2, therefore I added the ids to ensure they are set that way.

For the third point, I added a confirmed at date for the admin user to ensure that devise does not try to send a confirmation mail. Otherwise it crashes in devise/mailer/confirmation_instructions.html.erb on line 11 since there is no RequestContext while seeding.

For the last point, I added .id such that it actually gets the ids and not the instances.

Fixes #638

Taeir added 3 commits August 10, 2022 13:41
This ensures that types on which other models depend are created first.
This prevents an error during seeding in
devise/mailer/confirmation_instructions on line 11 since there is no
RequestContext while seeding.
Copy link
Member

@sau226 sau226 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

I ran this changeset through a dev environment, and it looks like everything "just works" now.

Unfortunately, I don't have merge access, so you'll need to wait until someone who does can merge it in.

@Taeir
Copy link
Contributor Author

Taeir commented Aug 14, 2022

I noticed another problem, tagsets were not getting linked to the initially seeded categories. I've added the fix for that too.

@ArtOfCode- ArtOfCode- merged commit 20c314a into codidact:develop Aug 14, 2022
@eip-ewi eip-ewi deleted the 638-fix-seeding branch August 27, 2022 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix category/post-type seeding
3 participants