-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e04e305
Fix #363: Creation of template with the same name
ca6bf08
Added the check in CreateTemplate func for existing template with the…
595ce83
Incorporate review comment and few optimisation
dee0a3f
Added UT for GetWorkflow function
0f7e7de
Added UT for creating a template with same name after deleting one
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package migration | ||
|
||
import migrate "github.com/rubenv/sql-migrate" | ||
|
||
func Get202012041103() *migrate.Migration { | ||
return &migrate.Migration{ | ||
Id: "202010221010-remove-unique-index", | ||
Up: []string{` | ||
ALTER TABLE template DROP CONSTRAINT template_name_key; | ||
`}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,11 +19,17 @@ func (d TinkDB) CreateTemplate(ctx context.Context, name string, data string, id | |
return err | ||
} | ||
|
||
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 commentThe 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. |
||
if err != sql.ErrNoRows { | ||
return errors.New("Template with name '" + name + "' already exist") | ||
} | ||
tx, err := d.instance.BeginTx(ctx, &sql.TxOptions{Isolation: sql.LevelSerializable}) | ||
if err != nil { | ||
return errors.Wrap(err, "BEGIN transaction") | ||
} | ||
|
||
_, err = tx.Exec(` | ||
INSERT INTO | ||
template (created_at, updated_at, name, data, id) | ||
|
@@ -45,20 +51,31 @@ func (d TinkDB) CreateTemplate(ctx context.Context, name string, data string, id | |
return nil | ||
} | ||
|
||
// GetTemplate returns a workflow template | ||
func (d TinkDB) GetTemplate(ctx context.Context, fields map[string]string) (string, string, string, error) { | ||
// GetTemplate returns template which is not deleted | ||
func (d TinkDB) GetTemplate(ctx context.Context, fields map[string]string, deleted bool) (string, string, string, error) { | ||
getCondition, err := buildGetCondition(fields) | ||
if err != nil { | ||
return "", "", "", errors.Wrap(err, "failed to get template") | ||
} | ||
|
||
query := ` | ||
var query string | ||
if !deleted { | ||
query = ` | ||
SELECT id, name, data | ||
FROM template | ||
WHERE | ||
` + getCondition + ` | ||
` + getCondition + ` AND | ||
deleted_at IS NULL | ||
` | ||
} else { | ||
query = ` | ||
SELECT id, name, data | ||
FROM template | ||
WHERE | ||
` + getCondition + ` | ||
` | ||
} | ||
|
||
row := d.instance.QueryRowContext(ctx, query) | ||
id := []byte{} | ||
name := []byte{} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
The id is wrong. Please use the same timestamp in the function name.