Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Fix determining CE/EE in migrations (#5283)

Adrian Gruntkowski847353d17e9b
diff --git a/.github/workflows/migrations-validation.yml b/.github/workflows/migrations-validation.yml
index 2046dc0d87..2d162f8021 100644
--- a/.github/workflows/migrations-validation.yml
+++ b/.github/workflows/migrations-validation.yml
@@ -21,6 +21,7 @@ jobs:
lib:
- 'lib/**'
- '!lib/plausible/data_migration/**'
+ - '!lib/plausible/migration_utils.ex'
extra:
- 'extra/**'
config:
diff --git a/lib/plausible/migration_utils.ex b/lib/plausible/migration_utils.ex
index 93cbca632e..01e884deeb 100644
--- a/lib/plausible/migration_utils.ex
+++ b/lib/plausible/migration_utils.ex
@@ -3,6 +3,8 @@ defmodule Plausible.MigrationUtils do
Base module for to use in Clickhouse migrations
"""
+ use Plausible
+
alias Plausible.IngestRepo
def on_cluster_statement(table) do
@@ -38,6 +40,10 @@ defmodule Plausible.MigrationUtils do
end
end
+ def enterprise_edition?(), do: ee?()
+
+ def community_edition?(), do: ce?()
+
defp encode(value) when is_number(value), do: value
defp encode(value) when is_binary(value), do: "'#{value}'"
end
diff --git a/priv/repo/migrations/20240528115149_migrate_site_imports.exs b/priv/repo/migrations/20240528115149_migrate_site_imports.exs
index ac53645883..e06c5d9ec0 100644
--- a/priv/repo/migrations/20240528115149_migrate_site_imports.exs
+++ b/priv/repo/migrations/20240528115149_migrate_site_imports.exs
@@ -1,9 +1,10 @@
defmodule Plausible.Repo.Migrations.MigrateSiteImports do
- use Plausible
use Ecto.Migration
+ import Plausible.MigrationUtils
+
def up do
- if ce?() do
+ if community_edition?() do
{:ok, _, _} =
Ecto.Migrator.with_repo(Plausible.ClickhouseRepo, fn _repo ->
Plausible.DataMigration.SiteImports.run(dry_run?: false)
diff --git a/priv/repo/migrations/20250403093826_backfill_teams_hourly_api_request_limit.exs b/priv/repo/migrations/20250403093826_backfill_teams_hourly_api_request_limit.exs
index 243e6d2fa4..f78571234d 100644
--- a/priv/repo/migrations/20250403093826_backfill_teams_hourly_api_request_limit.exs
+++ b/priv/repo/migrations/20250403093826_backfill_teams_hourly_api_request_limit.exs
@@ -1,9 +1,10 @@
defmodule Plausible.Repo.Migrations.BackfillTeamsHourlyApiRequestLimit do
- use Plausible
use Ecto.Migration
+ import Plausible.MigrationUtils
+
def up do
- if ce?() do
+ if community_edition?() do
Plausible.DataMigration.BackfillTeamsHourlyRequestLimit.run(dry_run?: false)
end
end