-
Notifications
You must be signed in to change notification settings - Fork 361
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
Add an unique index to service_instance_operations #2929
Merged
philippthun
merged 8 commits into
cloudfoundry:main
from
sap-contributions:add-unique-index-to-resource-id-for-service-istances
Oct 10, 2022
Merged
Add an unique index to service_instance_operations #2929
philippthun
merged 8 commits into
cloudfoundry:main
from
sap-contributions:add-unique-index-to-resource-id-for-service-istances
Oct 10, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kathap
force-pushed
the
add-unique-index-to-resource-id-for-service-istances
branch
from
August 25, 2022 14:21
5f38188
to
23cd15c
Compare
* Add unique index on column service_instance_id to prevent double entries for the same service_instance * Remove duplicate service_instance_id entries based on max(updated_at) (=keep the newest entry) to prepare for adding a uniqueness constraint * Drop foreign_key constraint which references service_instance_id (needed for mysql) and old index before creating the unique index Compared to service bindings, service keys and route bindings there is a UNIQUE index defined for the "resource_id" field; for service instances the UNIQUE keyword is missing.
kathap
force-pushed
the
add-unique-index-to-resource-id-for-service-istances
branch
from
August 29, 2022 14:49
deffcef
to
be9fb5e
Compare
5 tasks
philippthun
reviewed
Sep 28, 2022
...ations/20220818142407_add_unique_index_to_service_instance_operations_service_instance_id.rb
Outdated
Show resolved
Hide resolved
...ations/20220818142407_add_unique_index_to_service_instance_operations_service_instance_id.rb
Outdated
Show resolved
Hide resolved
philippthun
force-pushed
the
add-unique-index-to-resource-id-for-service-istances
branch
from
September 28, 2022 08:51
a331ee7
to
3dc2ad0
Compare
kathap
force-pushed
the
add-unique-index-to-resource-id-for-service-istances
branch
from
October 5, 2022 14:04
b8bc55b
to
2229658
Compare
philippthun
reviewed
Oct 5, 2022
...ations/20220818142407_add_unique_index_to_service_instance_operations_service_instance_id.rb
Outdated
Show resolved
Hide resolved
...ations/20220818142407_add_unique_index_to_service_instance_operations_service_instance_id.rb
Outdated
Show resolved
Hide resolved
- return all the operations for a given service instance which has duplicate entries - ordering by updated_at and id, so that the operation we want to keep is at the top of the list - skipping this first operation, delete the rest
kathap
commented
Oct 6, 2022
...s/20220818142407_add_unique_index_to_service_instance_operations_service_instance_id_spec.rb
Show resolved
Hide resolved
...ations/20220818142407_add_unique_index_to_service_instance_operations_service_instance_id.rb
Outdated
Show resolved
Hide resolved
philippthun
reviewed
Oct 7, 2022
...ations/20220818142407_add_unique_index_to_service_instance_operations_service_instance_id.rb
Outdated
Show resolved
Hide resolved
...ations/20220818142407_add_unique_index_to_service_instance_operations_service_instance_id.rb
Outdated
Show resolved
Hide resolved
Take over Philipp's suggestions and remove unnecessary stuff
philippthun
approved these changes
Oct 10, 2022
will-gant
pushed a commit
to sap-contributions/cloud_controller_ng
that referenced
this pull request
Oct 20, 2022
* Add unique index on column service_instance_id to prevent double entries for the same service_instance * Remove duplicate service_instance_id entries based on max(updated_at) (=keep the newest entry) to prepare for adding a uniqueness constraint * Drop foreign_key constraint which references service_instance_id (needed for mysql) and old index before creating the unique index
will-gant
pushed a commit
to sap-contributions/cloud_controller_ng
that referenced
this pull request
Dec 16, 2022
* Add unique index on column service_instance_id to prevent double entries for the same service_instance * Remove duplicate service_instance_id entries based on max(updated_at) (=keep the newest entry) to prepare for adding a uniqueness constraint * Drop foreign_key constraint which references service_instance_id (needed for mysql) and old index before creating the unique index
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We can see double entries for the same service_instance_id
in the service_instance_operations table. This leads to:
PG::ForeignKeyViolation: ERROR: update or delete on table
"service_instances" violates foreign key constraint
"fk_svc_inst_op_svc_instance_id" on table "service_instance_operations".
Compared to service bindings, service keys and route bindings there is a UNIQUE index
defined for the "resource_id" field; for service instances the UNIQUE keyword is missing. An unique index would prevent to get duplicates, therefore:
Add unique index on column service_instance_id to prevent double entries for the same
service_instance
Remove duplicate entries for one service_instance_id to prepare for adding a uniqueness constraint
Drop old index before creating the unique one
Links to any other associated PRs
Fix service instance operations duplicates root cause #2916
Add delete on cascade to fk_svc_inst_op_svc_instance_id #2905
I have reviewed the contributing guide
I have viewed, signed, and submitted the Contributor License Agreement
I have made this pull request to the
main
branchI have run all the unit tests using
bundle exec rake
I have run CF Acceptance Tests