Files
ubicloud/migrate/20240419_add_constratins_for_volume_device.rb
Furkan Sahin c07c0cfb98 StorageDevice and VmStorageVolume schema updates
We have 2 schema updates here;
1. Make VmStorageVolume.storage_device_id column not nullable;
We occasionally see a drift of StorageDevice.available_storage_gib vs
vm.vm_storage_volume used sizes. This is happening because of bugs and
not maintaining the relationship in between volume and the device
properly. In result, they cause negative available_storage_gib. This
commit introduces new constraints to block these cases so that we can be
aware of the situation.

2. Introduce non zero and smaller than total_storage_gib constraints to
the StorageDevice.available_storage_gib column. Because it makes sense,
just an extra precaution at the DB level.
2024-04-22 13:29:34 +02:00

15 lines
419 B
Ruby

# frozen_string_literal: true
Sequel.migration do
change do
alter_table(:vm_storage_volume) do
set_column_not_null :storage_device_id
end
alter_table(:storage_device) do
add_constraint(:available_storage_gib_non_negative) { available_storage_gib >= 0 }
add_constraint(:available_storage_gib_less_than_or_equal_to_total) { available_storage_gib <= total_storage_gib }
end
end
end