[pmg-devel] [PATCH pmg-api 1/8] feature: negation: add field to database

Leo Nunner l.nunner at proxmox.com
Fri Apr 7 15:42:47 CEST 2023


Add a 'Negation field to the RuleGroup table.

Signed-off-by: Leo Nunner <l.nunner at proxmox.com>
---
 src/PMG/DBTools.pm | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/PMG/DBTools.pm b/src/PMG/DBTools.pm
index 0b37361..07d39b1 100644
--- a/src/PMG/DBTools.pm
+++ b/src/PMG/DBTools.pm
@@ -407,6 +407,7 @@ sub create_ruledb {
           Objectgroup_ID INTEGER NOT NULL,
           Rule_ID INTEGER NOT NULL,
           Grouptype INTEGER NOT NULL,
+          Negate INTEGER NOT NULL DEFAULT 0,
           PRIMARY KEY (Objectgroup_ID, Rule_ID, Grouptype)
         );
 
@@ -569,6 +570,19 @@ sub upgradedb {
 	}
     }
 
+    # Allow negating rule objects
+    if (!database_column_exists($dbh, 'RuleGroup', 'Negate')) {
+	eval {
+	    $dbh->begin_work;
+	    $dbh->do("ALTER TABLE RuleGroup ADD COLUMN Negate INTEGER NOT NULL DEFAULT 0");
+	    $dbh->commit;
+	};
+	if (my $err = $@) {
+	    $dbh->rollback;
+	    die $err;
+	}
+    }
+
     foreach my $table (keys %$tables) {
 	eval { $dbh->do("ANALYZE $table"); };
 	warn $@ if $@;
-- 
2.30.2





More information about the pmg-devel mailing list