Skip to content

Commit

Permalink
Add data migration cleaning up referrer source for demo site (plausib…
Browse files Browse the repository at this point in the history
…le#4225)

* Add data migration cleaning up referrer source for demo site

* Alter query string formatting out of abundance of care 😬
  • Loading branch information
zoldar authored Jun 13, 2024
1 parent 2c05676 commit 6a511ec
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/plausible/data_migration/clean_up_demo_site_referrer_source.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
defmodule Plausible.DataMigration.CleanUpDemoSiteReferrerSource do
@moduledoc """
Clean up referrer_source entries for demo site with
`Direct / None` for value populated by dogfooding
Plausible stats.
"""

alias Plausible.IngestRepo
alias Plausible.Repo

def run(timeout \\ 60_000) do
demo_domain = PlausibleWeb.Endpoint.host()
%{id: demo_site_id} = Repo.get_by(Plausible.Site, domain: demo_domain)

for table <- ["sessions_v2", "events_v2"] do
IngestRepo.query!(
"ALTER TABLE {$0:Identifier} UPDATE referrer_source = '' WHERE " <>
"site_id = {$1:UInt64} AND referrer_source = 'Direct / None'",
[table, demo_site_id],
settings: [mutations_sync: 1],
timeout: timeout
)
end
end
end

0 comments on commit 6a511ec

Please sign in to comment.