-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test expecting *_id columns to be bigint type
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'set' | ||
describe "*_id columns" do | ||
EXCEPTIONS_LIST = Set.new( | ||
[ | ||
"authentications.ldap_id", | ||
"authentications.rhsm_pool_id", | ||
"cloud_networks.provider_segmentation_id", | ||
"container_volumes.common_volume_id", | ||
"miq_queue.task_id", | ||
"network_ports.binding_host_id", | ||
"scan_histories.task_id", | ||
"sessions.session_id" | ||
] | ||
).freeze | ||
|
||
it "should be type bigint" do | ||
ActiveRecord::Base.connection.tables.each do |table| | ||
next if ManageIQ::Schema::SYSTEM_TABLES.include?(table) | ||
DatabaseHelper.columns_for_table(table).each do |column| | ||
next unless column.name.end_with?("_id") | ||
if "#{table}.#{column.name}".in?(EXCEPTIONS_LIST) | ||
expect(column.sql_type).not_to eq("bigint"), "Thanks for fixing technical debt!!! Please remove '#{table}.#{column.name}' from EXCEPTIONS_LIST in #{__FILE__}" | ||
else | ||
expect(column.sql_type).to eq("bigint"), "Expected foreign key column #{table}.#{column.name} to be type 'bigint', got: '#{column.sql_type}'" | ||
end | ||
end | ||
end | ||
end | ||
end |