-
Notifications
You must be signed in to change notification settings - Fork 137
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
Fix #363: Creation of template with the same name #371
Conversation
deploy/db/tinkerbell-init.sql
Outdated
@@ -13,7 +13,7 @@ CREATE INDEX IF NOT EXISTS idxgin_type ON hardware USING GIN (data JSONB_PATH_OP | |||
|
|||
CREATE TABLE IF NOT EXISTS template ( | |||
id UUID UNIQUE NOT NULL | |||
, name VARCHAR(200) UNIQUE NOT NULL | |||
, name VARCHAR(200) 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.
This is not used anymore. We use migrations now
https://github.com/tinkerbell/tink/tree/master/db/migration
You have to create a new migration file that ALTERS the current table
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.
Done
Codecov Report
@@ Coverage Diff @@
## master #371 +/- ##
==========================================
+ Coverage 24.74% 26.09% +1.34%
==========================================
Files 14 14
Lines 1277 1280 +3
==========================================
+ Hits 316 334 +18
+ Misses 940 921 -19
- Partials 21 25 +4
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.
A few comments and tests have to be written for this PR
db/template.go
Outdated
@@ -14,7 +14,14 @@ import ( | |||
|
|||
// CreateTemplate creates a new workflow template | |||
func (d TinkDB) CreateTemplate(ctx context.Context, name string, data string, id uuid.UUID) error { | |||
_, err := wflow.Parse([]byte(data)) |
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 are you doing this?! If the template is not valid we should not go further. Can you revert or explain why you moved this down 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.
Yes you are right. I moved it down by mistake. Will fix it.
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.
Done
db/db.go
Outdated
@@ -37,6 +37,7 @@ type hardware interface { | |||
type template interface { | |||
CreateTemplate(ctx context.Context, name string, data string, id uuid.UUID) error | |||
GetTemplate(ctx context.Context, fields map[string]string) (string, string, string, error) | |||
GetTemplateForWorkflow(ctx context.Context, fields map[string]string) (string, string, string, 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 don't want to expose another API if not needed. Can you make ListTemplates
smarter and remove this call?
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 have made GetTemplate
API smarter and removed this new API.
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.
Done
db/template.go
Outdated
FROM template | ||
WHERE | ||
` + getCondition + ` | ||
created_at IS 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.
when would created_at
be null? why is this condition needed?
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 code has been discarded.
9825cb1
to
c370c87
Compare
Signed-off-by: parauliya <[email protected]>
… same name which is not deleted Signed-off-by: parauliya <[email protected]>
Signed-off-by: parauliya <[email protected]>
Signed-off-by: parauliya <[email protected]>
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 is good for me. Thank you for taking the time to add coverage.
I have to say, the more I look at the database package, and more I think we are doing something wrong in there. I would really like to write it in a more consistent way. But it is not part of this work for sure :D
Signed-off-by: parauliya <[email protected]>
|
||
func Get202012041103() *migrate.Migration { | ||
return &migrate.Migration{ | ||
Id: "202010221010-remove-unique-index", |
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 id is wrong. Please use the same timestamp in the function name.
fields := map[string]string{ | ||
"name": name, | ||
} | ||
_, _, _, err = d.GetTemplate(ctx, fields, false) |
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 query is not in the same transaction as the following insert DML, thus is not concurrent safe.
Introduced by #371 the migration has a wrong ID. Signed-off-by: Gianluca Arbezzano <[email protected]> Signed-off-by: Jonathan Wong <[email protected]>
## Description Some quick/shallow test for migration definition. ## Why is this needed #371 introduced a migration where none of the names matched :D, the Id & FuncName was fixed in #383 but that one missed the file name. Why make humans do things they're bad at when instead we can make a computer do something its good at? So this is that :D. ## How Has This Been Tested? Ran `go test` and it found the bad file name. I artificially changed an Id and the test caught the FuncName|Id mismatch. ## How are existing users impacted? What migration steps/scripts do we need? N/A ## Checklist: I have: - [ ] updated the documentation and/or roadmap (if required) - [x] added unit or e2e tests - [ ] provided instructions on how to upgrade
Signed-off-by: parauliya [email protected]
Description
This PR will fix allow user to create a template with the same name after deleting it. Before this, it was not possible because of an issue also after deleting a template all the workflow which were created with that template before deleting it will be able to access the template since we template will be deleted softly.
Why is this needed
Fixes: #363
How Has This Been Tested?
Tested all the scenarios mentioned in the linked issue manually using vagrant setup.
How are existing users impacted? What migration steps/scripts do we need?
Have written a migration script for db.
Checklist:
I have: