Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Space id for wi, wit and tracker query #900

Merged
merged 36 commits into from Mar 6, 2017

Conversation

hectorj2f
Copy link

@hectorj2f hectorj2f commented Feb 28, 2017

related to: #685 and #766

This PR uses as base code the following PR #852

@hectorj2f hectorj2f self-assigned this Feb 28, 2017
@@ -22,7 +24,7 @@ type WorkItemRepository interface {
Load(ctx context.Context, ID string) (*app.WorkItem, error)
Save(ctx context.Context, wi app.WorkItem) (*app.WorkItem, error)
Delete(ctx context.Context, ID string) error
Create(ctx context.Context, typeID string, fields map[string]interface{}, creator uuid.UUID) (*app.WorkItem, error)
Create(ctx context.Context, typeID string, fields map[string]interface{}, creator, spaceID uuid.UUID) (*app.WorkItem, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think space_id should be after context as it's the highest level.

Copy link
Author

Choose a reason for hiding this comment

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

Alright!

@hectorj2f hectorj2f changed the title Space id for wi and wit Space id for wi, wit and tracker query Mar 2, 2017
Conflicts:
	controller/search_blackbox_test.go
	design/spaces.go
	migration/migration.go
@hectorj2f hectorj2f changed the title Space id for wi, wit and tracker query [WIP] Space id for wi, wit and tracker query Mar 3, 2017
@hectorj2f
Copy link
Author

@aslakknutsen @kwk I am still dealing with some tests failing... I ping you when it is ready

Conflicts:
	controller/iteration_test.go
	controller/workitemtype.go
	design/media_types.go
	design/user_types.go
	design/workitems.go
	migration/migration.go
	search/search_repository_blackbox_test.go
	test/work_item_repository.go
	workitem/undoable_wi_repo.go
	workitem/undoable_wi_type_repo.go
	workitem/workitem.go
	workitem/workitem_repository.go
	workitem/workitemtype_repository.go
	workitem/workitemtype_repository_blackbox_test.go
	workitem/workitemtype_repository_whitebox_test.go
Conflicts:
	controller/work-item-comments_test.go
	migration/migration.go
	search/search_repository_blackbox_test.go
	search/search_repository_whitebox_test.go
	test/work_item_repository.go
	workitem/workitem_repository.go
	workitem/workitem_repository_blackbox_test.go
@hectorj2f hectorj2f changed the title [WIP] Space id for wi, wit and tracker query Space id for wi, wit and tracker query Mar 6, 2017
@@ -106,11 +100,28 @@ func TestUpdateTrackerQuery(t *testing.T) {
t.Errorf("Id should be %s, but is %s", tqresult.ID, tqr.ID)
}

spaceType := "spaces"
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't you make a constant out of this variable ? I see it is also used in the getCreateTrackerQueryPayload function below.

Copy link
Author

Choose a reason for hiding this comment

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

yeah, I'll make it 👍.

TrackerID: result.ID,
}
tqpayload := getCreateTrackerQueryPayload(result.ID)

_, trackerquery := test.CreateTrackerqueryCreated(t, nil, nil, &tqController, &tqpayload)
_, created := test.ShowTrackerqueryOK(t, nil, nil, &tqController, trackerquery.ID)
if created != nil && created.ID != trackerquery.ID {
Copy link
Contributor

Choose a reason for hiding this comment

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

what about using require.True(...) instead ?

Copy link
Contributor

@xcoulon xcoulon left a comment

Choose a reason for hiding this comment

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

This looks good, but I have a question about the data of the existing work items: I saw a lot of changes like this one in the tests:

-	c.Data.Relationships = &app.WorkItemRelationships{
-		BaseType: &app.RelationBaseType{
-			Data: &app.BaseTypeData{
-				Type: "workitemtypes",
-				ID:   workitem.SystemBug,
-			},
+	c.Data.Relationships.BaseType = &app.RelationBaseType{
+		Data: &app.BaseTypeData{
+			Type: "workitemtypes",
+			ID:   workitem.SystemBug,
 		},

and I wonder if this has any impact on the existing work item data and if so, how do you handle the change in the database ?

tqPayload := fmt.Sprintf(`{
"query": "abcdefgh",
"schedule": "1 1 * * * *",
"trackerID": "%s",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use %[1]s, %[2]s, %[3]s instead of just %s. It's easier to understand then where each parameter goes.

Copy link
Author

Choose a reason for hiding this comment

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

They are just three input arguments :)... I can understand that if I have n > 5. Anyway I will check that

Copy link
Collaborator

Choose a reason for hiding this comment

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

The second and third parameter are the same, so why even bother passing in the third? Instead just repeat %[2]s ;)

_, space := test.CreateSpaceCreated(s.T(), s.workItemSvc.Context, s.workItemSvc, s.spaceCtrl, createSpacePayload)
require.NotNil(s.T(), space)
s.userSpaceID = *space.Data.ID
fmt.Printf("Created link space with ID: %s\n", *space.Data.ID)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

+1

// Create a work item link space
createSpacePayload := CreateSpacePayload("test-space", "description")
_, space := test.CreateSpaceCreated(s.T(), s.workItemSvc.Context, s.workItemSvc, s.spaceCtrl, createSpacePayload)
require.NotNil(s.T(), space)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this check is not needed as test.CreateSpaceCreated sort of guarantees that the space it not nil because it calls the Validate() method of each media type before returning the result. I know, there're a lot of places in the code where we do check for not nil on returned objects, but I think we don't have to do that. @aslakknutsen agree?

Copy link
Author

Choose a reason for hiding this comment

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

Well, if this is done in called function then it isn't need to repeat code. I could change that for the space but I won't do those changes in the other lines

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure.

@@ -289,7 +314,7 @@ func CreateWorkItem(workItemType satoriuuid.UUID, title string) *app.CreateWorki
}

// CreateWorkItemLinkType defines a work item link type
func CreateWorkItemLinkType(name string, sourceTypeID, targetTypeID, categoryID, spaceID satoriuuid.UUID) *app.CreateWorkItemLinkTypePayload {
func CreateWorkItemLinkType(name string, sourceTypeID, targetTypeID, categoryID, spaceID uuid.UUID) *app.CreateWorkItemLinkTypePayload {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Next time, please keep this refactoring / renaming work out of your main PR.

Copy link
Author

@hectorj2f hectorj2f Mar 6, 2017

Choose a reason for hiding this comment

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

Well, I agree with that cause I always ask about it. But this change was already started in many other files where I had to solve conflicts. So I had to resolve them, consequently and following the same procedure, I decided to apply those changes to the files I touched.
Maybe we should try to avoid those partial changes in the future.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes

createSpacePayload := CreateSpacePayload("test-space", "description")
_, space := test.CreateSpaceCreated(s.T(), s.svcSpace.Context, s.svcSpace, s.spaceCtrl, createSpacePayload)
s.spaceID = space.Data.ID
require.NotNil(s.T(), space)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you insist to DO test that space is not nil, then please do so before dereferencing it one line above ;)

Copy link
Author

Choose a reason for hiding this comment

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

Hehehe good one :)! I don't insist I just simply followed the code structured as done in many other places.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We dereference before checking for nil in other places as well?

Copy link
Author

Choose a reason for hiding this comment

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

I changed in one more place

}, "space %s will be created", id)
_, err := spaceRepo.Create(ctx, newSpace)
if err != nil {
return errs.WithStack(err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use return errs.Wrapf(err, "failed to create space %s", id) instead. It is more expressive. The WithStack calls have been put into the code automatically at one point and cannot be considered a very good practice for newly added code.

Copy link
Author

Choose a reason for hiding this comment

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

ack

@@ -0,0 +1,27 @@
-- Alter the table work_items
ALTER TABLE work_items ADD space_id uuid DEFAULT '{{index . 0}}' NOT NULL;;
Copy link
Collaborator

Choose a reason for hiding this comment

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

So this is okay, but only because you have a DEFAULT. Otherwise the NOT NULL part would have to be SET later.

Copy link
Author

Choose a reason for hiding this comment

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

Exactly, this is done like that on purpose

ALTER TABLE work_items ADD space_id uuid DEFAULT '{{index . 0}}' NOT NULL;;
-- Once we set the values to the default. We drop this default constraint
ALTER TABLE work_items ALTER space_id DROP DEFAULT;
ALTER TABLE work_items ADD FOREIGN KEY (space_id) REFERENCES spaces(id) ON DELETE CASCADE;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer to add the FK when adding the column:

ALTER TABLE work_items
  ADD space_id uuid
  DEFAULT '{{index . 0}}' NOT NULL
  REFERENCES spaces(id) ON DELETE CASCADE;

but yours is fine, too.

tq2 := app.TrackerQuery{
ID: strconv.FormatUint(tq.ID, 10),
Query: query,
Schedule: schedule,
TrackerID: tracker}
TrackerID: tracker,
Relationships: &app.TrackerQueryRelationships{
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like the following code block is repeated in each repository method and I wonder if you can outsource it into a function.

Copy link
Author

Choose a reason for hiding this comment

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

You wonder well ;)


trackerqueries2, _ := queryRepo.List(context.Background())
trackerqueries2, _ := queryRepo.List(ctx)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What exactly is the benefit of not using context.Background().

Copy link
Author

Choose a reason for hiding this comment

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

@kwk context.Backgroun is empty while ctx is initialized with some parameters that will later use.

Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks

@kwk
Copy link
Collaborator

kwk commented Mar 6, 2017

and I wonder if this has any impact on the existing work item data and if so, how do you handle the change in the database ?

@xcoulon see the SQL migration script in this PR. @hectorj2f adds a new column to each of the affected tables and references the space there by using a foreign key.

@codecov-io
Copy link

codecov-io commented Mar 6, 2017

Codecov Report

Merging #900 into master will decrease coverage by -0.22%.
The diff coverage is 77.98%.

@@            Coverage Diff             @@
##           master     #900      +/-   ##
==========================================
- Coverage   69.49%   69.28%   -0.22%     
==========================================
  Files          90       93       +3     
  Lines        6874     7009     +135     
==========================================
+ Hits         4777     4856      +79     
- Misses       1650     1707      +57     
+ Partials      447      446       -1
Impacted Files Coverage Δ
rest/url.go 100% <ø> (ø)
workitem/undoable_wi_repo.go 0% <0%> (ø)
main.go 0% <0%> (ø)
workitem/undoable_wi_type_repo.go 0% <0%> (ø)
controller/workitemtype.go 74.54% <100%> (ø)
workitem/workitem.go 77.27% <100%> (+2.27%)
workitem/workitemtype_repository.go 84.23% <100%> (+0.44%)
workitem/workitem_repository.go 71.98% <100%> (+0.12%)
space/space.go 70.48% <100%> (+2.09%)
controller/workitem.go 91.37% <100%> (+2.48%)
... and 25 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 2765006...460ae4f. Read the comment docs.

@xcoulon
Copy link
Contributor

xcoulon commented Mar 6, 2017

ok, thanks for confirming. And after reading my comment again, I think that the change I was referring to made no sense with regards to the data migration. Sorry about that.

@hectorj2f
Copy link
Author

@xcoulon @kwk I addressed your comments :). Let's see if the test pass successfully.

@@ -215,7 +215,7 @@ func ConvertIteration(request *goa.RequestData, itr *iteration.Iteration, additi
Relationships: &app.IterationRelations{
Space: &app.RelationGeneric{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not use NewSpaceRelation here as well?

Copy link
Author

Choose a reason for hiding this comment

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

Because we have two type of objects for the relation, relationSpace and relationGeneric. I could unify this in a different PR.

Copy link
Collaborator

@kwk kwk left a comment

Choose a reason for hiding this comment

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

Looking much better now.

@@ -101,10 +111,21 @@ func TestConvertTypeFromModels(t *testing.T) {
},
},
},
Relationships: &app.WorkItemTypeRelationships{
Space: &app.RelationSpaces{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not use NewSpaceRelation() here?

Copy link
Author

Choose a reason for hiding this comment

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

I missed that! thx

Copy link
Collaborator

@kwk kwk left a comment

Choose a reason for hiding this comment

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

LGTM Except some minor things.

Conflicts:
	controller/workitem_blackbox_test.go
	workitem/undoable_wi_repo.go
	workitem/undoable_wi_type_repo.go
@hectorj2f hectorj2f merged commit 0454ce9 into fabric8-services:master Mar 6, 2017
@hectorj2f hectorj2f deleted the space_id_wi_wit branch March 6, 2017 16:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants