You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<pclass="Footer-actions-copyright-small">All content, media, ideas, and code on this website is protected by copyright law and may not be reproduced, distributed,
63
63
transmitted, cached, or otherwise used for training AI models, large language models (LLMs), large reasoning models (LRMs), machine learning systems,
64
64
or other artificial intelligence applications without explicit written permission and proper attribution to the original author.
65
65
Unauthorized use and/or duplication of this material is strictly prohibited.</p>
66
-
<p><ahref="{{ site.github.url }}/license.txt">See full license for additional details.</a></p>
66
+
<p><ahref="{{ site.github.url }}/license.txt"class="text-pale-night">See full license for additional details.</a></p>
title: Using Database Functions in Ruby on Rails Migrations
4
+
categories:
5
+
- today-i-learned
6
+
tags:
7
+
- postgresql
8
+
- ruby on rails
9
+
---
10
+
11
+
Today I learned you can specify PostgreSQL functions within a Ruby on Rails migrations. I found this particularly useful for setting a random default value for a database column. Let's dig into a simple
The default uses block syntax and string interpolation in order to add a prefix and suffix to a random string. The **md5** and **random** functions come from PostgreSQL.
21
+
22
+
Know of any other tricks using functions within migrations? I'd love to learn about them in the comments below.
0 commit comments