-
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
Update the Catalog sync to delete the removed resources info from existing db #292
Update the Catalog sync to delete the removed resources info from existing db #292
Conversation
6c74cac
to
b29c628
Compare
b29c628
to
47be2b9
Compare
47be2b9
to
b90c97e
Compare
8ef9a39
to
5cca636
Compare
/test pull-tekton-hub-unit-tests |
5cca636
to
d112a15
Compare
/retest |
d112a15
to
a98edc8
Compare
a98edc8
to
1674c51
Compare
1674c51
to
63a4fa8
Compare
@@ -55,9 +56,6 @@ func Migrate(api *app.APIBase) error { | |||
&model.SyncJob{}, | |||
&model.Scope{}, | |||
&model.Config{}, | |||
&model.Platform{}, |
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 these from here ?
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.
These were added in the migration as well
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 removing platform
? the other 2 will be autocreated how platform will get created on a new db installation if we remove from here?
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.
here platforms is optional and we can keep or remove it,if we remove platforms from here it will get created by the automigration on a new db installation
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.
okay but I didn't understood why this is optional? 🤔 on new db creation initschema
hub/api/pkg/db/migration/migration.go
Line 47 in 3c1ec7d
migration.InitSchema(func(db *gorm.DB) error { |
and if platforms is not added there still it will get created
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
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.
So platform table is getting created because of this migration
func createPlatformTables(log *log.Logger) *gormigrate.Migration { |
63a4fa8
to
56a2b98
Compare
56a2b98
to
3c1ec7d
Compare
} | ||
|
||
// Delete the tags which doesn't belongs to any other existing resources | ||
func (s *syncer) deleteTag(txn *gorm.DB, log *zap.SugaredLogger, tags []model.ResourceTag) { |
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.
do we need to do this as part of this api ? 🤔 what if we have a clean up api which would remove things like this which are no longer required
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 yes , if we want to have a clean up api then how we would identify which things are no longer required ?
ID: "202107221500_add_ondelete_constraints", | ||
Migrate: func(db *gorm.DB) error { | ||
txn := db.Begin() | ||
|
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 create a function like this https://github.com/tektoncd/hub/blob/main/api/pkg/db/migration/202107291608_refresh_all_tables.go#L36
and handle the error in a different function instead of writing txn.Rollback
multiple times
3c1ec7d
to
f8f3086
Compare
return err | ||
} | ||
|
||
if err := txn.Exec("ALTER TABLE resource_categories ADD CONSTRAINT fk_resource_categories_resource FOREIGN KEY (resource_id) REFERENCES resources(id) ON DELETE CASCADE;").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.
Not mandatory just a thought can't we use update query from gorm instead of writing the whole query, else the patch looks fine to me
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.
For example
Drop Constraint
update column from table by adding foreign key constraints with on Delete cascade
For ref : https://gorm.io/docs/update.html#Update-single-column
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.
No, we can't do with gorm and with gorm CreateConstraint does't create
f8f3086
to
b2cfc4f
Compare
/test pull-tekton-hub-unit-tests |
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.
Platform linux/amd64
is getting deleted which is still there in the other resources. Could you please take a look at it once
/hold
b2cfc4f
to
a0a060e
Compare
Thanks 🙂 /approve /hold cancel |
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: PuneetPunamiya 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 |
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.
also at the time of migration from 1.4 to latest migration fails. Can you please look into this?
/hold
err := addOnDelete(txn, log) | ||
if err != nil { | ||
txn.Rollback() | ||
log.Error(err) |
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.
nit: I guess we can avoid logging this error since we are already logging the errors in addOnDelete
function
…sting db This patch includes following changes - Adds a migration to add `OnDelete:CASECADE` constraint on existing foreign key constraints - Update the catalog sync which compares hosted catalog resources to existing db info of resources for same catalog while syncing catalogs and delete resources info from the db if any resources from the hosted catalog are removed Signed-off-by: Shiv Verma <shverma@redhat.com>
a0a060e
to
81e16b4
Compare
@vinamra28 done, could you please take a look once more |
/hold cancel |
This patch includes following changes
OnDelete:CASECADE
constraint on existingforeign key constraints
existing db info of resources for same catalog while syncing catalogs and delete
resources info from the db if any resources from the hosted catalog are removed
Signed-off-by: Shiv Verma shverma@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.