Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MunifTanjim/120adfa9b40706cac4d76120964a3e0d to your computer and use it in GitHub Desktop.
Save MunifTanjim/120adfa9b40706cac4d76120964a3e0d to your computer and use it in GitHub Desktop.
Node OIDC Provider - Database Schema (PostgreSQL)
begin;
create function on_update_timestamp_trigger()
returns trigger as $$
begin
new."updated_at" = current_timestamp;
return new;
end;
$$ language 'plpgsql';
create table "access_token" (
"id" text not null
constraint "access_token_pk"
primary key,
"grant_id" text,
"data" json,
"expires_at" timestamp with time zone,
"created_at" timestamp with time zone default current_timestamp not null,
"updated_at" timestamp with time zone default current_timestamp not null
);
create index "access_token_idx_grant_id"
on "access_token" using hash ("grant_id");
create trigger "access_token_on_update_timestamp"
before update on "access_token"
for each row execute procedure on_update_timestamp_trigger();
create table "authorization_code" (
"id" text not null
constraint "authorization_code_pk"
primary key,
"grant_id" text,
"data" json,
"expires_at" timestamp with time zone,
"consumed_at" timestamp with time zone,
"created_at" timestamp with time zone default current_timestamp not null,
"updated_at" timestamp with time zone default current_timestamp not null
);
create index "authorization_code_idx_grant_id"
on "authorization_code" using hash ("grant_id");
create trigger "authorization_code_on_update_timestamp"
before update on "authorization_code"
for each row execute procedure on_update_timestamp_trigger();
create table "client" (
"id" text not null
constraint "client_pk"
primary key,
"data" json,
"created_at" timestamp with time zone default current_timestamp not null,
"updated_at" timestamp with time zone default current_timestamp not null
);
create trigger "client_on_update_timestamp"
before update on "client"
for each row execute procedure on_update_timestamp_trigger();
create table "client_credentials" (
"id" text not null
constraint "client_credentials_pk"
primary key,
"data" json,
"expires_at" timestamp with time zone,
"created_at" timestamp with time zone default current_timestamp not null,
"updated_at" timestamp with time zone default current_timestamp not null
);
create trigger "client_credentials_on_update_timestamp"
before update on "client_credentials"
for each row execute procedure on_update_timestamp_trigger();
create table "device_code" (
"id" text not null
constraint "device_code_pk"
primary key,
"grant_id" text,
"user_code" text,
"data" json,
"expires_at" timestamp with time zone,
"consumed_at" timestamp with time zone,
"created_at" timestamp with time zone default current_timestamp not null,
"updated_at" timestamp with time zone default current_timestamp not null
);
create index "device_code_idx_grant_id"
on "device_code" using hash ("grant_id");
create index "device_code_idx_user_code"
on "device_code" using hash ("user_code");
create trigger "device_code_on_update_timestamp"
before update on "device_code"
for each row execute procedure on_update_timestamp_trigger();
create table "initial_access_token" (
"id" text not null
constraint "initial_access_token_pk"
primary key,
"data" json,
"expires_at" timestamp with time zone,
"created_at" timestamp with time zone default current_timestamp not null,
"updated_at" timestamp with time zone default current_timestamp not null
);
create trigger "initial_access_token_on_update_timestamp"
before update on "initial_access_token"
for each row execute procedure on_update_timestamp_trigger();
create table "interaction" (
"id" text not null
constraint "interaction_pk"
primary key,
"uid" text,
"data" json,
"expires_at" timestamp with time zone,
"created_at" timestamp with time zone default current_timestamp not null,
"updated_at" timestamp with time zone default current_timestamp not null
);
create index "interaction_idx_uid"
on "interaction" using hash ("uid");
create trigger "interaction_on_update_timestamp"
before update on "interaction"
for each row execute procedure on_update_timestamp_trigger();
create table "pushed_authorization_request" (
"id" text not null
constraint "pushed_authorization_request_pk"
primary key,
"data" json,
"expires_at" timestamp with time zone,
"created_at" timestamp with time zone default current_timestamp not null,
"updated_at" timestamp with time zone default current_timestamp not null
);
create trigger "pushed_authorization_request_on_update_timestamp"
before update on "pushed_authorization_request"
for each row execute procedure on_update_timestamp_trigger();
create table "refresh_token" (
"id" text not null
constraint "refresh_token_pk"
primary key,
"grant_id" text,
"data" json,
"expires_at" timestamp with time zone,
"consumed_at" timestamp with time zone,
"created_at" timestamp with time zone default current_timestamp not null,
"updated_at" timestamp with time zone default current_timestamp not null
);
create index "refresh_token_idx_grant_id"
on "refresh_token" using hash ("grant_id");
create trigger "refresh_token_on_update_timestamp"
before update on "refresh_token"
for each row execute procedure on_update_timestamp_trigger();
create table "registration_access_token" (
"id" text not null
constraint "registration_access_token_pk"
primary key,
"data" json,
"expires_at" timestamp with time zone,
"created_at" timestamp with time zone default current_timestamp not null,
"updated_at" timestamp with time zone default current_timestamp not null
);
create trigger "registration_access_token_on_update_timestamp"
before update on "registration_access_token"
for each row execute procedure on_update_timestamp_trigger();
create table "replay_detection" (
"id" text not null
constraint "replay_detection_pk"
primary key,
"data" json,
"expires_at" timestamp with time zone,
"created_at" timestamp with time zone default current_timestamp not null,
"updated_at" timestamp with time zone default current_timestamp not null
);
create trigger "replay_detection_on_update_timestamp"
before update on "replay_detection"
for each row execute procedure on_update_timestamp_trigger();
create table "session" (
"id" text not null
constraint "session_pk"
primary key,
"uid" text,
"data" json,
"expires_at" timestamp with time zone,
"created_at" timestamp with time zone default current_timestamp not null,
"updated_at" timestamp with time zone default current_timestamp not null
);
create index "session_idx_uid"
on "session" using hash ("uid");
create trigger "session_on_update_timestamp"
before update on "session"
for each row execute procedure on_update_timestamp_trigger();
commit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment