From b2da22dbaea6cbcfd64f327120170a1cf7a00b45 Mon Sep 17 00:00:00 2001 From: raczu Date: Mon, 3 Jun 2024 14:40:16 +0200 Subject: [PATCH 1/3] fix: change regexes to match more correct formats --- Database/init-constraints.sql | 12 ++-- Database/init-db.sql | 122 +++++++++++++++++----------------- 2 files changed, 67 insertions(+), 67 deletions(-) diff --git a/Database/init-constraints.sql b/Database/init-constraints.sql index 72272187..2c7ce16a 100644 --- a/Database/init-constraints.sql +++ b/Database/init-constraints.sql @@ -13,25 +13,25 @@ $$ LANGUAGE plpgsql STABLE; ALTER TABLE common.image ADD CONSTRAINT chk_object_fk CHECK (common.check_fk_exists(object_id, object_type)); -ALTER TABLE common.address ADD CONSTRAINT chk_address_street CHECK (street ~ '^[[:alnum:]]+(?:(\s)[[:alpha:]]+)*(\s(?:(\d+|\d+/\d+)))?$'); +ALTER TABLE common.address ADD CONSTRAINT chk_address_street CHECK (street ~ '^[[:alnum:]\s\-/.,#'']+(? Date: Mon, 3 Jun 2024 15:37:39 +0200 Subject: [PATCH 2/3] fix: country regex now match more correct formats --- Database/init-constraints.sql | 4 +- Database/init-db.sql | 122 +++++++++++++++++----------------- 2 files changed, 63 insertions(+), 63 deletions(-) diff --git a/Database/init-constraints.sql b/Database/init-constraints.sql index 2c7ce16a..523ba2ae 100644 --- a/Database/init-constraints.sql +++ b/Database/init-constraints.sql @@ -2,7 +2,7 @@ CREATE OR REPLACE FUNCTION common.check_fk_exists(object_id INT, object_type common.object_type) RETURNS BOOLEAN AS $$ BEGIN - IF object_type = 'User' THEN + IF object_type = 'User' THEN RETURN EXISTS (SELECT 1 FROM users.user WHERE "id" = object_id); ELSIF object_type = 'Event' THEN RETURN EXISTS (SELECT 1 FROM events.event WHERE "id" = object_id); ELSE RETURN FALSE; @@ -21,7 +21,7 @@ ALTER TABLE common.address ADD CONSTRAINT chk_address_city CHECK (city ~ '^[[:up ALTER TABLE common.address ADD CONSTRAINT chk_address_state CHECK (state ~ '^[[:upper:]][[:lower:]]+(?:(\s|-)[[:alpha:]]+)*$'); -ALTER TABLE common.address ADD CONSTRAINT chk_address_country CHECK (country ~ '^[[:upper:]][[:lower:]]+(?:\s[[:upper:]][[:lower:]]+){0,1}$'); +ALTER TABLE common.address ADD CONSTRAINT chk_address_country CHECK (country ~ '^[[:upper:]][[:alpha:]\s''-]*(? Date: Tue, 4 Jun 2024 00:17:43 +0200 Subject: [PATCH 3/3] fix: regex for surname now disallow multiple spaces --- Database/init-constraints.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Database/init-constraints.sql b/Database/init-constraints.sql index 523ba2ae..c433f1cc 100644 --- a/Database/init-constraints.sql +++ b/Database/init-constraints.sql @@ -29,7 +29,7 @@ ALTER TABLE users.user ADD CONSTRAINT chk_user_phone CHECK (phone ~ '^\+\d{1,3}\ ALTER TABLE users.user ADD CONSTRAINT chk_user_name CHECK (name ~ '^[[:upper:]][[:alpha:]\s''-]+$'); -ALTER TABLE users.user ADD CONSTRAINT chk_user_surname CHECK (surname ~ '^[[:alpha:]\s''-]*[^\s''-]+[[:alpha:]\s''-]*$'); +ALTER TABLE users.user ADD CONSTRAINT chk_user_surname CHECK (surname ~ '^[[:alpha:]]+(?:[\s''-][[:alpha:]]+)*$'); ALTER TABLE users.user ADD CONSTRAINT chk_user_username CHECK (username ~ '^[[:alnum:]_-]{4,}$');