The most common option is to let Rails pick the name for database constraints and indexes or let PostgreSQL use the defaults (when applicable). However, when defining custom names in Rails, or working in Go applications where no ORM is used, it is important to follow strict naming conventions to improve consistency and discoverability.
The table below describes the naming conventions for custom PostgreSQL constraints. The intent is not to retroactively change names in existing databases but rather ensure consistency of future changes.
|Check Constraint||The optional suffix should denote the type of validation, such as ||
|Exclusion Constraint||The optional suffix should denote the type of exclusion being performed.|
- Prefixes are preferred over suffices because they make it easier to identify the type of a given constraint quickly, as well as group them alphabetically;
_and_that joins column names can be omitted to keep the identifiers under the 63 characters’ length limit defined by PostgreSQL. Additionally, the notation may be abbreviated to the best of our ability if struggling to keep under this limit.
- For indexes added to solve a very specific problem, it may make sense for the name to reflect their use.