Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- switches IpAddress model to store ip addresses as strings - renamed column to address_str to avoid confusion that address returns int string Signed-off-by: dmitriy kalinin <dkalinin@pivotal.io>
- Loading branch information
Showing
19 changed files
with
568 additions
and
49 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
...sh-director/db/migrations/director/20170825141953_change_address_to_be_string_for_ipv6.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
Sequel.migration do | |||
change do | |||
alter_table :ip_addresses do | |||
add_column(:address_temp, String, unique: true) | |||
end | |||
|
|||
self[:ip_addresses].each do |ip_address| | |||
self[:ip_addresses].filter(:id => ip_address[:id]).update(address_temp: ip_address[:address].to_s) | |||
end | |||
|
|||
alter_table :ip_addresses do | |||
drop_column :address | |||
rename_column :address_temp, :address_str | |||
add_index [:address_str], unique: true, address_str: 'unique_address_str' | |||
set_column_not_null :address_str | |||
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
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
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
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
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
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
27 changes: 27 additions & 0 deletions
27
...c/unit/db/migrations/director/20170825141953_change_address_to_be_string_for_ipv6_spec.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,27 @@ | |||
require_relative '../../../../db_spec_helper' | |||
require 'netaddr' | |||
|
|||
module Bosh::Director | |||
describe 'change address column in IP address to be a string to record IPv6 addresses' do | |||
let(:db) { DBSpecHelper.db } | |||
let(:migration_file) { '20170825141953_change_address_to_be_string_for_ipv6.rb' } | |||
|
|||
before { DBSpecHelper.migrate_all_before(migration_file) } | |||
|
|||
it 'allows instance_id to be null' do | |||
db[:ip_addresses] << {id: 1, instance_id: nil, address: NetAddr::CIDR.create("192.168.50.6").to_i} | |||
|
|||
DBSpecHelper.migrate(migration_file) | |||
|
|||
expect(db[:ip_addresses].first[:address_str]).to eq(NetAddr::CIDR.create("192.168.50.6").to_i.to_s) | |||
|
|||
expect { | |||
db[:ip_addresses] << {id: 2, instance_id: nil, address_str: NetAddr::CIDR.create("192.168.50.6").to_i.to_s} | |||
}.to raise_error(Sequel::UniqueConstraintViolation, /ip_addresses.address/) | |||
|
|||
expect { | |||
db[:ip_addresses] << {id: 3, instance_id: nil, address_str: nil} | |||
}.to raise_error(Sequel::NotNullConstraintViolation, /ip_addresses.address/) | |||
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
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
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
Oops, something went wrong.