-
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 unique index to svc_inst_op on svc_inst_id
* Add unique index on column service_instance_id to prevent double entries for the same service_instance * Remove duplicate service_instance_id to prepare for adding a uniqueness constraint * Drop old index before creating the unique one 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.
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...ons/20220818142407_add_unique_index_to_service_instance_operations_service_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,24 @@ | ||
Sequel.migration do | ||
up do | ||
# Remove duplicate service_instance_operations.service_instance_id to prepare for adding a uniqueness constraint | ||
# assumption is that the max id = newest entry for the same svc_inst_id | ||
max_of_dup_groups = self[:service_instance_operations]. | ||
select(Sequel.function(:max, :id)). | ||
group_by(:service_instance_id). | ||
having { count.function.* >= 1 } | ||
|
||
self[:service_instance_operations].exclude(id: max_of_dup_groups).each do |row| | ||
self[:service_instance_operations].where(id: row[:id]).delete | ||
end | ||
alter_table :service_instance_operations do | ||
drop_index :service_instance_id, name: :svc_instance_id_index, if_exists: true | ||
add_index :service_instance_id, name: :svc_inst_op_svc_instance_id_unique_index, unique: true | ||
end | ||
end | ||
down do | ||
alter_table :service_instance_operations do | ||
drop_index :service_instance_id | ||
add_index :service_instance_id, name: :svc_instance_id_index | ||
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