Files
probo/pkg/coredata/migrations/20260728T143246Z.sql
Émile Ré eecf8a1d97 Make profile state filters multi-value
Address PR review feedback on the profile-state split: SAML sign-in now
activates a pending profile, deactivation counts owners against the
profile's own organization to close a last-owner bypass, the migration
leaves historical activated_at/deactivated_at NULL rather than
fabricating timestamps, and pending members are no longer rendered with
the deactivated (faded) styling.

Drop the single-value state filter in favor of the multi-value states
across the profile and signatory surfaces. Remove ProfileFilter.state
(only states[] remains) and convert the signatures profileState filter
to profileStates. Turn the console people filter, the CLI
"user list --state" flag, and the n8n listUsers and getAllSignatures
state inputs into multi-select controls, where an empty selection means
all states.

Signed-off-by: Émile Ré <emile@probo.com>
2026-07-30 09:19:42 +02:00

49 lines
1.7 KiB
SQL

-- Copyright (c) 2026 Probo Inc <hello@getprobo.com>.
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
-- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
-- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-- PERFORMANCE OF THIS SOFTWARE.
ALTER TABLE iam_membership_profiles
ADD COLUMN activated_at TIMESTAMP WITH TIME ZONE,
ADD COLUMN deactivated_at TIMESTAMP WITH TIME ZONE;
ALTER TABLE iam_membership_profiles
ALTER COLUMN state DROP DEFAULT;
ALTER TYPE membership_state RENAME TO membership_state_old;
CREATE TYPE membership_state AS ENUM ('PENDING', 'ACTIVE', 'DEACTIVATED');
ALTER TABLE iam_membership_profiles
ALTER COLUMN state TYPE membership_state
USING CASE
WHEN state::text = 'ACTIVE' THEN 'ACTIVE'::membership_state
ELSE 'DEACTIVATED'::membership_state
END;
DROP TYPE membership_state_old;
UPDATE iam_membership_profiles
SET state = 'PENDING'
WHERE state = 'DEACTIVATED'
AND source != 'SCIM'
AND EXISTS (
SELECT 1
FROM iam_invitations i
WHERE i.user_id = iam_membership_profiles.id
AND i.accepted_at IS NULL
AND (
i.expires_at >= NOW()
OR i.created_at >= NOW() - INTERVAL '7 days'
)
);