Skip to content

Commit 3e7eca4

Browse files
committed
POST: Functions in PostgreSQL and Rails Migrations
* Fixed Gemfile versions * Updated footer link styling
1 parent cfe5f75 commit 3e7eca4

File tree

6 files changed

+179
-51
lines changed

6 files changed

+179
-51
lines changed

.tool-versions

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
ruby 3.1.4
1+
ruby 3.4.2
2+
bundler 2.7.1

Gemfile.lock

Lines changed: 136 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,195 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
addressable (2.8.5)
5-
public_suffix (>= 2.0.2, < 6.0)
6-
ast (2.4.2)
7-
base64 (0.1.1)
4+
addressable (2.8.7)
5+
public_suffix (>= 2.0.2, < 7.0)
6+
ast (2.4.3)
7+
base64 (0.3.0)
8+
bigdecimal (3.2.2)
89
colorator (1.1.0)
9-
concurrent-ruby (1.2.2)
10+
concurrent-ruby (1.3.5)
11+
csv (3.3.5)
1012
em-websocket (0.5.3)
1113
eventmachine (>= 0.12.9)
1214
http_parser.rb (~> 0)
1315
eventmachine (1.2.7)
14-
ffi (1.15.5)
16+
ffi (1.17.2)
17+
ffi (1.17.2-aarch64-linux-gnu)
18+
ffi (1.17.2-aarch64-linux-musl)
19+
ffi (1.17.2-arm-linux-gnu)
20+
ffi (1.17.2-arm-linux-musl)
21+
ffi (1.17.2-arm64-darwin)
22+
ffi (1.17.2-x86-linux-gnu)
23+
ffi (1.17.2-x86-linux-musl)
24+
ffi (1.17.2-x86_64-darwin)
25+
ffi (1.17.2-x86_64-linux-gnu)
26+
ffi (1.17.2-x86_64-linux-musl)
1527
forwardable-extended (2.6.0)
16-
google-protobuf (3.24.3)
28+
google-protobuf (4.31.1)
29+
bigdecimal
30+
rake (>= 13)
31+
google-protobuf (4.31.1-aarch64-linux-gnu)
32+
bigdecimal
33+
rake (>= 13)
34+
google-protobuf (4.31.1-aarch64-linux-musl)
35+
bigdecimal
36+
rake (>= 13)
37+
google-protobuf (4.31.1-arm64-darwin)
38+
bigdecimal
39+
rake (>= 13)
40+
google-protobuf (4.31.1-x86-linux-gnu)
41+
bigdecimal
42+
rake (>= 13)
43+
google-protobuf (4.31.1-x86-linux-musl)
44+
bigdecimal
45+
rake (>= 13)
46+
google-protobuf (4.31.1-x86_64-darwin)
47+
bigdecimal
48+
rake (>= 13)
49+
google-protobuf (4.31.1-x86_64-linux-gnu)
50+
bigdecimal
51+
rake (>= 13)
52+
google-protobuf (4.31.1-x86_64-linux-musl)
53+
bigdecimal
54+
rake (>= 13)
1755
http_parser.rb (0.8.0)
18-
i18n (1.14.1)
56+
i18n (1.14.7)
1957
concurrent-ruby (~> 1.0)
20-
jekyll (4.3.2)
58+
jekyll (4.4.1)
2159
addressable (~> 2.4)
60+
base64 (~> 0.2)
2261
colorator (~> 1.0)
62+
csv (~> 3.0)
2363
em-websocket (~> 0.5)
2464
i18n (~> 1.0)
2565
jekyll-sass-converter (>= 2.0, < 4.0)
2666
jekyll-watch (~> 2.0)
67+
json (~> 2.6)
2768
kramdown (~> 2.3, >= 2.3.1)
2869
kramdown-parser-gfm (~> 1.0)
2970
liquid (~> 4.0)
30-
mercenary (>= 0.3.6, < 0.5)
71+
mercenary (~> 0.3, >= 0.3.6)
3172
pathutil (~> 0.9)
3273
rouge (>= 3.0, < 5.0)
3374
safe_yaml (~> 1.0)
3475
terminal-table (>= 1.8, < 4.0)
3576
webrick (~> 1.7)
36-
jekyll-compose (0.11.0)
77+
jekyll-compose (0.12.0)
3778
jekyll (>= 3.7, < 5.0)
38-
jekyll-feed (0.12.1)
79+
jekyll-feed (0.17.0)
3980
jekyll (>= 3.7, < 5.0)
4081
jekyll-paginate (1.1.0)
41-
jekyll-redirect-from (0.15.0)
82+
jekyll-redirect-from (0.16.0)
4283
jekyll (>= 3.3, < 5.0)
43-
jekyll-sass-converter (3.0.0)
44-
sass-embedded (~> 1.54)
84+
jekyll-sass-converter (3.1.0)
85+
sass-embedded (~> 1.75)
4586
jekyll-seo-tag (2.8.0)
4687
jekyll (>= 3.8, < 5.0)
47-
jekyll-sitemap (1.3.1)
88+
jekyll-sitemap (1.4.0)
4889
jekyll (>= 3.7, < 5.0)
4990
jekyll-watch (2.2.1)
5091
listen (~> 3.0)
51-
json (2.6.3)
52-
kramdown (2.4.0)
53-
rexml
92+
json (2.13.2)
93+
kramdown (2.5.1)
94+
rexml (>= 3.3.9)
5495
kramdown-parser-gfm (1.1.0)
5596
kramdown (~> 2.0)
56-
language_server-protocol (3.17.0.3)
97+
language_server-protocol (3.17.0.5)
98+
lint_roller (1.1.0)
5799
liquid (4.0.4)
58-
listen (3.8.0)
100+
listen (3.9.0)
59101
rb-fsevent (~> 0.10, >= 0.10.3)
60102
rb-inotify (~> 0.9, >= 0.9.10)
61103
mercenary (0.4.0)
62-
parallel (1.23.0)
63-
parser (3.2.2.3)
104+
parallel (1.27.0)
105+
parser (3.3.9.0)
64106
ast (~> 2.4.1)
65107
racc
66108
pathutil (0.16.2)
67109
forwardable-extended (~> 2.6)
68-
public_suffix (5.0.3)
69-
racc (1.6.2)
110+
prism (1.4.0)
111+
public_suffix (6.0.2)
112+
racc (1.8.1)
70113
rainbow (3.1.1)
71-
rake (12.3.2)
114+
rake (13.3.0)
72115
rb-fsevent (0.11.2)
73-
rb-inotify (0.10.1)
116+
rb-inotify (0.11.1)
74117
ffi (~> 1.0)
75-
regexp_parser (2.8.1)
76-
rexml (3.2.6)
77-
rouge (4.1.3)
78-
rubocop (1.56.3)
79-
base64 (~> 0.1.1)
118+
regexp_parser (2.11.2)
119+
rexml (3.4.1)
120+
rouge (4.6.0)
121+
rubocop (1.79.2)
80122
json (~> 2.3)
81-
language_server-protocol (>= 3.17.0)
123+
language_server-protocol (~> 3.17.0.2)
124+
lint_roller (~> 1.1.0)
82125
parallel (~> 1.10)
83-
parser (>= 3.2.2.3)
126+
parser (>= 3.3.0.2)
84127
rainbow (>= 2.2.2, < 4.0)
85-
regexp_parser (>= 1.8, < 3.0)
86-
rexml (>= 3.2.5, < 4.0)
87-
rubocop-ast (>= 1.28.1, < 2.0)
128+
regexp_parser (>= 2.9.3, < 3.0)
129+
rubocop-ast (>= 1.46.0, < 2.0)
88130
ruby-progressbar (~> 1.7)
89-
unicode-display_width (>= 2.4.0, < 3.0)
90-
rubocop-ast (1.29.0)
91-
parser (>= 3.2.1.0)
131+
unicode-display_width (>= 2.4.0, < 4.0)
132+
rubocop-ast (1.46.0)
133+
parser (>= 3.3.7.2)
134+
prism (~> 1.4)
92135
ruby-progressbar (1.13.0)
93136
safe_yaml (1.0.5)
94-
sass-embedded (1.63.3)
95-
google-protobuf (~> 3.23)
96-
rake (>= 10.0.0)
137+
sass-embedded (1.90.0)
138+
google-protobuf (~> 4.31)
139+
rake (>= 13)
140+
sass-embedded (1.90.0-aarch64-linux-android)
141+
google-protobuf (~> 4.31)
142+
sass-embedded (1.90.0-aarch64-linux-gnu)
143+
google-protobuf (~> 4.31)
144+
sass-embedded (1.90.0-aarch64-linux-musl)
145+
google-protobuf (~> 4.31)
146+
sass-embedded (1.90.0-arm-linux-androideabi)
147+
google-protobuf (~> 4.31)
148+
sass-embedded (1.90.0-arm-linux-gnueabihf)
149+
google-protobuf (~> 4.31)
150+
sass-embedded (1.90.0-arm-linux-musleabihf)
151+
google-protobuf (~> 4.31)
152+
sass-embedded (1.90.0-arm64-darwin)
153+
google-protobuf (~> 4.31)
154+
sass-embedded (1.90.0-riscv64-linux-android)
155+
google-protobuf (~> 4.31)
156+
sass-embedded (1.90.0-riscv64-linux-gnu)
157+
google-protobuf (~> 4.31)
158+
sass-embedded (1.90.0-riscv64-linux-musl)
159+
google-protobuf (~> 4.31)
160+
sass-embedded (1.90.0-x86_64-darwin)
161+
google-protobuf (~> 4.31)
162+
sass-embedded (1.90.0-x86_64-linux-android)
163+
google-protobuf (~> 4.31)
164+
sass-embedded (1.90.0-x86_64-linux-gnu)
165+
google-protobuf (~> 4.31)
166+
sass-embedded (1.90.0-x86_64-linux-musl)
167+
google-protobuf (~> 4.31)
97168
terminal-table (3.0.2)
98169
unicode-display_width (>= 1.1.1, < 3)
99-
unicode-display_width (2.4.2)
100-
webrick (1.7.0)
170+
unicode-display_width (2.6.0)
171+
webrick (1.9.1)
101172

