Skip to content

Commit

Permalink
Added a CHECK constraint to ensure that the 'phone_number' column in …
Browse files Browse the repository at this point in the history
…'users' table only contains digits, allowing for a maximum of 15 characters. (#103)

Co-authored-by: GitHub Gen Changes <>
  • Loading branch information
ariga-bot authored Oct 27, 2024
1 parent f71d631 commit 91e23d5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions dirs/ecommerce/migrations/20241027112248.sql
Original file line number Diff line number Diff line change
@@ -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}$'));
3 changes: 2 additions & 1 deletion dirs/ecommerce/migrations/atlas.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down Expand Up @@ -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=
5 changes: 3 additions & 2 deletions dirs/ecommerce/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci;

0 comments on commit 91e23d5

Please sign in to comment.