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

Refeshes all tables in Hub DB #301

Merged
merged 1 commit into from
Aug 5, 2021
Merged

Conversation

PuneetPunamiya
Copy link
Member

  • 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

Changes

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes tests (if functionality changed/added)
  • Run API Unit Tests, Lint Checks, API Design, Golden Files with make api-check
  • Run UI Unit Tests, Lint Checks with make ui-check
  • Commit messages follow commit message best practices

See the contribution guide for more details.

@tekton-robot tekton-robot requested review from sm43 and sthaha July 30, 2021 11:51
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 30, 2021
Copy link
Member

@vinamra28 vinamra28 left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 2, 2021
@pratap0007
Copy link
Contributor

/lgtm

updateResourcesCategoryTable(log),
removeExistingCategories(log),
Copy link
Member

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?

Copy link
Member

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?

Copy link
Member

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

Copy link
Member

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

Copy link
Member

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?

Copy link
Member

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{},
Copy link
Member

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 😸

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

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

@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Aug 2, 2021
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 2, 2021

CLA Signed

The committers are authorized under a signed CLA.

@vinamra28 vinamra28 force-pushed the fix-gorm branch 3 times, most recently from 4454e10 to 520ddae Compare August 2, 2021 09:24
@PuneetPunamiya PuneetPunamiya force-pushed the fix-gorm branch 6 times, most recently from 7ba466d to 137fe44 Compare August 4, 2021 07:06
@vinamra28
Copy link
Member

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 4, 2021
@PuneetPunamiya
Copy link
Member Author

/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 {
Copy link
Member

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
??

Copy link
Member Author

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 ??

Copy link
Member

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

Copy link
Member Author

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 {
Copy link
Member

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

Copy link
Member Author

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

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 :)

@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Aug 4, 2021
@PuneetPunamiya PuneetPunamiya force-pushed the fix-gorm branch 2 times, most recently from 1b2aa3f to af3b807 Compare August 5, 2021 04:27
 - 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>
Copy link
Member

@vinamra28 vinamra28 left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 5, 2021
@piyush-garg
Copy link
Contributor

/lgtm

@sm43
Copy link
Member

sm43 commented Aug 5, 2021

/approve
/meow

@tekton-robot
Copy link

@sm43: cat image

In response to this:

/approve
/meow

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.

@tekton-robot
Copy link

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 5, 2021
@tekton-robot tekton-robot merged commit 9488f5d into tektoncd:main Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants