-
Notifications
You must be signed in to change notification settings - Fork 104
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
Refeshes all tables in Hub DB #301
Conversation
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
/lgtm |
updateResourcesCategoryTable(log), | ||
removeExistingCategories(log), |
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 we removing migrations?
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.
don't we need to run them after refreshing the db?
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.
refreshAllTables this migration has to be run before all newly added migration, after that the remaning will be executed properly
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.
nope.... refresh_all_tables migration will do the job for us
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.
did you test this on a cluster?
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
} | ||
|
||
txn := db.Begin() | ||
if err := db.Migrator().DropTable(&model.Category{}, |
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 are starting a txn
but not using them while executing queries then how it would be helpful 😸
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.
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.
txn := db.Begin()
if err:= refreshDb(txn, log); err!=nil{
log error
txn.rollback()
}
txn.commit
and use txn passed for all queries
|
4454e10
to
520ddae
Compare
7ba466d
to
137fe44
Compare
/lgtm |
/test pull-tekton-hub-build-tests |
@@ -28,7 +27,7 @@ func removeExistingCategories(log *log.Logger) *gormigrate.Migration { | |||
return &gormigrate.Migration{ | |||
ID: "202107131802_remove_existing_categories", | |||
Migrate: func(db *gorm.DB) error { | |||
if err := db.Unscoped().Where("name IN ?", []string{"Deploy", "Editor", "Language", "Notification", "Others", "Test Framework"}).Delete(&model.Category{}).Error; err != nil { | |||
if err := db.Exec("DELETE FROM categories").Error; err != nil { |
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 we can remove this migration now. as we are updating the config refresh api to handle deletion
??
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.
But before running the api we need to fix the categories as well right ??
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.
to avoid deletion of all records which are not necessarily to be deleted we are updating the config refresh api
so refreshall migration will add those back in db
and when api server is started the new will get added the ones removed from config will get deleted
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 agreed on that but ones removed from config which are supposed to be deleted needs to be handled at the api level itself then right
return err | ||
} | ||
|
||
if len(catalog) > 0 { |
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.
just curious when we fetch records and insert as it is ... do the creation timestamp changes ? or remains same as before
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 it should remain the same since we are inserting the data which we have collected from the db itself and also the id for all is not changed so I think it should remain the same
@@ -15,11 +15,12 @@ | |||
# NOTE: | |||
# This record is added to make sure the sync_jobs table state remains same | |||
# for every catalog refresh test. not adding this will fails the test due to the | |||
# sequence which will be out of sync and have to manually bring it back in sync. | |||
# sequence which will be out of sync and have to manually bring it back in sync. | |||
# Error: ERROR: duplicate key value violates unique constraint "sync_jobs_pkey" | |||
|
|||
- id: 1 |
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.
jfyi the test didn't failed due to this record because we don't use this record in test.
see the note above :)
137fe44
to
264e7da
Compare
264e7da
to
e7e549f
Compare
1b2aa3f
to
af3b807
Compare
- This patch collects the existing data from db deletes the existing tables, recreates the tables back and inserts the data in order to update the db and makes it compatible with `gorm 2.0` Signed-off-by: Puneet Punamiya <ppunamiy@redhat.com>
af3b807
to
ca61af1
Compare
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
/lgtm |
/approve |
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sm43, vinamra28 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
the existing tables, recreates the tables back and
inserts the data in order to update the db and makes it
compatible with
gorm 2.0
Signed-off-by: Puneet Punamiya ppunamiy@redhat.com
Changes
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
make api-check
make ui-check
See the contribution guide for more details.