Files
ubicloud/migrate/20250610_ipv4_address.rb
Jeremy Evans 087ec3d5bf Add migration for ipv4_address table
This table will contain all ipv4 addresses that can be assigned in
a specific range.  It will eventually allow for public IPv4 address
selection for a VM in a single query.

This takes the unusual approach of having the foreign key to the
address table reference address.cidr instead of address.id. The
reason for doing that is to allow for a constraint ensuring the
ip address is inside the cidr. That's significantly more challenging
to implement correctly if the foreign key constraint references
address.id.
2025-06-21 03:11:54 +09:00

15 lines
403 B
Ruby

# frozen_string_literal: true
Sequel.migration do
change do
create_table(:ipv4_address) do
column :ip, :inet, primary_key: true
foreign_key :cidr, :address, key: :cidr, type: :cidr, null: false
index [:cidr, :ip], name: :ipv4_address_cidr_ip_idx
constraint(:ip_is_ipv4) { {family(:ip) => 4} }
constraint(:ip_is_in_cidr, Sequel.lit("ip <<= cidr"))
end
end
end