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

Dev seed (small.en) leads to error #1049

Closed
twothreenine opened this issue Mar 2, 2024 · 4 comments
Closed

Dev seed (small.en) leads to error #1049

twothreenine opened this issue Mar 2, 2024 · 4 comments

Comments

@twothreenine
Copy link
Contributor

When I try to set Foodsoft up for development via Docker and run

docker compose -f docker-compose-dev.yml run --rm foodsoft \
  bundle exec rake db:schema:load db:seed:small.en

I get

ActiveRecord::InvalidForeignKey: Mysql2::Error: Cannot delete or update a parent row: a foreign key constraint fails

This can be solved by:

  1. skipping this step and starting the container, accessing http://localhost:2080 (phpMyAdmin) and deleting all tables (development -> select all tables -> delete)
  2. There's an error that active_storage_blobs couldn't be deleted (similar error as above), trying again to delete all tables succeeds
    ... and then I forgot how we solved it
@yksflip
Copy link
Member

yksflip commented Mar 8, 2024

yeah I can reproduce this error. Look's like that the FinancialTransactionClass is already created somewhere else and then this fails in the seed as the key/name is already taken

@lentschi
Copy link
Contributor

lentschi commented Mar 8, 2024

It seems that rake db:schema:load is not intended to always succeed for existing dbs - see discussion here:
rails/rails#41491

Since rake foodsoft:setup_development_docker already ran rake db:setup (which includes schema loading and minimal seeding) it cannot be run again without first emptying the db.

@yksflip
Copy link
Member

yksflip commented Mar 8, 2024

ah okay, so we could either try to rewrite the seeds to check whether these initial records already exists (find_or_create_by doesn't work with the uniqueness constraint somehow rails#36027, but first_or_create worked for me) or we add a note to the docs that you'd have to recreate a plain database first before loading seeds

@lentschi
Copy link
Contributor

lentschi commented Mar 8, 2024

or we add a note to the docs that you'd have to recreate a plain database first before loading seeds

Seems like the easiest path, however...:
rake db:drop db:create db:schema:load db:seed:small.en fails as db:create doesn't work in our current docker setup (the connection string includes the development db). So the user would always have a manual step here.

So maybe your other approach would be the easiest way to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants