From 8f6ec252e91f747e73350050d32d9d00a6269f07 Mon Sep 17 00:00:00 2001 From: hq1 Date: Mon, 29 Jan 2024 11:51:00 +0100 Subject: [PATCH] Backfill accepted_traffic_until for active subscriptions (#3736) * Backfill accepted_traffic_until for active subscriptions * Narrow the results --- ...9102900_migrate_accepted_traffic_until.exs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 priv/repo/migrations/20240129102900_migrate_accepted_traffic_until.exs diff --git a/priv/repo/migrations/20240129102900_migrate_accepted_traffic_until.exs b/priv/repo/migrations/20240129102900_migrate_accepted_traffic_until.exs new file mode 100644 index 000000000..b8324018a --- /dev/null +++ b/priv/repo/migrations/20240129102900_migrate_accepted_traffic_until.exs @@ -0,0 +1,27 @@ +defmodule Plausible.Repo.Migrations.MigrateAcceptedTrafficUntil do + use Ecto.Migration + + def up do + # all the non-free, active subscriptions + execute """ + UPDATE users u1 + SET accept_traffic_until = s.next_bill_date + 30 + FROM users u2 + INNER JOIN subscriptions s ON u2.id = s.user_id + WHERE + u1.id = u2.id + AND + s.user_id = u1.id + AND + s.paddle_plan_id != 'free_10k' + AND + s.status = 'active' + AND + u1.accept_traffic_until <= s.next_bill_date + """ + end + + def down do + raise "irreversible" + end +end