mirror of
https://github.com/xbgmsharp/postgsail.git
synced 2025-09-17 11:17:46 +00:00
Update email type to CITEXT, https://www.postgresql.org/docs/current/citext.html
This commit is contained in:
@@ -22,7 +22,7 @@ CREATE EXTENSION IF NOT EXISTS "pgcrypto"; -- provides cryptographic functions
|
|||||||
DROP TABLE IF EXISTS auth.accounts CASCADE;
|
DROP TABLE IF EXISTS auth.accounts CASCADE;
|
||||||
CREATE TABLE IF NOT EXISTS auth.accounts (
|
CREATE TABLE IF NOT EXISTS auth.accounts (
|
||||||
userid UUID NOT NULL UNIQUE DEFAULT uuid_generate_v4(),
|
userid UUID NOT NULL UNIQUE DEFAULT uuid_generate_v4(),
|
||||||
email text primary key check ( email ~* '^.+@.+\..+$' ),
|
email CITEXT primary key check ( email ~* '^.+@.+\..+$' ),
|
||||||
first text not null check (length(pass) < 512),
|
first text not null check (length(pass) < 512),
|
||||||
last text not null check (length(pass) < 512),
|
last text not null check (length(pass) < 512),
|
||||||
pass text not null check (length(pass) < 512),
|
pass text not null check (length(pass) < 512),
|
||||||
@@ -55,7 +55,7 @@ COMMENT ON TRIGGER accounts_moddatetime
|
|||||||
DROP TABLE IF EXISTS auth.vessels;
|
DROP TABLE IF EXISTS auth.vessels;
|
||||||
CREATE TABLE IF NOT EXISTS auth.vessels (
|
CREATE TABLE IF NOT EXISTS auth.vessels (
|
||||||
vesselid TEXT NOT NULL UNIQUE DEFAULT RIGHT(gen_random_uuid()::text, 12),
|
vesselid TEXT NOT NULL UNIQUE DEFAULT RIGHT(gen_random_uuid()::text, 12),
|
||||||
owner_email TEXT PRIMARY KEY REFERENCES auth.accounts(email) ON DELETE RESTRICT,
|
owner_email CITEXT PRIMARY KEY REFERENCES auth.accounts(email) ON DELETE RESTRICT,
|
||||||
mmsi TEXT UNIQUE, -- Should be a numeric range between 100000000 and 800000000.
|
mmsi TEXT UNIQUE, -- Should be a numeric range between 100000000 and 800000000.
|
||||||
-- mmsi NUMERIC UNIQUE, -- MMSI can be optional but if present must be a valid one
|
-- mmsi NUMERIC UNIQUE, -- MMSI can be optional but if present must be a valid one
|
||||||
name TEXT NOT NULL CHECK (length(name) >= 3 AND length(name) < 512),
|
name TEXT NOT NULL CHECK (length(name) >= 3 AND length(name) < 512),
|
||||||
@@ -73,7 +73,7 @@ COMMENT ON TABLE
|
|||||||
-- Indexes
|
-- Indexes
|
||||||
CREATE INDEX vessels_role_idx ON auth.vessels (role);
|
CREATE INDEX vessels_role_idx ON auth.vessels (role);
|
||||||
CREATE INDEX vessels_name_idx ON auth.vessels (name);
|
CREATE INDEX vessels_name_idx ON auth.vessels (name);
|
||||||
CREATE INDEX vessels_vesseid_idx ON auth.vessels (vesseid);
|
CREATE INDEX vessels_vesselid_idx ON auth.vessels (vesselid);
|
||||||
|
|
||||||
CREATE TRIGGER vessels_moddatetime
|
CREATE TRIGGER vessels_moddatetime
|
||||||
BEFORE UPDATE ON auth.vessels
|
BEFORE UPDATE ON auth.vessels
|
||||||
|
@@ -10,7 +10,8 @@ select current_database();
|
|||||||
|
|
||||||
DROP TABLE IF EXISTS auth.otp;
|
DROP TABLE IF EXISTS auth.otp;
|
||||||
CREATE TABLE IF NOT EXISTS auth.otp (
|
CREATE TABLE IF NOT EXISTS auth.otp (
|
||||||
user_email TEXT NOT NULL PRIMARY KEY REFERENCES auth.accounts(email) ON DELETE RESTRICT,
|
-- update type to CITEXT, https://www.postgresql.org/docs/current/citext.html
|
||||||
|
user_email CITEXT NOT NULL PRIMARY KEY REFERENCES auth.accounts(email) ON DELETE RESTRICT,
|
||||||
otp_pass VARCHAR(10) NOT NULL,
|
otp_pass VARCHAR(10) NOT NULL,
|
||||||
otp_timestamp TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW(),
|
otp_timestamp TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW(),
|
||||||
otp_tries SMALLINT NOT NULL DEFAULT '0'
|
otp_tries SMALLINT NOT NULL DEFAULT '0'
|
||||||
@@ -51,14 +52,14 @@ DROP FUNCTION IF EXISTS api.generate_otp_fn;
|
|||||||
CREATE OR REPLACE FUNCTION api.generate_otp_fn(IN email TEXT) RETURNS TEXT
|
CREATE OR REPLACE FUNCTION api.generate_otp_fn(IN email TEXT) RETURNS TEXT
|
||||||
AS $generate_otp$
|
AS $generate_otp$
|
||||||
DECLARE
|
DECLARE
|
||||||
_email TEXT := email;
|
_email CITEXT := email;
|
||||||
_email_check TEXT := NULL;
|
_email_check TEXT := NULL;
|
||||||
otp_pass VARCHAR(10) := NULL;
|
otp_pass VARCHAR(10) := NULL;
|
||||||
BEGIN
|
BEGIN
|
||||||
IF email IS NULL OR _email IS NULL OR _email = '' THEN
|
IF email IS NULL OR _email IS NULL OR _email = '' THEN
|
||||||
RAISE EXCEPTION 'invalid input' USING HINT = 'check your parameter';
|
RAISE EXCEPTION 'invalid input' USING HINT = 'check your parameter';
|
||||||
END IF;
|
END IF;
|
||||||
SELECT lower(a.email) INTO _email_check FROM auth.accounts a WHERE lower(a.email) = lower(_email);
|
SELECT lower(a.email) INTO _email_check FROM auth.accounts a WHERE a.email = _email;
|
||||||
IF _email_check IS NULL THEN
|
IF _email_check IS NULL THEN
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
END IF;
|
END IF;
|
||||||
@@ -227,7 +228,7 @@ DROP FUNCTION IF EXISTS auth.telegram_user_exists_fn;
|
|||||||
CREATE OR REPLACE FUNCTION auth.telegram_user_exists_fn(IN email TEXT, IN chat_id BIGINT) RETURNS BOOLEAN
|
CREATE OR REPLACE FUNCTION auth.telegram_user_exists_fn(IN email TEXT, IN chat_id BIGINT) RETURNS BOOLEAN
|
||||||
AS $telegram_user_exists$
|
AS $telegram_user_exists$
|
||||||
declare
|
declare
|
||||||
_email TEXT := email;
|
_email CITEXT := email;
|
||||||
_chat_id BIGINT := chat_id;
|
_chat_id BIGINT := chat_id;
|
||||||
BEGIN
|
BEGIN
|
||||||
IF _email IS NULL OR _chat_id IS NULL THEN
|
IF _email IS NULL OR _chat_id IS NULL THEN
|
||||||
@@ -236,7 +237,7 @@ AS $telegram_user_exists$
|
|||||||
-- Does user and telegram obj
|
-- Does user and telegram obj
|
||||||
SELECT preferences->'telegram'->'id' INTO _chat_id
|
SELECT preferences->'telegram'->'id' INTO _chat_id
|
||||||
FROM auth.accounts a
|
FROM auth.accounts a
|
||||||
WHERE lower(a.email) = lower(_email)
|
WHERE a.email = _email
|
||||||
AND cast(preferences->'telegram'->'id' as BIGINT) = _chat_id::BIGINT;
|
AND cast(preferences->'telegram'->'id' as BIGINT) = _chat_id::BIGINT;
|
||||||
IF FOUND THEN
|
IF FOUND THEN
|
||||||
RETURN TRUE;
|
RETURN TRUE;
|
||||||
|
Reference in New Issue
Block a user