Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema update #110

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dirs/ecommerce/migrations/20241112131146.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Modify "users" table
ALTER TABLE `users` DROP CHECK `users_chk_1`, ADD CONSTRAINT `users_chk_1` CHECK (regexp_like(`email_address`,_utf8mb4'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$')), DROP COLUMN `email`, ADD COLUMN `email_address` varchar(255) NOT NULL, ADD UNIQUE INDEX `email_address` (`email_address`);

Check failure on line 2 in dirs/ecommerce/migrations/20241112131146.sql

View workflow job for this annotation

GitHub Actions / atlas

destructive changes detected

Dropping non-virtual column "email" (DS103) Details: https://atlasgo.io/lint/analyzers#DS103

Check failure on line 2 in dirs/ecommerce/migrations/20241112131146.sql

View workflow job for this annotation

GitHub Actions / atlas

data dependent changes detected

Adding a non-nullable "varchar" column "email_address" on table "users" without a default value implicitly sets existing rows with "" (MY101) Details: https://atlasgo.io/lint/analyzers#MY101
Comment on lines +1 to +2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

destructive changes detected
Dropping non-virtual column "email" DS103

Add a pre-migration check to ensure column "email" is NULL before dropping it

Suggested change
-- Modify "users" table
ALTER TABLE `users` DROP CHECK `users_chk_1`, ADD CONSTRAINT `users_chk_1` CHECK (regexp_like(`email_address`,_utf8mb4'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$')), DROP COLUMN `email`, ADD COLUMN `email_address` varchar(255) NOT NULL, ADD UNIQUE INDEX `email_address` (`email_address`);
-- atlas:txtar
-- checks/destructive.sql --
-- atlas:assert DS103
SELECT NOT EXISTS (SELECT 1 FROM `users` WHERE `email` IS NOT NULL) AS `is_empty`;
-- migration.sql --
-- Modify "users" table
ALTER TABLE `users` DROP CHECK `users_chk_1`, ADD CONSTRAINT `users_chk_1` CHECK (regexp_like(`email_address`,_utf8mb4'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$')), DROP COLUMN `email`, ADD COLUMN `email_address` varchar(255) NOT NULL, ADD UNIQUE INDEX `email_address` (`email_address`);

Ensure to run atlas migrate hash --dir "file://dirs/ecommerce/migrations" after applying the suggested changes.

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:mQ4os5dvdZVxq9ucRsiEYty95umfc04MMDQfT68e+VI=
h1:/9r4FymEqj6PfXOQjTlim5Jc3Nxiv3gErAIpTbdUVqM=
20230316085611.sql h1:br6W6LPEnnsejlz/7hRm9zthwStCzjN2vZkqVPxlmvo=
20230316090502.sql h1:GfeRjkSeoCt3JVRtLQNa/r50lRfpAPXS7AqTU2ZNFgY=
20230531091333_products_categories.sql h1:59q2M59dV5dJNv4Lyb2TAJz8V6HekgkLn9z4DoL98jA=
Expand Down Expand Up @@ -59,3 +59,4 @@ h1:mQ4os5dvdZVxq9ucRsiEYty95umfc04MMDQfT68e+VI=
20241105131055.sql h1:Pa43oRSXYgYlTyRPmz+ifOUdjC37MBxXty/y6GLCaqk=
20241107131023.sql h1:ZCiG0I6S1KZRirv89U4894V9ZBuG6ChLYDuPyWC098c=
20241110130904.sql h1:qRQ+S6KPxiFyp8VxRMkZIFVop3rO1qrS3EJpKz2gjhw=
20241112131146.sql h1:jr03WRQUeJi4bfjc0zlDXaq7D+AlZPYaY4YbKE5TalA=
6 changes: 3 additions & 3 deletions dirs/ecommerce/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
CREATE TABLE `users` (
`id` int NOT NULL COMMENT 'Unique identifier for each user',
`user_name` varchar(255) NOT NULL COMMENT 'The username of the user, must be unique',
`email` varchar(255) NOT NULL,
`email_address` varchar(255) NOT NULL,
`phone_number` varchar(15) NOT NULL,
`country_code` varchar(5) NOT NULL DEFAULT '+1' COMMENT 'Country code for the phone number, defaults to US',
`is_admin` bool NULL DEFAULT 0 COMMENT 'Flag indicating if the user is an admin, defaults to false',
Expand All @@ -17,10 +17,10 @@ CREATE TABLE `users` (
`phone_verified` bool NOT NULL DEFAULT 0 COMMENT 'Flag indicating if the user phone number is verified, defaults to false',
`deleted_at` timestamp NULL COMMENT 'Timestamp for soft deletion of the user record',
PRIMARY KEY (`id`),
UNIQUE INDEX `email` (`email`),
UNIQUE INDEX `email_address` (`email_address`),
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_address` 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';

Expand Down
Loading