Skip to content

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

Fix community editon migrations (#5307)

hq1023c7ac2c04a
diff --git a/priv/ingest_repo/migrations/20230509124919_clean_up_old_tables_after_v2_migration.exs b/priv/ingest_repo/migrations/20230509124919_clean_up_old_tables_after_v2_migration.exs
index 9102767bd9..7b2456030e 100644
--- a/priv/ingest_repo/migrations/20230509124919_clean_up_old_tables_after_v2_migration.exs
+++ b/priv/ingest_repo/migrations/20230509124919_clean_up_old_tables_after_v2_migration.exs
@@ -1,10 +1,10 @@
defmodule Plausible.IngestRepo.Migrations.CleanUpOldTablesAfterV2Migration do
use Ecto.Migration
- def change do
- selfhost? = Application.fetch_env!(:plausible, :is_selfhost)
+ import Plausible.MigrationUtils
- unless selfhost? do
+ def change do
+ unless community_edition?() do
drop_if_exists table(:events)
drop_if_exists table(:sessions)
end
diff --git a/priv/repo/migrations/20231121131602_create_plans_table.exs b/priv/repo/migrations/20231121131602_create_plans_table.exs
index 0ad209e737..fc3cbc58c5 100644
--- a/priv/repo/migrations/20231121131602_create_plans_table.exs
+++ b/priv/repo/migrations/20231121131602_create_plans_table.exs
@@ -1,8 +1,10 @@
defmodule Plausible.Repo.Migrations.CreatePlansTable do
use Ecto.Migration
+ import Plausible.MigrationUtils
+
def change do
- if !Application.get_env(:plausible, :is_selfhost) do
+ if enterprise_edition?() do
create table(:plans) do
add :generation, :integer, null: false
add :kind, :string, null: false
diff --git a/priv/repo/migrations/20231208125624_add_data_retention_in_years_to_plans.exs b/priv/repo/migrations/20231208125624_add_data_retention_in_years_to_plans.exs
index 6c1188be36..feb0c6fee1 100644
--- a/priv/repo/migrations/20231208125624_add_data_retention_in_years_to_plans.exs
+++ b/priv/repo/migrations/20231208125624_add_data_retention_in_years_to_plans.exs
@@ -1,8 +1,10 @@
defmodule Plausible.Repo.Migrations.AddDataRetentionInYearsToPlans do
use Ecto.Migration
+ import Plausible.MigrationUtils
+
def change do
- if !Application.get_env(:plausible, :is_selfhost) do
+ if enterprise_edition?() do
alter table(:plans) do
add :data_retention_in_years, :integer, null: true
end
diff --git a/priv/repo/migrations/20250318131615_site_legacy_time_on_page_cutoff.exs b/priv/repo/migrations/20250318131615_site_legacy_time_on_page_cutoff.exs
index dd5e1e4aff..31c245171c 100644
--- a/priv/repo/migrations/20250318131615_site_legacy_time_on_page_cutoff.exs
+++ b/priv/repo/migrations/20250318131615_site_legacy_time_on_page_cutoff.exs
@@ -2,6 +2,8 @@ defmodule Plausible.Repo.Migrations.SiteLegacyTimeOnPageCutoff do
use Ecto.Migration
use Plausible
+ import Plausible.MigrationUtils
+
def change do
alter table(:sites) do
# New sites will have new time-on-page enabled by default.
@@ -9,11 +11,13 @@ defmodule Plausible.Repo.Migrations.SiteLegacyTimeOnPageCutoff do
default: fragment("to_date('1970-01-01', 'YYYY-MM-DD')")
end
- if Application.get_env(:plausible, :is_selfhost) do
+ if community_edition?() do
# On self-hosted, new time-on-page will be populated during first deploy.
execute(
fn ->
- repo().query!("UPDATE sites SET legacy_time_on_page_cutoff = ?", [Date.utc_today()])
+ repo().query!("UPDATE sites SET legacy_time_on_page_cutoff = $1::date", [
+ Date.utc_today()
+ ])
end,
&pass/0
)
diff --git a/priv/repo/migrations/20250403093826_backfill_teams_hourly_api_request_limit.exs b/priv/repo/migrations/20250403093829_backfill_teams_hourly_api_request_limit.exs
similarity index 100%
rename from priv/repo/migrations/20250403093826_backfill_teams_hourly_api_request_limit.exs
rename to priv/repo/migrations/20250403093829_backfill_teams_hourly_api_request_limit.exs
diff --git a/test/plausible/release_test.exs b/test/plausible/release_test.exs
index a39e0d6e1c..4c4d59f988 100644
--- a/test/plausible/release_test.exs
+++ b/test/plausible/release_test.exs
@@ -30,6 +30,7 @@ defmodule Plausible.ReleaseTest do
end
end
+ @tag :ee_only
test "dump_plans/0 inserts plans" do
stdout =
capture_io(fn ->