Skip to content

Output number of table created from schema.rb or structure.sql, add polymorphic models count #37

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

Merged
merged 14 commits into from
May 30, 2025

Conversation

hmdros
Copy link
Contributor

@hmdros hmdros commented May 13, 2025

Closes #31

  • Add an entry to CHANGELOG.md that links to this PR under the "main (unreleased)" heading.

Description:

Adds to the output:

  • number of table created from schema.rb or structure.sql
  • STI count
  • polymorphic models count

I will abide by the code of conduct.

@hmdros hmdros force-pushed the print_schema_stats branch from 602404b to 8174700 Compare May 27, 2025 14:27
Copy link

codecov bot commented May 27, 2025

Codecov Report

Attention: Patch coverage is 84.74576% with 9 lines in your changes missing coverage. Please review.

Project coverage is 83.20%. Comparing base (8f3974d) to head (3a87be4).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
lib/rails_stats/console_formatter.rb 76.92% 3 Missing ⚠️
lib/rails_stats/json_formatter.rb 80.00% 3 Missing ⚠️
lib/rails_stats/stats_calculator.rb 90.32% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #37      +/-   ##
==========================================
+ Coverage   82.86%   83.20%   +0.33%     
==========================================
  Files          19       19              
  Lines         683      750      +67     
==========================================
+ Hits          566      624      +58     
- Misses        117      126       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hmdros hmdros force-pushed the print_schema_stats branch 3 times, most recently from 0f6be4b to baa9321 Compare May 27, 2025 16:47
@hmdros hmdros force-pushed the print_schema_stats branch from baa9321 to 4b93f2c Compare May 27, 2025 16:51
Copy link
Member

@etagwerker etagwerker left a comment

Choose a reason for hiding this comment

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

@hmdros Thanks for submitting this!

This is outside of the scope of #31:

STI models count: 1 STI classes

And it can be quite complex to implement.

Could you please submit a new issue about STIs?

I think we could merge this PR without the STIs code and then you can work on the STIs code in a separate PR.

Thank you!

@sti = 0
Dir.glob(File.join(@root_directory, "app", "models", "*.rb")).each do |file|
File.foreach(file) do |line|
if line =~ /class\s+(\w+)\s*<\s*(\w+)/ && !(line =~ /class\s+(\w+)\s*<\s*(ActiveRecord::Base|ApplicationRecord)/)
Copy link
Member

Choose a reason for hiding this comment

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

@hmdros I think this is too optimistic and it will generate false positives in certain applications.

Many projects use app/models as a place to put models that don't necessarily extend an ActiveRecord::Base|ApplicationRecord descendant.

I see that in your test you have this example:

class Pets < User
end

That's certainly an STI.

But what if someone has this in their app/models directory:

class Pets < User
end

And then:

class User 
...
end

That is not an STI and it will be counted as one (or two?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do agree that this can get confusing and the code to check this would need to be extra careful for this. I can try to get this in a different PR then. Removing

@hmdros hmdros changed the title Output number of table created from schema.rb or structure.sql, add STI count add polymorphic models count Output number of table created from schema.rb or structure.sql, add polymorphic models count May 29, 2025
@hmdros hmdros requested a review from etagwerker May 29, 2025 16:47
@etagwerker etagwerker merged commit e533d14 into main May 30, 2025
0 of 4 checks passed
@etagwerker etagwerker deleted the print_schema_stats branch May 30, 2025 01:44
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.

Idea: Output number of tables (and columns?)
3 participants