-
Notifications
You must be signed in to change notification settings - Fork 2
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
Update URL to url in field_type enum #1032
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1032 +/- ##
=======================================
Coverage 88.57% 88.57%
=======================================
Files 129 129
Lines 1725 1725
Branches 220 213 -7
=======================================
Hits 1528 1528
Misses 197 197 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe BaseField.ts
will need to be updated too, correct?
diff --git a/src/types/BaseField.ts b/src/types/BaseField.ts
index c0d9c61..6af8a4d 100644
--- a/src/types/BaseField.ts
+++ b/src/types/BaseField.ts
@@ -7,7 +7,7 @@ export enum BaseFieldDataType {
NUMBER = 'number',
PHONE_NUMBER = 'phone_number',
EMAIL = 'email',
- URL = 'URL',
+ URL = 'url',
BOOLEAN = 'boolean',
}
I do believe you are correct @reefdog ! Updating and force pushing now |
83ee966
to
4ee3d3a
Compare
ELSE data_type::text::updated_field_type | ||
END; | ||
DROP TYPE field_type CASCADE; | ||
ALTER TYPE updated_field_type RENAME to field_type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. I thought for a minute there may be another more brief way of doing it but this is probably the straightest-forward approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, and I have no qualms. I was curious though so asked GPT how it would do it:
-- Step 1: Add the new value to the enum type
ALTER TYPE user_type ADD VALUE 'boss';
-- Step 2: Update the table to use the new value
UPDATE users SET user_type = 'boss' WHERE user_type = 'BOSS';
-- Step 3: Remove the old value (PostgreSQL does not support removing enum values directly)
-- So instead, create a new type without 'BOSS' and replace the old type
-- Create a new enum type without 'BOSS'
CREATE TYPE user_type_new AS ENUM('boss', /* other values */);
-- Alter the table to use the new enum type
ALTER TABLE users
ALTER COLUMN user_type TYPE user_type_new
USING user_type::text::user_type_new;
-- Drop the old enum type
DROP TYPE user_type;
-- Rename the new enum type to the original name
ALTER TYPE user_type_new RENAME TO user_type;
It's very similar to your approach, but by adding the url
value to the original type / updating the fields to use url
, and then swapping the enum to one without the (now unused URL
) you could avoid the complexity of the CASE
statement.
I defer to you @hminsky2002 on which you prefer!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@slifty I think that avoiding a case statement is preferable!
I shall edit this commit with gusto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following up here since Harry and I went offline to do some rapid back and forth -- Harry did implement this change but psql doesn't like using enums that aren't committed in a transaction (idk why, but whatever.)
Having two migrations felt nastier than a case statement, so he landed back where he started with the case statement!
That was fun :D
@@ -7,7 +7,7 @@ export enum BaseFieldDataType { | |||
NUMBER = 'number', | |||
PHONE_NUMBER = 'phone_number', | |||
EMAIL = 'email', | |||
URL = 'URL', | |||
URL = 'url', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
@hminsky2002 just to confirm I don't see the change yet, unless I'm missing it! |
ff4e09b
to
7b54f46
Compare
@slifty apologies, I was running into an issue where altering the enum was failing the migration, with the error |
7b54f46
to
e624de1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
This commit remedies a typo from the field_type enum, which is used to validate the type of a basefield. The value of 'url' was originally capitalized as 'URL', but this goes against our convention. It adds a new migration, and updates the seed file accordingly Issue #989 Update URL enum value to url
e624de1
to
3e56720
Compare
This PR remedies a typo from the field_type enum, which is used to validate the type of a basefield. The value of 'url' was originally capitalized as 'URL', but this goes against our convention. It adds a new migration, and updates the seed file accordingly. Notably, it also casts any existing base-fields with type 'URL' to 'url'
Closes #989