102173
PLATFORMS
174+
aarch64-linux-android
175+
aarch64-linux-gnu
176+
aarch64-linux-musl
177+
arm-linux-androideabi
178+
arm-linux-gnu
179+
arm-linux-gnueabihf
180+
arm-linux-musl
181+
arm-linux-musleabihf
182+
arm64-darwin
183+
riscv64-linux-android
184+
riscv64-linux-gnu
185+
riscv64-linux-musl
103186
ruby
187+
x86-linux-gnu
188+
x86-linux-musl
189+
x86_64-darwin
190+
x86_64-linux-android
191+
x86_64-linux-gnu
192+
x86_64-linux-musl
104193

105194
DEPENDENCIES
106195
jekyll (~> 4)
@@ -115,7 +204,7 @@ DEPENDENCIES
115204
webrick
116205

117206
RUBY VERSION
118-
ruby 3.1.4p223
207+
ruby 3.4.2p28
119208

120209
BUNDLED WITH
121-
2.1.4
210+
2.7.1

_includes/footer.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ <h2 class="FooterActions-title">Get in Contact with Me</h2>
5858
</div>
5959

6060
<section class="Footer-actions-copyright">
61-
<p>© 2011-{{ "now" | date: "%Y" }}+ Josh Frankel. {{ site.title }}. All rights reserved</p>
61+
<p class="Footer-actions-copyright-author">© 2011-{{ "now" | date: "%Y" }}+ Josh Frankel. {{ site.title }}. All rights reserved</p>
6262
<p class="Footer-actions-copyright-small">All content, media, ideas, and code on this website is protected by copyright law and may not be reproduced, distributed,
6363
transmitted, cached, or otherwise used for training AI models, large language models (LLMs), large reasoning models (LRMs), machine learning systems,
6464
or other artificial intelligence applications without explicit written permission and proper attribution to the original author.
6565
Unauthorized use and/or duplication of this material is strictly prohibited.</p>
66-
<p><a href="{{ site.github.url }}/license.txt">See full license for additional details.</a></p>
66+
<p><a href="{{ site.github.url }}/license.txt" class="text-pale-night">See full license for additional details.</a></p>
6767
</section>
6868
</div>
6969
</div>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
layout: post
3+
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
12+
example of this concept.
13+
14+
<!--excerpt-->
15+
16+
```ruby
17+
add_column :table, :column, :text, default: -> { "('prefix-' || md5(random()::text) || 'suffix')" }, null: false, if_not_exists: true
18+
```
19+
20+
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.
23+
24+
Thanks for reading!

_sass/_tailwindcss.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
color: #fff;
4242
}
4343

44+
.text-pale-night {
45+
color: $pale-night-text;
46+
}
47+
4448
/**
4549
* Borders
4650
**/

_sass/components/_footer.scss

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ $smallWidth: 790px;
6868
}
6969
}
7070
&-copyright {
71-
border-top: 1px solid $pale-light-gray;
71+
border-top: 2px solid $pale-light-gray;
7272
margin-top: 25px;
7373

7474
p {
@@ -77,12 +77,22 @@ $smallWidth: 790px;
7777
font-weight: 600;
7878
}
7979

80+
.Footer-actions-copyright-author {
81+
text-align: center;
82+
}
83+
8084
.Footer-actions-copyright-small {
8185
color: $pale-night-text;
8286
font-size: 1rem;
8387
font-style: italic;
8488
line-height: 1.5;
8589
}
90+
91+
a {
92+
&:hover {
93+
color: lighten($pale-night-text, 10%);
94+
}
95+
}
8696
}
8797
}
8898
}

0 commit comments

Comments
 (0)