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

Fix #363: Creation of template with the same name #371

Merged
merged 5 commits into from
Dec 7, 2020

Conversation

parauliya
Copy link
Contributor

@parauliya parauliya commented Nov 23, 2020

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:

  • updated the documentation and/or roadmap (if required)
  • added unit or e2e tests
  • provided instructions on how to upgrade

@parauliya parauliya added the kind/bug Categorizes issue or PR as related to a bug. label Nov 23, 2020
@parauliya parauliya self-assigned this Nov 23, 2020
@@ -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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@codecov
Copy link

codecov bot commented Dec 3, 2020

Codecov Report

Merging #371 (0f7e7de) into master (fe762e8) will increase coverage by 1.34%.
The diff coverage is 83.33%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
grpc-server/workflow.go 29.55% <81.81%> (+8.55%) ⬆️
grpc-server/template.go 36.53% <100.00%> (ø)

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 fe762e8...0f7e7de. Read the comment docs.

@parauliya parauliya marked this pull request as ready for review December 3, 2020 14:19
@parauliya parauliya changed the title [WIP] : Fix #363: Creation of template with the same name Fix #363: Creation of template with the same name Dec 3, 2020
@parauliya parauliya requested a review from gianarb December 4, 2020 07:02
Copy link
Contributor

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

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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?

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 have made GetTemplate API smarter and removed this new API.

Copy link
Contributor Author

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

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?

Copy link
Contributor Author

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.

@parauliya parauliya force-pushed the Fix_363 branch 2 times, most recently from 9825cb1 to c370c87 Compare December 7, 2020 05:09
@parauliya parauliya requested review from kqdeng and gianarb December 7, 2020 07:08
gianarb
gianarb previously approved these changes Dec 7, 2020
Copy link
Contributor

@gianarb gianarb left a 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

@gianarb gianarb added the ready-to-merge Signal to Mergify to merge the PR. label Dec 7, 2020
@mergify mergify bot merged commit 1992c1c into tinkerbell:master Dec 7, 2020

func Get202012041103() *migrate.Migration {
return &migrate.Migration{
Id: "202010221010-remove-unique-index",
Copy link
Contributor

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)
Copy link
Contributor

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.

jonawong pushed a commit that referenced this pull request Dec 11, 2020
Introduced by #371 the migration
has a wrong ID.

Signed-off-by: Gianluca Arbezzano <[email protected]>
Signed-off-by: Jonathan Wong <[email protected]>
@mmlb mmlb mentioned this pull request Jan 23, 2021
3 tasks
mergify bot added a commit that referenced this pull request Jan 25, 2021
## 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
@mmlb mmlb removed the ready-to-merge Signal to Mergify to merge the PR. label Jan 25, 2021
@parauliya parauliya deleted the Fix_363 branch February 25, 2021 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creating a template sharing the same name as a deleted template causes an error
5 participants