From 91e23d57eb2088235e6b9a293d70b67a789461e1 Mon Sep 17 00:00:00 2001 From: Ariga Bot <98804354+ariga-bot@users.noreply.github.com> Date: Sun, 27 Oct 2024 16:04:36 +0200 Subject: [PATCH] Added a CHECK constraint to ensure that the 'phone_number' column in 'users' table only contains digits, allowing for a maximum of 15 characters. (#103) Co-authored-by: GitHub Gen Changes <> --- dirs/ecommerce/migrations/20241027112248.sql | 2 ++ dirs/ecommerce/migrations/atlas.sum | 3 ++- dirs/ecommerce/schema.sql | 5 +++-- 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 dirs/ecommerce/migrations/20241027112248.sql diff --git a/dirs/ecommerce/migrations/20241027112248.sql b/dirs/ecommerce/migrations/20241027112248.sql new file mode 100644 index 0000000..02e5738 --- /dev/null +++ b/dirs/ecommerce/migrations/20241027112248.sql @@ -0,0 +1,2 @@ +-- Modify "users" table +ALTER TABLE `users` ADD CONSTRAINT `users_chk_2` CHECK (regexp_like(`phone_number`,_utf8mb4'^[0-9]{1,15}$')); diff --git a/dirs/ecommerce/migrations/atlas.sum b/dirs/ecommerce/migrations/atlas.sum index 5addb1a..095aa9a 100644 --- a/dirs/ecommerce/migrations/atlas.sum +++ b/dirs/ecommerce/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:C0qh5Td3scs/xBoJEhSBkly6IP49GaH19aeFxHzpZXM= +h1:41GMD5Qi34HG+UJPkQ0XWLAEDpv2X0AEFG0+I2gvlYo= 20230316085611.sql h1:br6W6LPEnnsejlz/7hRm9zthwStCzjN2vZkqVPxlmvo= 20230316090502.sql h1:GfeRjkSeoCt3JVRtLQNa/r50lRfpAPXS7AqTU2ZNFgY= 20230531091333_products_categories.sql h1:59q2M59dV5dJNv4Lyb2TAJz8V6HekgkLn9z4DoL98jA= @@ -52,3 +52,4 @@ h1:C0qh5Td3scs/xBoJEhSBkly6IP49GaH19aeFxHzpZXM= 20241017131153.sql h1:yTRRglIJ2ckWSjqrI3yzVhUXeWgIRIzYjetlGnxEMVk= 20241020130953.sql h1:Tvps4LR+l6bKFHNb82EY4SGzhPvCYXx3nwvFDjFRDac= 20241022103333_add_comments.sql h1:/H61oAHrzxI4ZgrNQMApyTLkYeOKZB4qaATCEHJHFI8= +20241027112248.sql h1:Uz/zd2cH0VzbQuO8TcENLacZimgQA9XIdHmL+det8Lc= diff --git a/dirs/ecommerce/schema.sql b/dirs/ecommerce/schema.sql index 92560ea..f153c04 100644 --- a/dirs/ecommerce/schema.sql +++ b/dirs/ecommerce/schema.sql @@ -19,7 +19,8 @@ CREATE TABLE `users` ( UNIQUE INDEX `email` (`email`), UNIQUE INDEX `user_name` (`user_name`), UNIQUE INDEX `phone_number` (`phone_number`), - CHECK (`email` REGEXP '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$') + CHECK (`email` REGEXP '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'), + CHECK (`phone_number` REGEXP '^[0-9]{1,15}$') ) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT 'Table storing user information, including authentication and profile details'; -- Create 'categories' table @@ -147,4 +148,4 @@ CREATE TABLE `payment_methods` ( PRIMARY KEY (`id`), INDEX `user_id` (`user_id`), CONSTRAINT `payment_methods_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE - ) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci; \ No newline at end of file + ) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci;