Sometimes we write plain SQL queries in migrations so we don't have to mock ActiveRecord classes. These two migrations...
The linked article points out that COUNT queries might be unexpectedly slow in PostgreSQL. If you just need to know...
When you repeat a subpattern with a *, + or {...} operator, you may choose between greedy, lazy and possessive modes. Switching modes...
PostgreSQL has partial indexes. With a partial index you tell Postgres to only index rows matching a given query.
We currently test most of our gems on Travis CI, but want to migrate those tests to Github Actions. This...
When loading a database dump created with pg_dump into your database, you might run into an error like
It sometimes happen that a database dump, that would want to insert into your development database, does not match the...
If you want to prevent that two processes run some code at the same time you can use the gem...
GoodJob is a new background worker gem. It's compatible with ActiveJob. We're huge fans of Sidekiq for its...
If you have a :string or :text field, you should pair it with a model validation that restricts its length...
TL;DR PostgreSQL handles Rails 4+ text and string columns the same. Some libraries may still reflect on the column...
We can use ActiveRecord's where to add conditions to a relation. But sometimes our condition is not on the...
PostgreSQL and ActiveRecord have a good support for storing dynamic attributes (hashes) in columns of type JSONB. But sometimes you...
It's every developer's nightmare: SQL queries that get large and unwieldy. This can happen fairly quickly with the...
As an application exists, data accumulates. While you'll be loosely monitoring the main models' record count, some supportive database...
Travis changed their default distribution from Ubuntu 14.04 (trusty) to 16.04 (precise). This might break your test setup for new...
When doing some meta-programming magic and you want to do something for all attributes of a class, you may...
For searching in large database tables we usually use PostgreSQL's fulltext search capabilities. While this works reasonably well for...
When restoring a PostgreSQL dump using pg_restore, you usually add the --clean flag to remove any existing data from...
To remove all tables from a database (but keep the database itself), you have two options. Option 1: Drop the...
When projects run for many years, they require special regular maintenance to stay fresh. This kind of maintenance is usually...
Setting array columns When using PostgreSQL array columns, you can set an array attribute to a value with square brackets...
When you need to store structured data (like Ruby hashes) in a single database column with ActiveRecord, a simple way...
When you have a large PG database, you may want to find out which tables are consuming the most disk...