Shahar Havivi has uploaded a new change for review.

Change subject: core: child count is not updated for template
......................................................................

core: child count is not updated for template

Change-Id: Ia6ddedc913bb0a383f560c03282b1ab5295bd4bb
Bug-Url: https://bugzilla.redhat.com/1006313
Signed-off-by: Shahar Havivi <shah...@redhat.com>
---
A packaging/dbscripts/upgrade/03_05_0470_update_vm_static_child_count.sql
M packaging/dbscripts/vms_sp.sql
2 files changed, 15 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/97/27797/1

diff --git 
a/packaging/dbscripts/upgrade/03_05_0470_update_vm_static_child_count.sql 
b/packaging/dbscripts/upgrade/03_05_0470_update_vm_static_child_count.sql
new file mode 100644
index 0000000..1191899
--- /dev/null
+++ b/packaging/dbscripts/upgrade/03_05_0470_update_vm_static_child_count.sql
@@ -0,0 +1,2 @@
+UPDATE vm_static as a
+SET child_count =(SELECT COUNT(*) FROM vm_static as b WHERE a.vm_guid = 
b.vmt_guid and entity_type = 'VM');
diff --git a/packaging/dbscripts/vms_sp.sql b/packaging/dbscripts/vms_sp.sql
index 00cd470..60d4292 100644
--- a/packaging/dbscripts/vms_sp.sql
+++ b/packaging/dbscripts/vms_sp.sql
@@ -512,6 +512,10 @@
 -- perform deletion from vm_ovf_generations to ensure that no record exists 
when performing insert to avoid PK violation.
 DELETE FROM vm_ovf_generations gen WHERE gen.vm_guid = v_vm_guid;
 INSERT INTO vm_ovf_generations(vm_guid, storage_pool_id) VALUES (v_vm_guid, 
(SELECT storage_pool_id FROM vds_groups vg WHERE vg.vds_group_id = 
v_vds_group_id));
+-- set child_count for the template
+UPDATE vm_static
+    SET child_count =(SELECT COUNT(*) FROM vm_static WHERE vmt_guid = 
v_vmt_guid and entity_type = 'VM')
+    WHERE vm_guid = v_vmt_guid;
 END; $procedure$
 LANGUAGE plpgsql;
 
@@ -680,7 +684,11 @@
    AS $procedure$
    DECLARE
    v_val  UUID;
+   v_vmt_guid  UUID;
 BEGIN
+      -- store vmt_guid for setting the child_count
+      SELECT   vm_static.vmt_guid INTO v_vmt_guid FROM vm_static WHERE vm_guid 
= v_vm_guid;
+
                        -- Get (and keep) a shared lock with "right to upgrade 
to exclusive"
             -- in order to force locking parent before children
       select   vm_guid INTO v_val FROM vm_static  WHERE vm_guid = v_vm_guid    
 FOR UPDATE;
@@ -692,6 +700,11 @@
       if v_remove_permissions then
         DELETE FROM permissions where object_id = v_vm_guid;
       end if;
+
+      -- set the child_count for the template
+      UPDATE vm_static
+          SET child_count =(SELECT COUNT(*) FROM vm_static WHERE vmt_guid = 
v_vmt_guid and entity_type = 'VM')
+          WHERE vm_guid = v_vmt_guid;
 END; $procedure$
 LANGUAGE plpgsql;
 


-- 
To view, visit http://gerrit.ovirt.org/27797
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia6ddedc913bb0a383f560c03282b1ab5295bd4bb
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Shahar Havivi <shav...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to