update: use jwt
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
DROP TABLE IF EXISTS public.verification;
|
||||
DROP TABLE IF EXISTS public.jwks;
|
||||
DROP TABLE IF EXISTS public.session;
|
||||
DROP TABLE IF EXISTS public.account;
|
||||
DROP TABLE IF EXISTS public."user";
|
||||
DROP TABLE IF EXISTS public."user";
|
||||
|
||||
DROP TABLE IF EXISTS drizzle.__drizzle_migrations;
|
||||
DROP SCHEMA IF EXISTS drizzle;
|
||||
|
||||
DROP EXTENSION IF EXISTS pgcrypto;
|
||||
|
||||
@@ -1,52 +1,88 @@
|
||||
CREATE EXTENSION IF NOT EXISTS pgcrypto;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public."user" (
|
||||
id text NOT NULL,
|
||||
ssh_identifier text UNIQUE NOT NULL DEFAULT substr(encode(gen_random_bytes(16), 'hex'), 1, 32),
|
||||
name text NOT NULL,
|
||||
email text NOT NULL,
|
||||
email_verified boolean DEFAULT false NOT NULL,
|
||||
image text,
|
||||
created_at timestamp without time zone DEFAULT now() NOT NULL,
|
||||
updated_at timestamp without time zone DEFAULT now() NOT NULL,
|
||||
CONSTRAINT user_pkey PRIMARY KEY (id)
|
||||
CREATE TABLE public."user" (
|
||||
id TEXT PRIMARY KEY,
|
||||
ssh_identifier TEXT NOT NULL DEFAULT substr(encode(gen_random_bytes(16), 'hex'), 1, 32),
|
||||
name TEXT NOT NULL,
|
||||
email TEXT NOT NULL,
|
||||
email_verified BOOLEAN NOT NULL DEFAULT false,
|
||||
image TEXT,
|
||||
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.account (
|
||||
id text NOT NULL,
|
||||
account_id text NOT NULL,
|
||||
provider_id text NOT NULL,
|
||||
user_id text NOT NULL,
|
||||
access_token text,
|
||||
refresh_token text,
|
||||
id_token text,
|
||||
access_token_expires_at timestamp without time zone,
|
||||
refresh_token_expires_at timestamp without time zone,
|
||||
scope text,
|
||||
password text,
|
||||
created_at timestamp without time zone DEFAULT now() NOT NULL,
|
||||
updated_at timestamp without time zone NOT NULL,
|
||||
CONSTRAINT account_pkey PRIMARY KEY (id)
|
||||
CREATE UNIQUE INDEX user_email_unique
|
||||
ON public."user"(email);
|
||||
|
||||
CREATE UNIQUE INDEX user_ssh_identifier_unique
|
||||
ON public."user"(ssh_identifier);
|
||||
|
||||
CREATE TABLE public.account (
|
||||
id TEXT PRIMARY KEY,
|
||||
account_id TEXT NOT NULL,
|
||||
provider_id TEXT NOT NULL,
|
||||
user_id TEXT NOT NULL,
|
||||
access_token TEXT,
|
||||
refresh_token TEXT,
|
||||
id_token TEXT,
|
||||
access_token_expires_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
refresh_token_expires_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
scope TEXT,
|
||||
password TEXT,
|
||||
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMP WITHOUT TIME ZONE NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.session (
|
||||
id text NOT NULL,
|
||||
expires_at timestamp without time zone NOT NULL,
|
||||
token text NOT NULL,
|
||||
created_at timestamp without time zone DEFAULT now() NOT NULL,
|
||||
updated_at timestamp without time zone NOT NULL,
|
||||
ip_address text,
|
||||
user_agent text,
|
||||
user_id text NOT NULL,
|
||||
CONSTRAINT session_pkey PRIMARY KEY (id)
|
||||
CREATE INDEX account_userId_idx
|
||||
ON public.account(user_id);
|
||||
|
||||
ALTER TABLE public.account
|
||||
ADD CONSTRAINT account_user_id_user_id_fk
|
||||
FOREIGN KEY (user_id)
|
||||
REFERENCES public."user"(id)
|
||||
ON DELETE CASCADE;
|
||||
|
||||
|
||||
CREATE TABLE public.session (
|
||||
id TEXT PRIMARY KEY,
|
||||
expires_at TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
||||
token TEXT NOT NULL,
|
||||
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
||||
ip_address TEXT,
|
||||
user_agent TEXT,
|
||||
user_id TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.verification (
|
||||
id text NOT NULL,
|
||||
identifier text NOT NULL,
|
||||
value text NOT NULL,
|
||||
expires_at timestamp without time zone NOT NULL,
|
||||
created_at timestamp without time zone DEFAULT now() NOT NULL,
|
||||
updated_at timestamp without time zone DEFAULT now() NOT NULL,
|
||||
CONSTRAINT verification_pkey PRIMARY KEY (id)
|
||||
);
|
||||
CREATE UNIQUE INDEX session_token_unique
|
||||
ON public.session(token);
|
||||
|
||||
CREATE INDEX session_userId_idx
|
||||
ON public.session(user_id);
|
||||
|
||||
ALTER TABLE public.session
|
||||
ADD CONSTRAINT session_user_id_user_id_fk
|
||||
FOREIGN KEY (user_id)
|
||||
REFERENCES public."user"(id)
|
||||
ON DELETE CASCADE;
|
||||
|
||||
|
||||
CREATE TABLE public.jwks (
|
||||
id TEXT PRIMARY KEY,
|
||||
public_key TEXT NOT NULL,
|
||||
private_key TEXT NOT NULL,
|
||||
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
||||
expires_at TIMESTAMP WITHOUT TIME ZONE
|
||||
);
|
||||
|
||||
CREATE TABLE public.verification (
|
||||
id TEXT PRIMARY KEY,
|
||||
identifier TEXT NOT NULL,
|
||||
value TEXT NOT NULL,
|
||||
expires_at TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
||||
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX verification_identifier_idx
|
||||
ON public.verification(identifier);
|
||||
|
||||
Reference in New Issue
Block a user