Rails PG Extras
Apartment
Our great sponsors
Rails PG Extras | Apartment | |
---|---|---|
11 | 5 | |
1,074 | 2,648 | |
- | 0.7% | |
5.7 | 0.0 | |
2 months ago | about 2 months ago | |
Ruby | Ruby | |
MIT License | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
Rails PG Extras
-
What are your favourite approaches to keeping on top of Postgres health?
I use either PgHero or Rails PG Extras on every project
- rails-pg-extras introduces new API for measuring SQL queries generated by any Ruby snippet
-
Effective Queries with Rails and PostgreSQL
Your first impression may be that it's better to add indexes to every field in a database. However, first of all, only one of the defined indexes is working here (see the compound index section). Furthermore, indexes can slow down queries if there are not many records in the database, and each index takes up space in a computer's memory. Often, the size of the indexes may be larger than the amount of the data stored in a database. You can install the "rails-pg-extras" gem to get more information. I recommend that you carefully study the documentation of this gem, as it contains many useful functions that will make your work with the database as efficient as possible.
-
Best way to learn query optimization?
https://github.com/pawurb/rails-pg-extras is useful for identifying slow queries and generally things that could make queries slow.
- rails-pg-extras: a new release adds built-in dashboard interface
- rails-pg-extras - new release adds 'table_info' and 'index_info' methods displaying summary of useful metadata
- rails-pg-extras: new release allows generating a healthcheck report of your PostgreSQL database
Apartment
-
Figma's Databases team lived to tell the scale
I recall a popular rails gem[1] once upon a time that provided multi-tenancy via postgres schemas.
As it turns out, even the company the initially developed the gem ended up ditching the approach due to some of the issues you outlined above.
Managing separate schemas feels like one of those nefarious decisions that make things simple _initially_ but get you into a world of hurt when you need to scale. The company is since defunct but they have an article where they discuss why they ditched the approach [2], TL;DR it's too difficult to maintain and scale
[1] https://github.com/influitive/apartment#tenants-on-different...
-
Is there a way to have rails return a different set of data depending on the hostname?
Looks like you're trying to implement multi-tenancy. You might also want to look at the apartment gem.
-
Create views to display all data managed by apartment gem
One strategy of the apartment gem is to store tenant data in dedicated schemas in a Postgres database.
- restart rails app from controller action
-
How we found and fixed a rare race condition in our session handling - The GitHub Blog
The other issue I think was with Apartment tenant switching and ActiveRecord's column cache. Some tenants had the updated columns and others didn't. Also with Puma. People love them some Puma! Me, I go with Passenger. Well, if the requirements are right that is...
What are some alternatives?
Enumerize - Enumerated attributes with I18n and ActiveRecord/Mongoid support
Acts As Tennant - Easy multi-tenancy for Rails in a shared database setup.
marginalia - Attach comments to ActiveRecord's SQL queries
Milia - Easy multi-tenanting for Rails5 (or Rails4) + Devise
Awesome Nested Set - An awesome replacement for acts_as_nested_set and better_nested_set.
activerecord-multi-tenant - Rails/ActiveRecord support for distributed multi-tenant databases like Postgres+Citus
ActsAsList - An ActiveRecord plugin for managing lists.
rails_or - Cleaner syntax for writing OR Query in Rails 5, 6. And also add #or support to Rails 3 and 4.
Audited - Audited (formerly acts_as_audited) is an ORM extension that logs all changes to your Rails models.
pluck_all - A more efficient way to get data from database. Like #pluck method but return array of hashes instead.
Closure Tree - Easily and efficiently make your ActiveRecord models support hierarchies
SanitizeSqlLike - Backport #sanitize_sql_like method from Rails 4 for Rails 3. Sanitizes a string so that it is safe to use within an SQL LIKE statement.