Skip to content

Conversation

@RocKhalil
Copy link
Contributor

This PR fixes an issue when generating a resource and the database connection is not working.
Currently, it creates an empty file, but with catching the error, it will generate the file with the default template:

class Avo::Resources::<%= resource_class %> < Avo::BaseResource
  self.includes = []<%= model_class_from_args %>
  # self.search = {
  #   query: -> { query.ransack(id_eq: params[:q], m: "or").result(distinct: false) }
  # }

  def fields
    field :id, as: :id
  end
end

@qlty-cloud-legacy
Copy link

qlty-cloud-legacy bot commented Jan 9, 2024

Code Climate has analyzed commit 6d5b00d and detected 0 issues on this pull request.

View more on Code Climate.

@adrianthedev
Copy link
Collaborator

Can you please remove all the style changes?

@RocKhalil RocKhalil force-pushed the bug-fixes/resource-generation branch from 1b36a25 to 9d61d92 Compare January 9, 2024 11:23
@adrianthedev adrianthedev requested a review from Paul-Bob January 9, 2024 11:39
Copy link
Contributor

@Paul-Bob Paul-Bob left a comment

Choose a reason for hiding this comment

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

It looks great, thanks for the contribution!

I was thinking if we should use the rescue_from at the class level and avoid repeating the rescue on multiple methods

rescue_from ActiveRecord::NoDatabaseError, with: :no_database_error
def no_database_error
  puts "Database not found, please create your database and regenerate the resource."
  []
end

The current state of the PR is good to merge IMO, just wondering about ☝️

Comment on lines 241 to 244
rescue ActiveRecord::NoDatabaseError
puts "Database not found, please create your database and regenerate the resource."
rescue ActiveRecord::ConnectionNotEstablished
puts "Database connection error, please create your database and regenerate the resource."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't these return emtpy arrays too?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not on this method, only if the exception start being rescued on model_db_columns

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct; so I have moved the rescue to model_db_columns instead

Copy link
Contributor

Choose a reason for hiding this comment

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

Good move since that's the origin of the exception.

Ready to merge 👌

@adrianthedev adrianthedev merged commit 7c299be into avo-hq:main Jan 11, 2024
@adrianthedev
Copy link
Collaborator

Thanks for the contribution @RocKhalil

@Paul-Bob Paul-Bob added the Fix label Jan 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants