[pmg-devel] [PATCH WIP api 01/11] negation: add field to database
Leo Nunner
l.nunner at proxmox.com
Thu Sep 14 11:52:22 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 9e133bc..81d7fb3 100644
--- a/src/PMG/DBTools.pm
+++ b/src/PMG/DBTools.pm
@@ -417,6 +417,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)
);
@@ -579,6 +580,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.39.2
More information about the pmg-devel
mailing list