mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -05:00
refactor(schemas): use native enum for invitation status
This commit is contained in:
parent
571b53d9cc
commit
41f7b4d8ad
4 changed files with 17 additions and 17 deletions
|
@ -7,6 +7,8 @@ import { applyTableRls, dropTableRls } from './utils/1704934999-tables.js';
|
|||
const alteration: AlterationScript = {
|
||||
up: async (pool) => {
|
||||
await pool.query(sql`
|
||||
create type organization_invitation_status as enum ('Pending', 'Accepted', 'Expired', 'Revoked');
|
||||
|
||||
create table organization_invitations (
|
||||
tenant_id varchar(21) not null
|
||||
references tenants (id) on update cascade on delete cascade,
|
||||
|
@ -22,7 +24,7 @@ const alteration: AlterationScript = {
|
|||
/** The ID of the organization to which the invitee is invited. */
|
||||
organization_id varchar(21) not null,
|
||||
/** The status of the invitation. */
|
||||
status varchar(32) /* @use OrganizationInvitationStatus */ not null,
|
||||
status organization_invitation_status not null,
|
||||
/** The ID of the magic link that can be used to accept the invitation. */
|
||||
magic_link_id varchar(21)
|
||||
references magic_links (id) on update cascade on delete cascade,
|
||||
|
@ -37,6 +39,11 @@ const alteration: AlterationScript = {
|
|||
references organization_user_relations (tenant_id, user_id, organization_id)
|
||||
on update cascade on delete cascade
|
||||
);
|
||||
|
||||
-- Ensure there is only one pending invitation for a given invitee and organization.
|
||||
create unique index organization_invitations__invitee_organization_id
|
||||
on organization_invitations (tenant_id, invitee, organization_id)
|
||||
where status = 'Pending';
|
||||
`);
|
||||
await applyTableRls(pool, 'organization_invitations');
|
||||
|
||||
|
@ -63,6 +70,7 @@ const alteration: AlterationScript = {
|
|||
await dropTableRls(pool, 'organization_invitations');
|
||||
await pool.query(sql`
|
||||
drop table organization_invitations;
|
||||
drop type organization_invitation_status;
|
||||
`);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -11,7 +11,6 @@ export * from './sentinel.js';
|
|||
export * from './users.js';
|
||||
export * from './sso-connector.js';
|
||||
export * from './applications.js';
|
||||
export * from './organizations.js';
|
||||
|
||||
export {
|
||||
configurableConnectorMetadataGuard,
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
import { z } from 'zod';
|
||||
|
||||
/** The status of an organization invitation. */
|
||||
export enum OrganizationInvitationStatus {
|
||||
/** The invitation is pending for the invitee's response. */
|
||||
Pending = 'Pending',
|
||||
/** The invitation is accepted by the invitee. */
|
||||
Accepted = 'Accepted',
|
||||
/** The invitation is revoked by the inviter. */
|
||||
Revoked = 'Revoked',
|
||||
/** The invitation is expired, or the invitee has already joined the organization. */
|
||||
Expired = 'Expired',
|
||||
}
|
||||
export const organizationInvitationStatusGuard = z.nativeEnum(OrganizationInvitationStatus);
|
|
@ -1,5 +1,7 @@
|
|||
/* init_order = 3 */
|
||||
|
||||
create type organization_invitation_status as enum ('Pending', 'Accepted', 'Expired', 'Revoked');
|
||||
|
||||
/** The invitation entry defined in RFC 0003. It stores the invitation information for a user to join an organization. */
|
||||
create table organization_invitations (
|
||||
tenant_id varchar(21) not null
|
||||
|
@ -16,7 +18,7 @@ create table organization_invitations (
|
|||
/** The ID of the organization to which the invitee is invited. */
|
||||
organization_id varchar(21) not null,
|
||||
/** The status of the invitation. */
|
||||
status varchar(32) /* @use OrganizationInvitationStatus */ not null,
|
||||
status organization_invitation_status not null,
|
||||
/** The ID of the magic link that can be used to accept the invitation. */
|
||||
magic_link_id varchar(21)
|
||||
references magic_links (id) on update cascade on delete cascade,
|
||||
|
@ -31,3 +33,8 @@ create table organization_invitations (
|
|||
references organization_user_relations (tenant_id, user_id, organization_id)
|
||||
on update cascade on delete cascade
|
||||
);
|
||||
|
||||
-- Ensure there is only one pending invitation for a given invitee and organization.
|
||||
create unique index organization_invitations__invitee_organization_id
|
||||
on organization_invitations (tenant_id, invitee, organization_id)
|
||||
where status = 'Pending';
|
||||
|
|
Loading…
Reference in a new issue