Skip to content

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

Choose a reason for hiding this comment

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

I'm curious if it would work as intended if we put the db:migrate here, and then the schema:load within the Rails.env.development? block. I'm not sure if this is ran in our deploy process for production anyway, or this is generally just used for development purposes.

Copy link
Author

@lenikadali lenikadali Aug 15, 2025

Choose a reason for hiding this comment

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

I wouldn't know since I was running this for development setup purposes 🙃
Maybe the contributors who've deployed Flaredown in production can comment?

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!!

Copy link
Collaborator

@haydenrou haydenrou left a comment

Choose a reason for hiding this comment

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

thank you! Just left a couple of thoughts

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

Choose a reason for hiding this comment

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

I'm curious if it would work as intended if we put the db:migrate here, and then the schema:load within the Rails.env.development? block. I'm not sure if this is ran in our deploy process for production anyway, or this is generally just used for development purposes.

def change
create_table :positions do |t|
t.string :postal_code, null: false
t.string :location_name, null: false
t.decimal :latitude, {precision: 10, scale: 7}
t.decimal :longitude, {precision: 10, scale: 7}
#t.decimal :longitude, {precision: 10, scale: 7}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was this causing a problem?

Copy link
Author

Choose a reason for hiding this comment

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

Probably the migration was failing to go through with the field as is. Can check and confirm.

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.

None yet

3 participants