-- Remove leftovers of vm_interface_statistics orphan childs.
DELETE FROM vm_interface_statistics
WHERE id NOT IN (SELECT id from vm_interface);

SELECT fn_db_create_constraint('vm_interface_statistics', 'fk_vm_interface_statistics_vm_interface', 'FOREIGN KEY (id) REFERENCES vm_interface(id) ON DELETE CASCADE');

Add fk constraint on vm_interface_statistics
core: Add fk constraint on vm_interface_statistics

Once a network interface is being removed from the Data Base its
corresponding statistics data in _vm_interface_statistics should be
removed also.

Currently, when a Storge Domain is being detached from a Data Center, all the data related
to it is being removed from the Data Base.

Since there is no foreign key between vm_interface and
vm_interface_statistics which does cascade delete there are left overs
which are left in vm_interface_statistics although the vm_interface was
deleted.

Change-Id: I53cf2737ef91cf967c93990fcb237f6c4e12a8f8
Bug-Url: https://bugzilla.redhat.com/1196251
Signed-off-by: Maor Lipchuk <37a323a8cadba73c2b6c8d3f850c79092d0199e6@redhat.com>
