Skip to content

Commit 023c7ac

Browse files
authored
Fix community editon migrations (#5307)
* Fix migration that was not working cc @macobo * Fixup old migrations to use `community_edition?` predicate * Move hourly api request limit migration to the bottom The odds are low that self-hosters use that one, but let's make sure it runs after teams have been migrated. * Tag dump plans as ee only
1 parent 087b6e7 commit 023c7ac

6 files changed

Lines changed: 16 additions & 7 deletions

priv/ingest_repo/migrations/20230509124919_clean_up_old_tables_after_v2_migration.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
defmodule Plausible.IngestRepo.Migrations.CleanUpOldTablesAfterV2Migration do
22
use Ecto.Migration
33

4-
def change do
5-
selfhost? = Application.fetch_env!(:plausible, :is_selfhost)
4+
import Plausible.MigrationUtils
65

7-
unless selfhost? do
6+
def change do
7+
unless community_edition?() do
88
drop_if_exists table(:events)
99
drop_if_exists table(:sessions)
1010
end

priv/repo/migrations/20231121131602_create_plans_table.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
defmodule Plausible.Repo.Migrations.CreatePlansTable do
22
use Ecto.Migration
33

4+
import Plausible.MigrationUtils
5+
46
def change do
5-
if !Application.get_env(:plausible, :is_selfhost) do
7+
if enterprise_edition?() do
68
create table(:plans) do
79
add :generation, :integer, null: false
810
add :kind, :string, null: false

priv/repo/migrations/20231208125624_add_data_retention_in_years_to_plans.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
defmodule Plausible.Repo.Migrations.AddDataRetentionInYearsToPlans do
22
use Ecto.Migration
33

4+
import Plausible.MigrationUtils
5+
46
def change do
5-
if !Application.get_env(:plausible, :is_selfhost) do
7+
if enterprise_edition?() do
68
alter table(:plans) do
79
add :data_retention_in_years, :integer, null: true
810
end

priv/repo/migrations/20250318131615_site_legacy_time_on_page_cutoff.exs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@ defmodule Plausible.Repo.Migrations.SiteLegacyTimeOnPageCutoff do
22
use Ecto.Migration
33
use Plausible
44

5+
import Plausible.MigrationUtils
6+
57
def change do
68
alter table(:sites) do
79
# New sites will have new time-on-page enabled by default.
810
add :legacy_time_on_page_cutoff, :date,
911
default: fragment("to_date('1970-01-01', 'YYYY-MM-DD')")
1012
end
1113

12-
if Application.get_env(:plausible, :is_selfhost) do
14+
if community_edition?() do
1315
# On self-hosted, new time-on-page will be populated during first deploy.
1416
execute(
1517
fn ->
16-
repo().query!("UPDATE sites SET legacy_time_on_page_cutoff = ?", [Date.utc_today()])
18+
repo().query!("UPDATE sites SET legacy_time_on_page_cutoff = $1::date", [
19+
Date.utc_today()
20+
])
1721
end,
1822
&pass/0
1923
)

priv/repo/migrations/20250403093826_backfill_teams_hourly_api_request_limit.exs renamed to priv/repo/migrations/20250403093829_backfill_teams_hourly_api_request_limit.exs

File renamed without changes.

test/plausible/release_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ defmodule Plausible.ReleaseTest do
3030
end
3131
end
3232

33+
@tag :ee_only
3334
test "dump_plans/0 inserts plans" do
3435
stdout =
3536
capture_io(fn ->

0 commit comments

Comments
 (0)