Backfill accepted_traffic_until for active subscriptions (#3736)

* Backfill accepted_traffic_until for active subscriptions

* Narrow the results
pull/3738/head r2024.01.29-333
hq1 3 years ago committed by GitHub
parent 04b9067591
commit 8f6ec252e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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
Loading…
Cancel
Save