Skip to content

Commit dead112

Browse files
authored
Merge pull request #1128 from landongrindheim/1125-update-existing-timestamps
1125 update existing timestamps
2 parents d5b2b25 + 2ca4124 commit dead112

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
defmodule CodeCorps.Repo.Migrations.UpdateNullTaskValuesFromGithubIntegration do
2+
use Ecto.Migration
3+
4+
@consecutive_whitespace_regex ~r/\s+/
5+
6+
def up do
7+
execute created_at_update()
8+
execute created_from_update()
9+
10+
execute modified_at_update()
11+
execute modified_from_update()
12+
end
13+
14+
def down do
15+
# no-op
16+
end
17+
18+
defp created_at_update do
19+
squish(
20+
"""
21+
UPDATE tasks
22+
SET created_at = inserted_at
23+
WHERE created_at IS NULL
24+
"""
25+
)
26+
end
27+
28+
defp created_from_update do
29+
squish(
30+
"""
31+
UPDATE tasks
32+
SET created_from = 'code_corps'
33+
WHERE created_from IS NULL
34+
"""
35+
)
36+
end
37+
38+
defp modified_at_update do
39+
squish(
40+
"""
41+
UPDATE tasks
42+
SET modified_at = updated_at
43+
WHERE modified_at IS NULL
44+
"""
45+
)
46+
end
47+
48+
defp modified_from_update do
49+
squish(
50+
"""
51+
UPDATE tasks
52+
SET modified_from = 'code_corps'
53+
WHERE modified_from IS NULL
54+
"""
55+
)
56+
end
57+
58+
defp squish(query) do
59+
String.replace(query, @consecutive_whitespace_regex, " ") |> String.trim
60+
end
61+
end
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
defmodule CodeCorps.Repo.Migrations.UpdateNullCommentValuesFromGithubIntegrations do
2+
use Ecto.Migration
3+
4+
@consecutive_whitespace_regex ~r/\s+/
5+
6+
def up do
7+
execute created_at_update()
8+
execute created_from_update()
9+
10+
execute modified_at_update()
11+
execute modified_from_update()
12+
end
13+
14+
def down do
15+
# no-op
16+
end
17+
18+
defp created_at_update do
19+
squish(
20+
"""
21+
UPDATE comments
22+
SET created_at = inserted_at
23+
WHERE created_at IS NULL
24+
"""
25+
)
26+
end
27+
28+
defp created_from_update do
29+
squish(
30+
"""
31+
UPDATE comments
32+
SET created_from = 'code_corps'
33+
WHERE created_from IS NULL
34+
"""
35+
)
36+
end
37+
38+
defp modified_at_update do
39+
squish(
40+
"""
41+
UPDATE comments
42+
SET modified_at = updated_at
43+
WHERE modified_at IS NULL
44+
"""
45+
)
46+
end
47+
48+
defp modified_from_update do
49+
squish(
50+
"""
51+
UPDATE comments
52+
SET modified_from = 'code_corps'
53+
WHERE modified_from IS NULL
54+
"""
55+
)
56+
end
57+
58+
defp squish(query) do
59+
String.replace(query, @consecutive_whitespace_regex, " ") |> String.trim
60+
end
61+
end

0 commit comments

Comments
 (0)