-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add delete on cascade to fk_svc_inst_op_svc_instance_id (#2905)
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" For service bindings, service keys and route bindings the foreign key constraint from operation to resource contains ON DELETE CASCADE; for service instances this is missing. Adding ON DELETE CASCADE to FK fk_svc_inst_op_svc_instance_id in service_instance_operations Remove association dependency to be consistent with service binding operations, route binding operations and service key operations.
- Loading branch information
Showing
3 changed files
with
28 additions
and
1 deletion.
There are no files selected for viewing
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
18 changes: 18 additions & 0 deletions
18
db/migrations/20220805145100_add_delete_on_cascade_to_fk_svc_inst_op_svc_instance_id.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Sequel.migration do | ||
# Add DELETE CASCADE to foreign key fk_svc_inst_op_svc_instance_id to ensure that 'service instance operations' | ||
# are deleted together with the referenced 'service instance'. | ||
|
||
up do | ||
alter_table :service_instance_operations do | ||
drop_constraint :fk_svc_inst_op_svc_instance_id, type: :foreign_key | ||
add_foreign_key [:service_instance_id], :service_instances, key: :id, name: :fk_svc_inst_op_svc_instance_id, on_delete: :cascade | ||
end | ||
end | ||
|
||
down do | ||
alter_table :service_instance_operations do | ||
drop_constraint :fk_svc_inst_op_svc_instance_id, type: :foreign_key | ||
add_foreign_key [:service_instance_id], :service_instances, key: :id, name: :fk_svc_inst_op_svc_instance_id | ||
end | ||
end | ||
end |
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