|
| 1 | +defmodule Plausible.IngestRepo.Migrations.RemapSourcesV2 do |
| 2 | + use Ecto.Migration |
| 3 | + |
| 4 | + @mappings %{ |
| 5 | + # UTM sources |
| 6 | + "fb" => "Facebook", |
| 7 | + "fb-ads" => "Facebook", |
| 8 | + "fbads" => "Facebook", |
| 9 | + "fbad" => "Facebook", |
| 10 | + "facebook-ads" => "Facebook", |
| 11 | + "facebook_ads" => "Facebook", |
| 12 | + "fcb" => "Facebook", |
| 13 | + "facebook_ad" => "Facebook", |
| 14 | + "facebook_feed_ad" => "Facebook", |
| 15 | + "ig" => "Instagram", |
| 16 | + "yt" => "Youtube", |
| 17 | + "yt-ads" => "Youtube", |
| 18 | + "reddit-ads" => "Reddit", |
| 19 | + "google_ads" => "Google", |
| 20 | + "google-ads" => "Google", |
| 21 | + "googleads" => "Google", |
| 22 | + "gads" => "Google", |
| 23 | + "google ads" => "Google", |
| 24 | + "adwords" => "Google", |
| 25 | + "twitter-ads" => "Twitter", |
| 26 | + "tiktokads" => "TikTok", |
| 27 | + "tik.tok" => "TikTok", |
| 28 | + "perplexity" => "Perplexity", |
| 29 | + "linktree" => "Linktree", |
| 30 | + |
| 31 | + # Referrers |
| 32 | + "android-app://com.reddit.frontpage" => "Reddit", |
| 33 | + "perplexity.ai" => "Perplexity", |
| 34 | + "search.brave.com" => "Brave", |
| 35 | + "yandex.com.tr" => "Yandex", |
| 36 | + "yandex.kz" => "Yandex", |
| 37 | + "ya.ru" => "Yandex", |
| 38 | + "yandex.uz" => "Yandex", |
| 39 | + "yandex.fr" => "Yandex", |
| 40 | + "yandex.eu" => "Yandex", |
| 41 | + "yandex.tm" => "Yandex", |
| 42 | + "discord.com" => "Discord", |
| 43 | + "t.me" => "Telegram", |
| 44 | + "webk.telegram.org" => "Telegram", |
| 45 | + "sogou.com" => "Sogou", |
| 46 | + "m.sogou.com" => "Sogou", |
| 47 | + "wap.sogou.com" => "Sogou", |
| 48 | + "canary.discord.com" => "Discord", |
| 49 | + "ptb.discord.com" => "Discord", |
| 50 | + "discordapp.com" => "Discord", |
| 51 | + "linktr.ee" => "Linktree", |
| 52 | + "baidu.com" => "Baidu", |
| 53 | + "statics.teams.cdn.office.net" => "Microsoft Teams", |
| 54 | + "ntp.msn.com" => "Bing", |
| 55 | + "en.wikipedia.org" => "Wikipedia", |
| 56 | + "en.m.wikipedia.org" => "Wikipedia", |
| 57 | + "de.wikipedia.org" => "Wikipedia", |
| 58 | + "de.m.wikipedia.org" => "Wikipedia", |
| 59 | + "fr.wikipedia.org" => "Wikipedia", |
| 60 | + "ru.wikipedia.org" => "Wikipedia", |
| 61 | + "fr.m.wikipedia.org" => "Wikipedia", |
| 62 | + "es.wikipedia.org" => "Wikipedia", |
| 63 | + "ja.wikipedia.org" => "Wikipedia", |
| 64 | + "nl.wikipedia.org" => "Wikipedia", |
| 65 | + "ru.m.wikipedia.org" => "Wikipedia", |
| 66 | + "da.m.wikipedia.org" => "Wikipedia", |
| 67 | + "no.wikipedia.org" => "Wikipedia", |
| 68 | + "es.m.wikipedia.org" => "Wikipedia", |
| 69 | + "it.wikipedia.org" => "Wikipedia", |
| 70 | + "nl.m.wikipedia.org" => "Wikipedia", |
| 71 | + "da.wikipedia.org" => "Wikipedia", |
| 72 | + "sv.wikipedia.org" => "Wikipedia", |
| 73 | + "it.m.wikipedia.org" => "Wikipedia", |
| 74 | + "zh.wikipedia.org" => "Wikipedia", |
| 75 | + "sv.m.wikipedia.org" => "Wikipedia", |
| 76 | + "no.m.wikipedia.org" => "Wikipedia", |
| 77 | + "fi.m.wikipedia.org" => "Wikipedia", |
| 78 | + "fi.wikipedia.org" => "Wikipedia", |
| 79 | + "ca.wikipedia.org" => "Wikipedia", |
| 80 | + "ja.m.wikipedia.org" => "Wikipedia", |
| 81 | + "pt.wikipedia.org" => "Wikipedia", |
| 82 | + "pl.wikipedia.org" => "Wikipedia", |
| 83 | + "pt.m.wikipedia.org" => "Wikipedia", |
| 84 | + "cs.wikipedia.org" => "Wikipedia", |
| 85 | + "zh.m.wikipedia.org" => "Wikipedia", |
| 86 | + "ca.m.wikipedia.org" => "Wikipedia", |
| 87 | + "pl.m.wikipedia.org" => "Wikipedia", |
| 88 | + "cs.m.wikipedia.org" => "Wikipedia", |
| 89 | + "is.wikipedia.org" => "Wikipedia", |
| 90 | + "ko.wikipedia.org" => "Wikipedia", |
| 91 | + "uk.wikipedia.org" => "Wikipedia", |
| 92 | + "is.m.wikipedia.org" => "Wikipedia", |
| 93 | + "he.m.wikipedia.org" => "Wikipedia", |
| 94 | + "tr.wikipedia.org" => "Wikipedia", |
| 95 | + "he.wikipedia.org" => "Wikipedia", |
| 96 | + "id.m.wikipedia.org" => "Wikipedia", |
| 97 | + "tr.m.wikipedia.org" => "Wikipedia", |
| 98 | + "et.wikipedia.org" => "Wikipedia", |
| 99 | + "fa.m.wikipedia.org" => "Wikipedia", |
| 100 | + "uk.m.wikipedia.org" => "Wikipedia", |
| 101 | + "simple.wikipedia.org" => "Wikipedia", |
| 102 | + "ko.m.wikipedia.org" => "Wikipedia", |
| 103 | + "id.wikipedia.org" => "Wikipedia", |
| 104 | + "hr.m.wikipedia.org" => "Wikipedia", |
| 105 | + "simple.m.wikipedia.org" => "Wikipedia", |
| 106 | + "vi.wikipedia.org" => "Wikipedia", |
| 107 | + "el.wikipedia.org" => "Wikipedia", |
| 108 | + "hr.wikipedia.org" => "Wikipedia", |
| 109 | + "sk.wikipedia.org" => "Wikipedia", |
| 110 | + "hu.wikipedia.org" => "Wikipedia", |
| 111 | + "hu.m.wikipedia.org" => "Wikipedia", |
| 112 | + "fa.wikipedia.org" => "Wikipedia", |
| 113 | + "el.m.wikipedia.org" => "Wikipedia", |
| 114 | + "arz.m.wikipedia.org" => "Wikipedia", |
| 115 | + "th.m.wikipedia.org" => "Wikipedia", |
| 116 | + "ta.m.wikipedia.org" => "Wikipedia", |
| 117 | + "ga.wikipedia.org" => "Wikipedia", |
| 118 | + "et.m.wikipedia.org" => "Wikipedia", |
| 119 | + "vi.m.wikipedia.org" => "Wikipedia", |
| 120 | + "ro.wikipedia.org" => "Wikipedia", |
| 121 | + "ro.m.wikipedia.org" => "Wikipedia", |
| 122 | + "ms.m.wikipedia.org" => "Wikipedia", |
| 123 | + "bs.m.wikipedia.org" => "Wikipedia", |
| 124 | + "az.m.wikipedia.org" => "Wikipedia", |
| 125 | + "bg.m.wikipedia.org" => "Wikipedia", |
| 126 | + "nn.wikipedia.org" => "Wikipedia", |
| 127 | + "bg.wikipedia.org" => "Wikipedia", |
| 128 | + "ml.m.wikipedia.org" => "Wikipedia", |
| 129 | + "bn.m.wikipedia.org" => "Wikipedia", |
| 130 | + "sl.wikipedia.org" => "Wikipedia", |
| 131 | + "nn.m.wikipedia.org" => "Wikipedia", |
| 132 | + "sk.m.wikipedia.org" => "Wikipedia", |
| 133 | + "ms.wikipedia.org" => "Wikipedia", |
| 134 | + "uz.wikipedia.org" => "Wikipedia", |
| 135 | + "th.wikipedia.org" => "Wikipedia", |
| 136 | + "sr.m.wikipedia.org" => "Wikipedia", |
| 137 | + "hi.m.wikipedia.org" => "Wikipedia", |
| 138 | + "eu.wikipedia.org" => "Wikipedia", |
| 139 | + "uz.m.wikipedia.org" => "Wikipedia", |
| 140 | + "sr.wikipedia.org" => "Wikipedia", |
| 141 | + "lv.wikipedia.org" => "Wikipedia", |
| 142 | + "la.wikipedia.org" => "Wikipedia", |
| 143 | + "sl.m.wikipedia.org" => "Wikipedia", |
| 144 | + "arz.wikipedia.org" => "Wikipedia", |
| 145 | + "ta.wikipedia.org" => "Wikipedia", |
| 146 | + "ka.m.wikipedia.org" => "Wikipedia", |
| 147 | + "ga.m.wikipedia.org" => "Wikipedia", |
| 148 | + "lt.wikipedia.org" => "Wikipedia", |
| 149 | + "lv.m.wikipedia.org" => "Wikipedia", |
| 150 | + "kk.m.wikipedia.org" => "Wikipedia", |
| 151 | + "lt.m.wikipedia.org" => "Wikipedia", |
| 152 | + "ar.wikipedia.org" => "Wikipedia", |
| 153 | + "eo.wikipedia.org" => "Wikipedia", |
| 154 | + "sw.m.wikipedia.org" => "Wikipedia", |
| 155 | + "sh.wikipedia.org" => "Wikipedia", |
| 156 | + "bs.wikipedia.org" => "Wikipedia", |
| 157 | + "ml.wikipedia.org" => "Wikipedia", |
| 158 | + "hy.wikipedia.org" => "Wikipedia", |
| 159 | + "ka.wikipedia.org" => "Wikipedia", |
| 160 | + "hi.wikipedia.org" => "Wikipedia", |
| 161 | + "la.m.wikipedia.org" => "Wikipedia", |
| 162 | + "bn.wikipedia.org" => "Wikipedia", |
| 163 | + "ur.m.wikipedia.org" => "Wikipedia", |
| 164 | + "sh.m.wikipedia.org" => "Wikipedia", |
| 165 | + "az.wikipedia.org" => "Wikipedia", |
| 166 | + "si.m.wikipedia.org" => "Wikipedia", |
| 167 | + "sq.wikipedia.org" => "Wikipedia", |
| 168 | + "zh-yue.wikipedia.org" => "Wikipedia", |
| 169 | + "ckb.m.wikipedia.org" => "Wikipedia", |
| 170 | + "kn.wikipedia.org" => "Wikipedia", |
| 171 | + "lij.wikipedia.org" => "Wikipedia", |
| 172 | + "fy.wikipedia.org" => "Wikipedia", |
| 173 | + "lij.m.wikipedia.org" => "Wikipedia", |
| 174 | + "hy.m.wikipedia.org" => "Wikipedia", |
| 175 | + "mn.m.wikipedia.org" => "Wikipedia", |
| 176 | + "ar.m.wikipedia.org" => "Wikipedia", |
| 177 | + "tl.wikipedia.org" => "Wikipedia", |
| 178 | + "eu.m.wikipedia.org" => "Wikipedia", |
| 179 | + "fo.wikipedia.org" => "Wikipedia", |
| 180 | + "mn.wikipedia.org" => "Wikipedia", |
| 181 | + "mr.wikipedia.org" => "Wikipedia", |
| 182 | + "zh-classical.wikipedia.org" => "Wikipedia", |
| 183 | + "cy.wikipedia.org" => "Wikipedia", |
| 184 | + "olo.wikipedia.org" => "Wikipedia", |
| 185 | + "te.m.wikipedia.org" => "Wikipedia", |
| 186 | + "mk.wikipedia.org" => "Wikipedia", |
| 187 | + "dz.wikipedia.org" => "Wikipedia", |
| 188 | + "as.m.wikipedia.org" => "Wikipedia", |
| 189 | + "szl.m.wikipedia.org" => "Wikipedia", |
| 190 | + "oc.wikipedia.org" => "Wikipedia", |
| 191 | + "rw.m.wikipedia.org" => "Wikipedia", |
| 192 | + "tl.m.wikipedia.org" => "Wikipedia", |
| 193 | + "si.wikipedia.org" => "Wikipedia", |
| 194 | + "nostalgia.wikipedia.org" => "Wikipedia", |
| 195 | + "lrc.wikipedia.org" => "Wikipedia", |
| 196 | + "eo.m.wikipedia.org" => "Wikipedia", |
| 197 | + "ky.wikipedia.org" => "Wikipedia", |
| 198 | + "new.wikipedia.org" => "Wikipedia", |
| 199 | + "be.wikipedia.org" => "Wikipedia", |
| 200 | + "bcl.m.wikipedia.org" => "Wikipedia", |
| 201 | + "sq.m.wikipedia.org" => "Wikipedia", |
| 202 | + "am.wikipedia.org" => "Wikipedia", |
| 203 | + "nds-nl.m.wikipedia.org" => "Wikipedia", |
| 204 | + "gu.m.wikipedia.org" => "Wikipedia", |
| 205 | + "bjn.wikipedia.org" => "Wikipedia", |
| 206 | + "pa.m.wikipedia.org" => "Wikipedia", |
| 207 | + "sa.m.wikipedia.org" => "Wikipedia", |
| 208 | + "tt.wikipedia.org" => "Wikipedia", |
| 209 | + "qu.wikipedia.org" => "Wikipedia", |
| 210 | + "be-tarask.wikipedia.org" => "Wikipedia", |
| 211 | + "mg.m.wikipedia.org" => "Wikipedia", |
| 212 | + "dga.m.wikipedia.org" => "Wikipedia", |
| 213 | + "bat-smg.wikipedia.org" => "Wikipedia", |
| 214 | + "sw.wikipedia.org" => "Wikipedia", |
| 215 | + "wuu.wikipedia.org" => "Wikipedia", |
| 216 | + "ne.m.wikipedia.org" => "Wikipedia", |
| 217 | + "yi.m.wikipedia.org" => "Wikipedia", |
| 218 | + "vec.wikipedia.org" => "Wikipedia", |
| 219 | + "be-tarask.m.wikipedia.org" => "Wikipedia", |
| 220 | + "crh.wikipedia.org" => "Wikipedia" |
| 221 | + } |
| 222 | + |
| 223 | + def up do |
| 224 | + {keys, values} = Enum.unzip(@mappings) |
| 225 | + |
| 226 | + events_sql = """ |
| 227 | + ALTER TABLE events_v2 |
| 228 | + UPDATE referrer_source = transform(lower(referrer_source), {$0:Array(String)}, {$1:Array(String)}) |
| 229 | + WHERE lower(referrer_source) IN {$0:Array(String)} |
| 230 | + """ |
| 231 | + |
| 232 | + sessions_sql = """ |
| 233 | + ALTER TABLE sessions_v2 |
| 234 | + UPDATE referrer_source = transform(lower(referrer_source), {$0:Array(String)}, {$1:Array(String)}) |
| 235 | + WHERE lower(referrer_source) IN {$0:Array(String)} |
| 236 | + """ |
| 237 | + |
| 238 | + execute(fn -> repo().query!(events_sql, [keys, values]) end) |
| 239 | + execute(fn -> repo().query!(sessions_sql, [keys, values]) end) |
| 240 | + end |
| 241 | + |
| 242 | + def down do |
| 243 | + raise "irreversible" |
| 244 | + end |
| 245 | +end |
0 commit comments