-
Notifications
You must be signed in to change notification settings - Fork 674
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
MF-739 - Add ID to the User entity #1152
Conversation
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Codecov Report
@@ Coverage Diff @@
## master #1152 +/- ##
==========================================
- Coverage 74.56% 74.25% -0.31%
==========================================
Files 102 102
Lines 6946 6855 -91
==========================================
- Hits 5179 5090 -89
+ Misses 1415 1411 -4
- Partials 352 354 +2
Continue to review full report at Codecov.
|
password CHAR(60) NOT NULL | ||
)`, | ||
email VARCHAR(254) PRIMARY KEY, | ||
password CHAR(60) NOT NULL)`, |
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.
Move closing brackets in the next line, to mark clearly the block closing.
users/postgres/init.go
Outdated
}, | ||
Down: []string{"DROP TABLE users"}, | ||
}, | ||
{ | ||
Id: "users_2", | ||
Up: []string{ | ||
`ALTER TABLE IF EXISTS users ADD COLUMN IF NOT EXISTS metadata JSONB`, | ||
`ALTER TABLE IF EXISTS users ADD COLUMN IF NOT EXISTS | ||
metadata JSONB`, |
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.
No need to break in two lines IMHO.
users/uuid/idp.go
Outdated
@@ -0,0 +1,32 @@ | |||
// Copyright (c) Mainflux |
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.
Is the same one used for things (like UUIDv4 generator)? Maybe then can be moved to project root and mutualized between two packages?
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 agree, I wanted to propose this also. Especially because there are 3 services that use idp
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'll fix this for other services in a separate PR: https://github.com/mainflux/mainflux/issues/1154
@@ -83,16 +83,14 @@ func migrateDB(db *sqlx.DB) error { | |||
Id: "things_2", | |||
Up: []string{ | |||
`ALTER TABLE IF EXISTS things ALTER COLUMN | |||
metadata TYPE JSONB using metadata::text::jsonb | |||
`, | |||
metadata TYPE JSONB using metadata::text::jsonb`, |
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 kinda liked that this comma was in the new line. I am not saying that this is good solution, but I think it would be worth to check best practices when writing SQL strings in the code...
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 would follow the standard which is to don't add a new line. We are also following this standard in other services.
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.
@manuio I agree, I just suggested to check where this standard commens and if it widely accepted, not something just invented by us. How other big Go projects handle this problem?
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 think that there are 2 versions:
Up: []string{
`ALTER TABLE IF EXISTS channels ALTER COLUMN
metadata TYPE JSONB using metadata::text::jsonb`,
},
or
Up: []string{`
ALTER TABLE IF EXISTS channels ALTER COLUMN
metadata TYPE JSONB using metadata::text::jsonb`,
},
And I like the one that we are using
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 was expecting some research links... And my remark was about comma (,
) at the end of the statement, not backticks.
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.
@drasko the ,
still there
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.
Is it, but it is not in the new line. So this is what I am trying to figure out - should it be in a new line or not.
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.
In this case it's not a good proposition since it doesn't build, Lines are closed with ,
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.
How did it build before then?
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.
Because of the `,
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
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.
Generally looks, good. I will let others review as well it is importnant, but I think we are close.
uuid/idp.go
Outdated
@@ -0,0 +1,32 @@ | |||
// Copyright (c) Mainflux |
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.
Will we call this top leve package uuid
? It does not really implement uuid
, but rather our IdP...
I do not know, does not bother me much, but I'd like to her form @mainflux/maintainers
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 not an Identity provider.
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.
maybe we should rename it to uuid/uuid.go
?
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.
Make more sense to me @manuio or put it under /pkg
its really shared lib
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.
LGTM
users/postgres/users.go
Outdated
@@ -71,7 +71,7 @@ func (ur userRepository) UpdateUser(ctx context.Context, user users.User) error | |||
} | |||
|
|||
func (ur userRepository) RetrieveByID(ctx context.Context, email string) (users.User, error) { |
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.
If its RetrieveByID
why param is email
?
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.
@nmarcetic because in Users service we use email as unique ID. I can maybe rename the function
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.
Yea because we didn't have ID
but now when we introduce ID
, this should be changed.
uuid/idp.go
Outdated
@@ -0,0 +1,32 @@ | |||
// Copyright (c) Mainflux |
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 not an Identity provider.
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
// RetrieveByID retrieves user by its unique identifier (i.e. email). | ||
RetrieveByID(context.Context, string) (User, error) | ||
// RetrieveByEmail retrieves user by its unique identifier (i.e. email). | ||
RetrieveByEmail(ctx context.Context, email string) (User, error) |
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.
do we need RetrieveByID
too?
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Sorry for off topic, but do you have any plans to use this ID in references in relations instead of email (owner)? |
This makes sense to me, now when we have |
@sprql @nmarcetic yes, that's the idea. But we have to think about the backward compatibility of Things and Channels owner. |
Yea it will be a breaking change, make sense. Not sure how we can get backward compatibility, except migration scripts. Which can be tricky for us to do it. Let's think about this |
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Codecov Report
@@ Coverage Diff @@
## master #1152 +/- ##
==========================================
+ Coverage 77.25% 77.29% +0.03%
==========================================
Files 102 102
Lines 6816 6830 +14
==========================================
+ Hits 5266 5279 +13
Misses 1180 1180
- Partials 370 371 +1
Continue to review full report at Codecov.
|
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.
LGTM
* MF-739 - Add ID to the User entity Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Resolve remarks Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Move idp to project root Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Use RetrieveByEmail func and UUIDProvider Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rm idp.go Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix comment Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename UserInfo into ViewUser Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix ViewUser naming Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale manuel.imperiale@gmail.com