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

Add an unique index to service_instance_operations #2929

Conversation

kathap
Copy link
Contributor

@kathap kathap commented Aug 18, 2022

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:

@kathap kathap marked this pull request as draft August 18, 2022 13:02
@kathap kathap force-pushed the add-unique-index-to-resource-id-for-service-istances branch from 5f38188 to 23cd15c Compare August 25, 2022 14:21
* 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 kathap force-pushed the add-unique-index-to-resource-id-for-service-istances branch from deffcef to be9fb5e Compare August 29, 2022 14:49
@kathap kathap marked this pull request as ready for review August 31, 2022 10:02
@philippthun philippthun self-assigned this Sep 28, 2022
@philippthun philippthun force-pushed the add-unique-index-to-resource-id-for-service-istances branch from a331ee7 to 3dc2ad0 Compare September 28, 2022 08:51
@kathap kathap force-pushed the add-unique-index-to-resource-id-for-service-istances branch from b8bc55b to 2229658 Compare October 5, 2022 14:04
kathap added 2 commits October 6, 2022 14:24
- 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 and others added 3 commits October 7, 2022 15:25
@philippthun philippthun merged commit cce461e into cloudfoundry:main 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants