Skip to content

Rails: Mysql to Postgresql

Ben A. Morgan edited this page Jul 19, 2024 · 3 revisions

Precautions

  • Review all code that uses the sql GROUP BY. Mysql is liberal with GROUP BY (until 5.7) - it allows you to select a column that is not part of the GROUP BY clause, which is incorrect. Postgresql doesn't allow this.
  • Mysql LIKE is case insensitive. Postgresql is case sensitive. If your code depends on case insensitive matching, use ILIKE

Features to use

  • Database migrations are transactional in Postgres. This means, if a migration fails, it is rolled back entirely. This is a big win. (Nothing needs to be done to use this. Added just so we can be thankful)
  • INET columns - a column type to store IP addresses or versions (to achieve version comparison in db but requires three periods)
  • The UUID - if you need ids beyond the INT range or want count obfuscation
  • Partial indexes - useful for things like soft-delete. The index considers only the active rows. Results in better/faster indexing