File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed
Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments