Files
ubicloud/migrate/20240516_boot_image_size_gib.rb
Hadi Moshayedi 4b9500e982 Migrations to add size_gib to the boot_image table
We need this when removing a boot image, when we want to update
available storage on the storage device.

Alternatively, we could get the size using an ssh command when removing
the boot image. But since this is also useful as a way of
double-checking approximate total used size on a storage device, where
we can just sum vm_storage_volume and boot_image sizes on it.
2024-05-16 09:32:05 -07:00

30 lines
826 B
Ruby

# frozen_string_literal: true
Sequel.migration do
change do
alter_table(:boot_image) do
add_column :size_gib, Integer, null: true
end
# Update existing boot images
run <<-SQL
UPDATE boot_image
SET size_gib = CASE
WHEN boot_image.name = 'ubuntu-jammy' THEN 3
WHEN boot_image.name = 'almalinux-9.1' THEN 10
WHEN vm_host.arch = 'x64' AND boot_image.name LIKE 'github-ubuntu-%' THEN 75
WHEN vm_host.arch = 'arm64' AND boot_image.name LIKE 'github-ubuntu-%' THEN 50
WHEN boot_image.name = 'github-gpu-ubuntu-2204' THEN 31
WHEN boot_image.name LIKE 'postgres-%' THEN 8
ELSE 0
END
FROM vm_host
WHERE boot_image.vm_host_id = vm_host.id;
SQL
alter_table(:boot_image) do
set_column_not_null :size_gib
end
end
end