Files
ubicloud/migrate/20240409_move_firewall_to_subnet.rb
Furkan Sahin 1c2b15ea92 Move Firewalls from VM to Subnet model migration
We made the decision to make Firewalls to be added to the whole subnet
instead of individual VMs. This commit implements the migration file.
2024-05-02 20:04:04 +02:00

34 lines
620 B
Ruby

# frozen_string_literal: true
Sequel.migration do
up do
alter_table(:firewall) do
add_foreign_key :private_subnet_id, :private_subnet, type: :uuid
end
run <<~SQL
UPDATE firewall f
SET private_subnet_id = (
SELECT n.private_subnet_id
FROM nic n
WHERE n.vm_id = f.vm_id
);
SQL
end
down do
run <<~SQL
UPDATE firewall f
SET vm_id = (
SELECT n.vm_id
FROM nic n
WHERE n.private_subnet_id = f.private_subnet_id
);
SQL
alter_table(:firewall) do
drop_column :private_subnet_id
end
end
end