Closed begedin closed 6 years ago
We should also make the database normalize this to lower.
Only way I can think of to achieve this would be via a trigger. Off the top of my head:
CREATE OR REPLACE FUNCTION lowercase_type() RETURNS trigger AS $lowercase_type$
BEGIN
NEW.foo = LOWER(NEW.foo);
RETURN NEW;
END;
$lowercase_type$;
CREATE TRIGGER lowercase_type_trigger BEFORE INSERT OR UPDATE ON users
FOR EACH ROW EXECUTE PROCEDURE lowercase_type();
This should be a separate migration in addition to the one above.
The up
migration should add the function and the trigger, in that order. The down
migration should remove the trigger, then the function.
I'm not sure there's a programmatic way to add a trigger/function with ecto, other than using execute/1
.
I think maybe that I had meant that we can index the type as LOWER()
rather than actually coerce the date itself to be lower. My mistake here.
Problem
The github user payload has a
type
field which can be"User"
,"Bot"
or"Organization".
With
"User"
and"Bot"
, we normalize these values during conversion into"user"
and"bot"
.However,
"Organization"
remains capitalized and is not changed when inserting/updating into our database. Any case where where the type is being saved as"Organization"
should be saved as"organization"
(lowercased).Subtasks
"Organization"
is normalized into the lowercase"organization"
lib/github/adapters/user.ex
, the functiontransform_type/1
is likely the only culprit"Organization"
to"organization"
on all user records of type"Organization"