Actions
Feature #21429
openForeman's testsuite should contain a test that checks presence of foreign key constraints
Status:
New
Priority:
Normal
Assignee:
-
Category:
Tests
Target version:
-
Description
Foreman should check if potential changes in db migrations in pull requests correctly set foreign keys.
The test should:- check all descendants of AppliactionRecord
- test whether foreign keys exist for all relevant associations in the record (polymorphic associations will obviously need to be skipped)
- provide a way of defining what associations on which classes should be excluded from this test
- enable excluding associations also from plugins
So far it seems that the best way of getting information about what foreign keys exist is via SchemaDumper:
stream = StringIO.new ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream) lines = stream.string.split("\n").select{|l| l.match?(/[ ]*add_foreign/)} puts lines add_foreign_key "architectures_operatingsystems", "architectures", name: "architectures_operatingsystems_architecture_id_fk" add_foreign_key "architectures_operatingsystems", "operatingsystems", name: "architectures_operatingsystems_operatingsystem_id_fk" add_foreign_key "compute_attributes", "compute_profiles", name: "compute_attributes_compute_profile_id_fk" add_foreign_key "compute_attributes", "compute_resources", name: "compute_attributes_compute_resource_id_fk" add_foreign_key "containers", "smart_proxies", column: "capsule_id" add_foreign_key "domains", "smart_proxies", column: "dns_id", name: "domains_dns_id_fk" add_foreign_key "environment_classes", "environments", name: "environment_classes_environment_id_fk" add_foreign_key "environment_classes", "lookup_keys", column: "puppetclass_lookup_key_id", name: "environment_classes_lookup_key_id_fk" add_foreign_key "environment_classes", "puppetclasses", name: "environment_classes_puppetclass_id_fk" add_foreign_key "external_usergroups", "auth_sources", name: "external_usergroups_auth_source_id_fk" add_foreign_key "external_usergroups", "usergroups", name: "external_usergroups_usergroup_id_fk" add_foreign_key "fact_values", "fact_names", name: "fact_values_fact_name_id_fk" add_foreign_key "fact_values", "hosts", name: "fact_values_host_id_fk" add_foreign_key "features_smart_proxies", "features", name: "features_smart_proxies_feature_id_fk" add_foreign_key "features_smart_proxies", "smart_proxies", name: "features_smart_proxies_smart_proxy_id_fk" add_foreign_key "filterings", "filters", name: "filterings_filters_id_fk" add_foreign_key "filterings", "permissions", name: "filterings_permissions_id_fk" ...
No data to display
Actions