2023-01-19 07:27:01 -05:00
/* init_order = 1 */
2024-11-04 04:22:20 -05:00
create type application_type as enum ( ' Native ' , ' SPA ' , ' Traditional ' , ' MachineToMachine ' , ' Protected ' , ' SAML ' ) ;
2021-08-10 04:21:34 -05:00
create table applications (
2023-01-19 07:27:01 -05:00
tenant_id varchar ( 21 ) not null
references tenants ( id ) on update cascade on delete cascade ,
2022-04-18 02:27:58 -05:00
id varchar ( 21 ) not null ,
2021-08-10 04:21:34 -05:00
name varchar ( 256 ) not null ,
2024-07-27 19:40:01 -05:00
/* * @deprecated The internal client secret. Note it is only used for internal validation, and the actual secret should be stored in the `application_secrets` table. You should NOT use it unless you are sure what you are doing. */
2022-08-02 03:18:50 -05:00
secret varchar ( 64 ) not null ,
2022-01-10 22:58:58 -05:00
description text ,
2021-08-10 04:21:34 -05:00
type application_type not null ,
oidc_client_metadata jsonb /* @use OidcClientMetadata */ not null ,
2022-01-13 01:15:13 -05:00
custom_client_metadata jsonb /* @use CustomClientMetadata */ not null default ' {} ' : : jsonb ,
2023-12-19 04:04:14 -05:00
protected_app_metadata jsonb /* @use ProtectedAppMetadata */ ,
2024-07-25 04:55:57 -05:00
custom_data jsonb /* @use JsonObject */ not null default ' {} ' : : jsonb ,
2023-12-12 01:54:49 -05:00
is_third_party boolean not null default false ,
2021-08-18 03:36:52 -05:00
created_at timestamptz not null default ( now ( ) ) ,
2024-11-04 04:22:20 -05:00
primary key ( id ) ,
constraint check_saml_app_third_party_consistency check (
type ! = ' SAML ' OR ( type = ' SAML ' AND is_third_party = true )
)
2021-08-10 04:21:34 -05:00
) ;
2023-01-19 07:27:01 -05:00
create index applications__id
2023-01-28 06:26:29 -05:00
on applications ( tenant_id , id ) ;
2023-12-12 01:54:49 -05:00
create index applications__is_third_party
on applications ( tenant_id , is_third_party ) ;
2024-01-29 22:53:27 -05:00
create unique index applications__protected_app_metadata_host
on applications (
( protected_app_metadata - > > ' host ' )
) ;
2024-01-30 22:05:20 -05:00
create unique index applications__protected_app_metadata_custom_domain
on applications (
( protected_app_metadata - > ' customDomains ' - > 0 - > > ' domain ' )
) ;
2024-06-19 09:29:44 -05:00
2024-07-21 06:59:30 -05:00
create function check_application_type (
application_id varchar ( 21 ) ,
variadic target_type application_type [ ]
) returns boolean as
2024-06-19 09:29:44 -05:00
$ $ begin
2024-07-21 06:59:30 -05:00
return ( select type from applications where id = application_id ) = any ( target_type ) ;
2024-06-24 05:11:43 -05:00
end ; $ $ language plpgsql set search_path = public ;