Skip to content

Change ActiveRecord::Migration to ActiveRecord::Migration[7.1] #788

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lenikadali
Copy link

  • Changed the line ActiveRecord::Migration to ActiveRecord::Migration[7.1] so that schema loading could work (it is now required for newer versions of Rails)
  • Updated and commented out the load schema task since it fails to find and run the loading of data into the database PostgreSQL container
  • Added the initialize_profile method and add it to the after_create portion of the User factory because of the NameError I encountered:
  • NameError: undefined local variable or method `init_profile' for #FactoryBot::SyntaxRunner:0x00007eaac2e3c560 (NameError)

Changed the line ActiveRecord::Migration to ActiveRecord::Migration[7.1]
so that schema loading could work (it is now required for newer versions
of Rails)

Updated and commented out the load schema task since it fails to find
and run the loading of data into the database PostgreSQL container

Added the initialize_profile method and add it to the `after_create`
portion of the User factory because of the NameError I encountered:

NameError: undefined local variable or method `init_profile'
for #<FactoryBot::SyntaxRunner:0x00007eaac2e3c560> (NameError)
Comment on lines +30 to +45
def initialize_profile
create_profile!(
checkin_reminder: true,
onboarding_step_id: "onboarding-personal",
most_recent_doses: {},
most_recent_conditions_positions: {},
most_recent_symptoms_positions: {},
most_recent_treatments_positions: {}
)
end

factory :user do
sequence(:email) { |number| "user#{number}@example.com" }
password { "password123" }
password_confirmation { "password123" }
after(:create) { initialize_profile }
Copy link
Author

Choose a reason for hiding this comment

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

Modified the User factory to have the init_profile model from the User model and renamed it to initialize_profile because of the error below:

Done.
bin/rails aborted!
NameError: undefined local variable or method `init_profile' for #<FactoryBot::SyntaxRunner:0x00007eaac2e3c560> (NameError)

    after(:create) { init_profile }
                     ^^^^^^^^^^^^
Did you mean?  initialize
/app/spec/factories/users.rb:45:in `block (3 levels) in <top (required)>'
/app/db/seeds/development/users.seeds.rb:4:in `block in evaluate'
/app/db/seeds/development/users.seeds.rb:3:in `each'
/app/db/seeds/development/users.seeds.rb:3:in `evaluate'
Tasks: TOP => db:seed => db:seed:development => db:seed:development:users
(See full trace by running task with --trace)

end
Rake::Task["db:structure:load"].invoke
#Rake::Task["db:schema:load"].invoke
Copy link
Author

@lenikadali lenikadali Mar 10, 2025

Choose a reason for hiding this comment

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

Had to comment out the db:schema:load task, after updating from db:structure:load since this was removed in Rails 6.2, in order to be able to run the rails app:setup command.

The error I got when I tried to run rails db:schema:load independently was:

psql:/app/db/structure.sql:60: ERROR:  relation "ar_internal_metadata" already exists
bin/rails aborted!
failed to execute:
psql --set ON_ERROR_STOP=1 --quiet --no-psqlrc --output /dev/null --file /app/db/structure.sql flaredown_development

Please check the output above for any errors and make sure that `psql` is installed in your PATH and has proper permissions.

/app/lib/tasks/app.rake:47:in `build_database'
/app/lib/tasks/app.rake:32:in `setup'
/app/lib/tasks/app.rake:4:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:schema:load
(See full trace by running task with --trace)

It seems psql needs to be installed in the Rails container in order for the schema loading to work. Not sure why since pg is in the backend/Gemfile and I would think that should cover the database connection needs for the app.

Copy link
Collaborator

@compwron compwron left a comment

Choose a reason for hiding this comment

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

This is looking good!!

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.

2 participants