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

MF-739 - Add ID to the User entity #1152

Merged
merged 12 commits into from
Jun 4, 2020
Merged

MF-739 - Add ID to the User entity #1152

merged 12 commits into from
Jun 4, 2020

Conversation

manuio
Copy link
Contributor

@manuio manuio commented Apr 30, 2020

Signed-off-by: Manuel Imperiale manuel.imperiale@gmail.com

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
@manuio manuio requested a review from a team as a code owner April 30, 2020 08:52
@codecov-io
Copy link

codecov-io commented Apr 30, 2020

Codecov Report

Merging #1152 into master will decrease coverage by 0.30%.
The diff coverage is 92.00%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
sdk/go/sdk.go 96.55% <ø> (+2.26%) ⬆️
users/api/responses.go 75.00% <ø> (-5.00%) ⬇️
users/users.go 80.48% <ø> (-4.52%) ⬇️
users/service.go 84.78% <60.00%> (-9.02%) ⬇️
things/postgres/init.go 93.22% <100.00%> (-0.53%) ⬇️
users/api/endpoint.go 83.09% <100.00%> (+0.38%) ⬆️
users/postgres/init.go 88.23% <100.00%> (-0.66%) ⬇️
users/postgres/users.go 53.62% <100.00%> (+1.62%) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0c016cd...d962fbc. Read the comment docs.

password CHAR(60) NOT NULL
)`,
email VARCHAR(254) PRIMARY KEY,
password CHAR(60) NOT NULL)`,
Copy link
Contributor

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.

},
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`,
Copy link
Contributor

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.

@@ -0,0 +1,32 @@
// Copyright (c) Mainflux
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

@manuio manuio May 1, 2020

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`,
Copy link
Contributor

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...

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

@manuio manuio May 1, 2020

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

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@drasko the , still there

Copy link
Contributor

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.

Copy link
Contributor Author

@manuio manuio May 1, 2020

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 ,

Copy link
Contributor

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?

Copy link
Contributor Author

@manuio manuio May 1, 2020

Choose a reason for hiding this comment

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

Because of the `,

manuio added 3 commits May 1, 2020 08:21
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Copy link
Contributor

@drasko drasko left a 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
Copy link
Contributor

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

Copy link
Collaborator

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.

Copy link
Contributor Author

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 ?

Copy link
Collaborator

@nmarcetic nmarcetic May 5, 2020

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

mteodor
mteodor previously approved these changes May 4, 2020
Copy link
Contributor

@mteodor mteodor left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -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) {
Copy link
Collaborator

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 ?

Copy link
Contributor Author

@manuio manuio May 5, 2020

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

Copy link
Collaborator

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
Copy link
Collaborator

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.

manuio added 2 commits May 6, 2020 09:13
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
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)
Copy link
Contributor

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>
mteodor
mteodor previously approved these changes May 6, 2020
@sprql
Copy link
Contributor

sprql commented May 8, 2020

Sorry for off topic, but do you have any plans to use this ID in references in relations instead of email (owner)?

@nmarcetic
Copy link
Collaborator

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 ID we should use it as unique resource identification, as we are doing for other entities in the system. @mainflux/maintainers what do you think?

@manuio
Copy link
Contributor Author

manuio commented May 11, 2020

@sprql @nmarcetic yes, that's the idea. But we have to think about the backward compatibility of Things and Channels owner.

@nmarcetic
Copy link
Collaborator

@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

@drasko drasko modified the milestone: 0.11.0 May 12, 2020
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-commenter
Copy link

Codecov Report

Merging #1152 into master will increase coverage by 0.03%.
The diff coverage is 82.69%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
pkg/sdk/go/sdk.go 96.55% <ø> (ø)
users/api/logging.go 0.00% <0.00%> (ø)
users/api/metrics.go 0.00% <0.00%> (ø)
users/users.go 80.48% <ø> (ø)
users/service.go 84.78% <84.61%> (-1.43%) ⬇️
things/postgres/init.go 93.22% <100.00%> (-0.23%) ⬇️
users/api/endpoint.go 83.09% <100.00%> (+1.00%) ⬆️
users/api/requests.go 73.33% <100.00%> (ø)
users/api/responses.go 75.00% <100.00%> (ø)
users/api/transport.go 79.56% <100.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7f3e2c1...8af0e06. Read the comment docs.

Copy link
Contributor

@mteodor mteodor left a comment

Choose a reason for hiding this comment

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

LGTM

@drasko drasko merged commit 97f8d65 into absmach:master Jun 4, 2020
@manuio manuio deleted the users branch June 4, 2020 20:58
manuio added a commit that referenced this pull request Oct 12, 2020
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants