If you have a :string or :text field, you should pair it with a model validation that restricts its length...
We can use ActiveRecord's where to add conditions to a relation. But sometimes our condition is not on the...
It's every developer's nightmare: SQL queries that get large and unwieldy. This can happen fairly quickly with the...
Was ist Elastic? Suchmaschine, basierend auf Apache Lucene größtenteils Open-Source einige kommerzielle Features ("Elastic Stack", früher "X-Pack") Zugriffsrechte...
Tod is a gem for working with daytimes. That's a tuple of (hour, minute second) without a day, month...
If you have a PostgreSQL dump in the custom format you can can view the text format dump (plain SQL...
To remove all tables from a database (but keep the database itself), you have two options. Option 1: Drop the...
When your code does not behave as expected, you can use a debugger statement ("breakpoint") at any point in your...
Migrating data from a legacy into a new system can be a surprisingly large undertaking. We have done this a...
When you have a large PG database, you may want to find out which tables are consuming the most disk...
The attached article explains options you have to store the order of items in a database table. The simplest solution...
Don't sum up columns with + in a sql-query if NULL-Values can be present. MySQL and PostgreSQL cannot...
You might have some trouble running a Rails LTS 2 app with MySQL 5.7. If you don't want to...
MySQL and MariaDB have an SQL mode setting which changes how MySQL behaves. The SQL mode value is comprised of...
mysql> SELECT @@global.version; +------------------+ | @@global.version | +------------------+ | 5.6.30 | +------------------+ 1 row in set (0,00 sec) MySQL 5.6 Reference Manual says "BLOB and TEXT...
You should avoid using application models in your migrations. But how else could you create records in a migration?
PostgreSQL's Common Table Expressions (CTEs) can be used to extract sub-queries from bulky SQL statements into a temporary...
PostgreSQL supports the SQL OVERLAPS operator. You can use it to test if two date ranges overlap: => SELECT ('2001-02...
I frequently find myself needing a combination of group_by, count and sort for quick statistics. Here's a method...
When using GROUP BY, MySQL now complains if the SELECT includes columns which are not part of the GROUP BY...
This card is just about creating simple PostgreSQL dumps. This is no instruction for a backup strategy nor a guide...
Like you know from "How to tell ActiveRecord how to preload associations (either JOINs or separate queries)", you can tell...
Instantiating ActiveRecord objects comes expensive. To speed up things, you can choose a more direct way to talk to your...
#reverse_order does not work with complex sorting constraints and may even silently create malformed SQL for rails < 5.