            WHEN d.disk_interface = 'SCSI' THEN cast(1 as smallint)
            WHEN d.disk_interface = 'VirtIO' THEN cast(2 as smallint)
        END AS vm_disk_interface,
+       d.shareable as is_shared,
        i._create_date AS create_date,
        i._update_date AS update_date
 FROM   images as i
            INNER JOIN
                base_disks as d ON i.image_group_id = d.disk_id
            INNER JOIN
-               vm_device as vd ON d.disk_id = vd.device_id
-		              INNER JOIN
-		                  vm_static ON vm_static.vm_guid = vd.vm_id
-           INNER JOIN
                image_storage_domain_map ON image_storage_domain_map.image_id = i.image_guid
+           LEFT OUTER JOIN vm_device ON vm_device.device_id = i.image_group_id
+                               LEFT OUTER JOIN vm_static ON vm_static.vm_guid = vm_device.vm_id
 WHERE     i.active = true AND
-                 vm_static.entity_type = 'VM' AND
+          (vm_static.entity_type = 'VM' OR vm_static.entity_type IS NULL) AND
           (i._create_date >
                           (SELECT     var_datetime
                            FROM         dwh_history_timekeeping


CREATE OR REPLACE VIEW dwh_vm_disks_history_view
AS
SELECT
	images.image_guid as vm_disk_id,
	cast(images.imageStatus as smallint) as vm_disk_status,
	cast(disk_image_dynamic.actual_size / 1048576 as int) as vm_disk_actual_size_mb,
	disk_image_dynamic.read_rate as read_rate_bytes_per_second,

	disk_image_dynamic.write_latency_seconds as write_latency_seconds,
	disk_image_dynamic.flush_latency_seconds as flush_latency_seconds
FROM    images
            INNER JOIN
                 disk_image_dynamic ON images.image_guid = disk_image_dynamic.image_id
            INNER JOIN
                 base_disks as d ON images.image_group_id = d.disk_id
            LEFT OUTER JOIN vm_device ON vm_device.device_id = images.image_group_id
                                LEFT OUTER JOIN vm_static ON vm_static.vm_guid = vm_device.vm_id
WHERE images.active = true AND
      (vm_static.entity_type = 'VM' OR vm_static.entity_type IS NULL);

CREATE OR REPLACE VIEW dwh_remove_tags_relations_history_view AS
SELECT    tag_id as entity_id,
