-
Notifications
You must be signed in to change notification settings - Fork 138
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
Template revision #438
Template revision #438
Conversation
ea407bd
to
ead2309
Compare
c105880
to
117d200
Compare
Codecov Report
@@ Coverage Diff @@
## master #438 +/- ##
==========================================
+ Coverage 35.82% 37.92% +2.10%
==========================================
Files 47 48 +1
Lines 2892 3032 +140
==========================================
+ Hits 1036 1150 +114
- Misses 1763 1775 +12
- Partials 93 107 +14
Continue to review full report at Codecov.
|
5d0640c
to
e031ce4
Compare
db/db.go
Outdated
@@ -42,6 +42,7 @@ type template interface { | |||
DeleteTemplate(ctx context.Context, name string) error | |||
ListTemplates(in string, fn func(id, n string, in, del *timestamp.Timestamp) error) error | |||
UpdateTemplate(ctx context.Context, name string, data string, id uuid.UUID) error | |||
ListTemplateRevisions(id string, fn func(id string, revision int, tCr *timestamp.Timestamp) error) 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.
Let's try to write something a bit more readable:
ListRevisionsByTemplateID(templateID string, fn func(revisionID string, revision int, tCr *timestamp.Timestamp) error) error
I am not sure what revisiononID string
and revision int
are
db/db.go
Outdated
@@ -81,6 +82,19 @@ func (t *TinkDB) Migrate() (int, error) { | |||
return migrate.Exec(t.instance, "postgres", migration.GetMigrations(), migrate.Up) | |||
} | |||
|
|||
// WithMigrations applies only the given migrations. | |||
// It is required to unit test migrations. | |||
func (t *TinkDB) WithMigrations(migrations []func() *migrate.Migration) 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 think we need this function for mainly one reason. This is a new API that should not be used outside of tests
. So it is in the wrong place, it should be exposed via TinkDB
because it allows developers to use it outside of tests, and we do not want that.
Another reason is that it does not add much value or simplification you use it this way:
err := tinkDB.WithMigrations([]func() *migrate.Migration{
migration.Get202009171251,
migration.Get202010071530,
migration.Get202010221010,
migration.Get202012041103,
migration.Get202012091055,
migration.Get2020121691335,
})
But you can get to the same point writing:
_, err := migrate.Exec(db, "postgres", migrate.MemoryMigrationSource{
Migrations: []*migrate.Migration{
migration.Get202009171251(),
migration.Get202010071530(),
migration.Get202010221010(),
migration.Get202012041103(),
migration.Get202012091055(),
migration.Get2020121691335(),
},
}, migrate.Up)
Almost same line of code. If you are wondering where db
is coming from:
db, tinkDB, cl := NewPostgresDatabaseClient(t, ctx, NewPostgresDatabaseRequest{})
db/template_test.go
Outdated
id := uuid.New().String() | ||
w.ID = id | ||
w.Name = fmt.Sprintf("id_%d", rand.Int()) | ||
err := createTemplateFromWorkflowType(ctx, tinkDB, w) |
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 test fails because the function CreateTemplate
already relies on revision. Even if you didn't apply the migration yet, the Go code assumes revision to be in place.
In order to fix that you have to add a template not via code but with a SQL query.
bb5d9cf
to
e9eee26
Compare
} | ||
} | ||
|
||
func createTemplatesFromSQL(ctx context.Context, db *sql.DB) 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.
Can you add a comment? I am sure the next person or even myself in a couple of days will not remember why we have this function and the name is so generic that it won't help
@gauravgahlot got from Dan and EM two databases containing different templates. We will use them as data sources for testing the migration against more data ❤️ |
e9eee26
to
44f2d71
Compare
Tested with the databases and it's working as expected. 🚀 |
When a workflow starts we have to keep track of the revision as well. To be able to figure out what it actually ran even after a couple of days, when it is likely possible that the template changed to a different revision. In preparation for exposing the actual revisions do you mind creating two GRPC requests as part of the TemplateService:
Please write tests for this as well and document the new API as part of the proto file |
d1b7c1f
to
9bbf4ef
Compare
9bbf4ef
to
74f3e07
Compare
Fixes: tinkerbell#413 The migration introduces template revisions. A template can have multiple revisions, which are stored in the 'template_revisions' table. The migration also transforms the existing templates to the new template-revisions structure. Therefore ensuring that end users do not face any issues with the introduction of revisions. Signed-off-by: Gaurav Gahlot <[email protected]>
Signed-off-by: Gaurav Gahlot <[email protected]>
Signed-off-by: Gaurav Gahlot <[email protected]>
Signed-off-by: Gaurav Gahlot <[email protected]>
Signed-off-by: Gaurav Gahlot <[email protected]>
Signed-off-by: Gaurav Gahlot <[email protected]>
Signed-off-by: Gaurav Gahlot <[email protected]>
Signed-off-by: Gaurav Gahlot <[email protected]>
d6ef61c
to
95afc12
Compare
As of today, the db.GetTemplate() method returns (string, string, string). The callers need to guess or look at the implementation code to figure out what is being returned. Signed-off-by: Gaurav Gahlot <[email protected]>
Signed-off-by: Gaurav Gahlot <[email protected]>
Is this PR ready to be re-reviewed? I noticed there were still some unresolved comments. |
The PR aimed to solve the issue with tink events. Now that we don't have events, we don't really need this PR (unless we are planning to reintroduce events). The issue itself can be closed as well. However, it would be great if @thebsdbox and @gianarb can confirm. |
@gianarb Please can you confirm ? |
I can confirm. Let's close it for now. Thanks a lot for your work I am sure if will be reused in the future |
Description
The PR introduces template revisions. The
template.Data
field will not contain the actual template but a reference to a particular revision. Revisions are immutable, when you update a template you create a new revision.Why is this needed
Fixes: #413
How Has This Been Tested?
Checklist:
I have: