Skip to content

Commit

Permalink
Populate site_imports from sites.imported_data in CE (#4155)
Browse files Browse the repository at this point in the history
* populate site_imports from sites.imported_data in CE

* not dry_run?

* Wrap data migration using `with_repo` to ensure ClickhouseRepo is running

* Do not create funnels in seeds when running CE

* Remove migrator wrapper

* Explicitly raise on rollback attempt

* Put a warning in data migration scripts which are put in migrations

---------

Co-authored-by: Adrian Gruntkowski <[email protected]>
  • Loading branch information
ruslandoga and zoldar authored May 29, 2024
1 parent 55dfe4c commit dc7243f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
5 changes: 3 additions & 2 deletions lib/plausible/data_migration/site_imports.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
defmodule Plausible.DataMigration.SiteImports do
@moduledoc """
!!!WARNING!!!: This script is used in migrations. Please take special care
when altering it.
Site imports migration backfilling SiteImport entries for old imports
and alters import end dates to match actual end date of respective import stats.
"""

import Ecto.Query
Expand Down
7 changes: 6 additions & 1 deletion lib/plausible/data_migration/versioned_sessions.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
defmodule Plausible.DataMigration.VersionedSessions do
@moduledoc """
Sessions CollapsingMergeTree -> VersionedCollapsingMergeTree migration, SQL files available at:
!!!WARNING!!!: This script is used in migrations. Please take special care
when altering it.
Sessions CollapsingMergeTree -> VersionedCollapsingMergeTree migration,
SQL files available at:
priv/data_migrations/VersionedSessions/sql
"""
use Plausible.DataMigration, dir: "VersionedSessions", repo: Plausible.IngestRepo
Expand Down
14 changes: 14 additions & 0 deletions priv/repo/migrations/20240528115149_migrate_site_imports.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule Plausible.Repo.Migrations.MigrateSiteImports do
use Plausible
use Ecto.Migration

def up do
if ce?() do
Plausible.DataMigration.SiteImports.run(dry_run?: false)
end
end

def down do
raise "Irreversible"
end
end
14 changes: 8 additions & 6 deletions priv/repo/seeds.exs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ seeded_token = Plausible.Plugins.API.Token.generate("seed-token")
{:ok, _goal5} = Plausible.Goals.create(site, %{"page_path" => Enum.random(long_random_paths)})
{:ok, outbound} = Plausible.Goals.create(site, %{"event_name" => "Outbound Link: Click"})

{:ok, _funnel} =
Plausible.Funnels.create(site, "From homepage to login", [
%{"goal_id" => goal1.id},
%{"goal_id" => goal2.id},
%{"goal_id" => goal3.id}
])
if Plausible.ee?() do
{:ok, _funnel} =
Plausible.Funnels.create(site, "From homepage to login", [
%{"goal_id" => goal1.id},
%{"goal_id" => goal2.id},
%{"goal_id" => goal3.id}
])
end

put_random_time = fn
date, 0 ->
Expand Down

0 comments on commit dc7243f

Please sign in to comment.