Space id for wi, wit and tracker query #900
Conversation
Conflicts: work-item-link-blackbox_test.go work-item-link-type.go workitem/link/type.go workitem/link/type_repository.go
Conflicts: migration/migration.go
Conflicts: migration/migration.go
workitem/workitem_repository.go
Outdated
@@ -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) |
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 space_id should be after context as it's the highest level.
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.
Alright!
Conflicts: controller/search_blackbox_test.go design/spaces.go migration/migration.go
@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
controller/trackerquery_test.go
Outdated
@@ -106,11 +100,28 @@ func TestUpdateTrackerQuery(t *testing.T) { | |||
t.Errorf("Id should be %s, but is %s", tqresult.ID, tqr.ID) | |||
} | |||
|
|||
spaceType := "spaces" |
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.
shouldn't you make a constant out of this variable ? I see it is also used in the getCreateTrackerQueryPayload
function below.
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.
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 { |
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.
what about using require.True(...)
instead ?
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 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", |
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.
Please use %[1]s
, %[2]s
, %[3]s
instead of just %s
. It's easier to understand then where each parameter goes.
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.
They are just three input arguments :)... I can understand that if I have n > 5. Anyway I will check that
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.
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) |
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.
Please use s.T().Logf("Created link space with ID: %s\n", *space.Data.ID)
instead.
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.
+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) |
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 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?
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.
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
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.
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 { |
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.
Next time, please keep this refactoring / renaming work out of your main PR.
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.
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.
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.
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) |
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 you insist to DO test that space
is not nil
, then please do so before dereferencing it one line above ;)
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.
Hehehe good one :)! I don't insist I just simply followed the code structured as done in many other places.
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.
We dereference before checking for nil in other places as well?
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 changed in one more place
migration/migration.go
Outdated
}, "space %s will be created", id) | ||
_, err := spaceRepo.Create(ctx, newSpace) | ||
if err != nil { | ||
return errs.WithStack(err) |
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.
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.
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.
ack
@@ -0,0 +1,27 @@ | |||
-- Alter the table work_items | |||
ALTER TABLE work_items ADD space_id uuid DEFAULT '{{index . 0}}' 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.
So this is okay, but only because you have a DEFAULT
. Otherwise the NOT NULL
part would have to be SET
later.
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.
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; |
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 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{ |
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.
It looks like the following code block is repeated in each repository method and I wonder if you can outsource it into a 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.
You wonder well ;)
|
||
trackerqueries2, _ := queryRepo.List(context.Background()) | ||
trackerqueries2, _ := queryRepo.List(ctx) |
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.
What exactly is the benefit of not using context.Background()
.
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.
@kwk context.Backgroun is empty while ctx is initialized with some parameters that will later use.
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.
thanks
@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 Report
@@ 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
Continue to review full report at Codecov.
|
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. |
Conflicts: migration/migration.go
Conflicts: migration/migration.go
@@ -215,7 +215,7 @@ func ConvertIteration(request *goa.RequestData, itr *iteration.Iteration, additi | |||
Relationships: &app.IterationRelations{ | |||
Space: &app.RelationGeneric{ |
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.
Why not use NewSpaceRelation
here as well?
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 we have two type of objects for the relation, relationSpace and relationGeneric. I could unify this in a different PR.
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.
Looking much better now.
@@ -101,10 +111,21 @@ func TestConvertTypeFromModels(t *testing.T) { | |||
}, | |||
}, | |||
}, | |||
Relationships: &app.WorkItemTypeRelationships{ | |||
Space: &app.RelationSpaces{ |
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.
Why not use NewSpaceRelation() here?
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 missed that! thx
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 Except some minor things.
Conflicts: controller/workitem_blackbox_test.go workitem/undoable_wi_repo.go workitem/undoable_wi_type_repo.go
related to: #685 and #766
This PR uses as base code the following PR #852