Add data migration cleaning up referrer source for demo site (#4225)

* Add data migration cleaning up referrer source for demo site

* Alter query string formatting out of abundance of care 😬
This commit is contained in:
Adrian Gruntkowski 2024-06-13 13:28:15 +02:00 committed by GitHub
parent 2c05676d8e
commit 6a511ec8a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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