2023-01-19 07:27:01 -05:00
|
|
|
/* init_order = 1 */
|
|
|
|
|
2024-03-03 22:18:19 -05:00
|
|
|
create type users_password_encryption_method as enum ('Argon2i', 'SHA1', 'SHA256', 'MD5', 'Bcrypt');
|
2021-07-03 06:13:05 -05:00
|
|
|
|
2021-07-02 08:09:08 -05:00
|
|
|
create table users (
|
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(12) not null,
|
2023-02-11 01:38:16 -05:00
|
|
|
username varchar(128),
|
|
|
|
primary_email varchar(128),
|
|
|
|
primary_phone varchar(128),
|
2021-07-02 08:09:08 -05:00
|
|
|
password_encrypted varchar(128),
|
2022-02-24 05:01:17 -05:00
|
|
|
password_encryption_method users_password_encryption_method,
|
2022-02-14 03:03:13 -05:00
|
|
|
name varchar(128),
|
2024-03-19 09:51:26 -05:00
|
|
|
/** The URL that points to the user's profile picture. Mapped to OpenID Connect's `picture` claim. */
|
2022-06-17 04:04:04 -05:00
|
|
|
avatar varchar(2048),
|
2024-03-19 09:51:26 -05:00
|
|
|
/** Additional OpenID Connect standard claims that are not included in user's properties. */
|
|
|
|
profile jsonb /* @use UserProfile */ not null default '{}'::jsonb,
|
2022-05-26 04:44:32 -05:00
|
|
|
application_id varchar(21),
|
2022-02-08 23:55:06 -05:00
|
|
|
identities jsonb /* @use Identities */ not null default '{}'::jsonb,
|
2023-04-23 22:11:27 -05:00
|
|
|
custom_data jsonb /* @use JsonObject */ not null default '{}'::jsonb,
|
2023-11-02 03:16:21 -05:00
|
|
|
logto_config jsonb /* @use JsonObject */ not null default '{}'::jsonb,
|
2023-09-14 22:16:47 -05:00
|
|
|
mfa_verifications jsonb /* @use MfaVerifications */ not null default '[]'::jsonb,
|
2022-11-03 21:10:01 -05:00
|
|
|
is_suspended boolean not null default false,
|
2022-05-05 03:22:43 -05:00
|
|
|
last_sign_in_at timestamptz,
|
2022-09-29 02:32:43 -05:00
|
|
|
created_at timestamptz not null default (now()),
|
2024-03-19 09:51:26 -05:00
|
|
|
updated_at timestamptz not null default (now()),
|
2023-02-11 01:38:16 -05:00
|
|
|
primary key (id),
|
|
|
|
constraint users__username
|
|
|
|
unique (tenant_id, username),
|
|
|
|
constraint users__primary_email
|
|
|
|
unique (tenant_id, primary_email),
|
|
|
|
constraint users__primary_phone
|
|
|
|
unique (tenant_id, primary_phone)
|
2021-07-02 08:09:08 -05:00
|
|
|
);
|
2022-09-29 02:32:43 -05:00
|
|
|
|
2023-01-19 07:27:01 -05:00
|
|
|
create index users__id
|
|
|
|
on users (tenant_id, id);
|
|
|
|
|
|
|
|
create index users__name
|
|
|
|
on users (tenant_id, name);
|
2024-03-20 00:16:23 -05:00
|
|
|
|
|
|
|
create trigger set_updated_at
|
|
|
|
before update on users
|
|
|
|
for each row
|
|
|
|
execute procedure set_updated_at();
|