Eli Mesika has uploaded a new change for review.

Change subject: core: DB - check if contraint exists before...
......................................................................

core: DB - check if contraint exists before...

DB - check if constraint exists before attempting to drop it.

Check in the upgrade script that constraint exists before attempting to
drop it.
Since this fix must run also for Postgres 8.4.x we can not simply use
the 'IF EXISTS' clause for that constraint since that is supported only
from Postgres 9.x

Change-Id: I8356df36a53f06751779f7e221bdcf4b1dfa9de7
Signed-off-by: Eli Mesika <[email protected]>
---
M 
backend/manager/dbscripts/upgrade/03_01_0100_migrate_templates_to_vm_static.sql
1 file changed, 6 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/00/10700/1

diff --git 
a/backend/manager/dbscripts/upgrade/03_01_0100_migrate_templates_to_vm_static.sql
 
b/backend/manager/dbscripts/upgrade/03_01_0100_migrate_templates_to_vm_static.sql
index f043b7f..c954d81 100644
--- 
a/backend/manager/dbscripts/upgrade/03_01_0100_migrate_templates_to_vm_static.sql
+++ 
b/backend/manager/dbscripts/upgrade/03_01_0100_migrate_templates_to_vm_static.sql
@@ -14,7 +14,9 @@
 WHERE  vm_guid IN (SELECT vm_guid FROM vm_dynamic);
 
 ALTER TABLE vm_static ALTER COLUMN entity_type SET NOT NULL;
-ALTER TABLE vm_static DROP CONSTRAINT vm_templates_vm_static;
+IF  EXISTS (SELECT 1 from pg_constraint where conname = 
'vm_templates_vm_static') THEN
+    ALTER TABLE vm_static DROP CONSTRAINT vm_templates_vm_static;
+END IF;
 
 INSERT INTO vm_static (
     vm_guid,
@@ -91,7 +93,9 @@
     FROM   vm_static
     WHERE  entity_type = 'TEMPLATE');
 
-ALTER TABLE vm_static ADD CONSTRAINT vm_templates_vm_static FOREIGN KEY 
(vmt_guid) REFERENCES vm_static (vm_guid);
+IF  NOT EXISTS (SELECT 1 from pg_constraint where conname = 
'vm_templates_vm_static') THEN
+    ALTER TABLE vm_static ADD CONSTRAINT vm_templates_vm_static FOREIGN KEY 
(vmt_guid) REFERENCES vm_static (vm_guid);
+END IF;
 
 INSERT
 INTO   image_vm_map(


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8356df36a53f06751779f7e221bdcf4b1dfa9de7
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Eli Mesika <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to