Implement backfill migration for enterprise plans (#5368)

This commit is contained in:
Adrian Gruntkowski 2025-04-29 17:23:05 +02:00 committed by GitHub
parent 6afd12cdab
commit a147aea0c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,27 @@
defmodule Plausible.Repo.Migrations.BackfillEnterisePlansFeautresSitesApi do
use Ecto.Migration
def change do
execute """
UPDATE enterprise_plans ep SET features = array_append(features, 'sites_api')
WHERE
'stats_api' = ANY(features) AND
EXISTS (
SELECT 1 FROM team_memberships AS tm
WHERE
tm.team_id = ep.team_id AND
EXISTS(
SELECT 1 FROM api_keys ak
WHERE
ak.user_id = tm.user_id AND
'sites:provision:*' = ANY(ak.scopes)
)
)
""",
"""
UPDATE enterprise_plans SET features = array(
SELECT unnest(features) EXCEPT SELECT unnest('{"sites_api"}'::varchar[])
)
"""
end
end