2023-01-19 20:27:01 +08:00
/* init_order = 1 */
2023-12-19 15:59:27 +08:00
create type application_type as enum ( ' Native ' , ' SPA ' , ' Traditional ' , ' MachineToMachine ' , ' Protected ' ) ;
2021-08-10 17:21:34 +08:00
create table applications (
2023-01-19 20:27:01 +08:00
tenant_id varchar ( 21 ) not null
references tenants ( id ) on update cascade on delete cascade ,
2022-04-18 15:27:58 +08:00
id varchar ( 21 ) not null ,
2021-08-10 17:21:34 +08:00
name varchar ( 256 ) not null ,
2024-07-28 08:40:01 +08: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 16:18:50 +08:00
secret varchar ( 64 ) not null ,
2022-01-11 11:58:58 +08:00
description text ,
2021-08-10 17:21:34 +08:00
type application_type not null ,
oidc_client_metadata jsonb /* @use OidcClientMetadata */ not null ,
2022-01-13 14:15:13 +08:00
custom_client_metadata jsonb /* @use CustomClientMetadata */ not null default ' {} ' : : jsonb ,
2023-12-19 17:04:14 +08:00
protected_app_metadata jsonb /* @use ProtectedAppMetadata */ ,
2024-07-25 17:55:57 +08:00
custom_data jsonb /* @use JsonObject */ not null default ' {} ' : : jsonb ,
2023-12-12 14:54:49 +08:00
is_third_party boolean not null default false ,
2021-08-18 16:36:52 +08:00
created_at timestamptz not null default ( now ( ) ) ,
2021-08-10 17:21:34 +08:00
primary key ( id )
) ;
2023-01-19 20:27:01 +08:00
create index applications__id
2023-01-28 19:26:29 +08:00
on applications ( tenant_id , id ) ;
2023-12-12 14:54:49 +08:00
create index applications__is_third_party
on applications ( tenant_id , is_third_party ) ;
2024-01-30 11:53:27 +08:00
create unique index applications__protected_app_metadata_host
on applications (
( protected_app_metadata - > > ' host ' )
) ;
2024-01-31 11:05:20 +08:00
create unique index applications__protected_app_metadata_custom_domain
on applications (
( protected_app_metadata - > ' customDomains ' - > 0 - > > ' domain ' )
) ;
2024-06-19 22:29:44 +08:00
2024-07-21 19:59:30 +08:00
create function check_application_type (
application_id varchar ( 21 ) ,
variadic target_type application_type [ ]
) returns boolean as
2024-06-19 22:29:44 +08:00
$ $ begin
2024-07-21 19:59:30 +08:00
return ( select type from applications where id = application_id ) = any ( target_type ) ;
2024-06-24 18:11:43 +08:00
end ; $ $ language plpgsql set search_path = public ;