From: Leo Nunner <l.nunner@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH WIP api 05/11] match groups: update database schema
Date: Thu, 14 Sep 2023 11:52:26 +0200 [thread overview]
Message-ID: <20230914095234.115469-6-l.nunner@proxmox.com> (raw)
In-Reply-To: <20230914095234.115469-1-l.nunner@proxmox.com>
Adds a 'MatchGroup' table which contains all the data relevant for a
match group:
- ID: numerical ID of the group
- Rule ID: of the rule it belongs to
- Class: which object type it belongs to
The 'RuleGroup' table - which maps objects to a specific rule - now also
has a 'MatchGroup' field to store the ID of the corresponding match
group, should it be part of one.
Signed-off-by: Leo Nunner <l.nunner@proxmox.com>
---
src/PMG/DBTools.pm | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/src/PMG/DBTools.pm b/src/PMG/DBTools.pm
index 81d7fb3..1461dae 100644
--- a/src/PMG/DBTools.pm
+++ b/src/PMG/DBTools.pm
@@ -295,6 +295,15 @@ my $userprefs_ctablecmd = <<__EOD;
__EOD
+my $matchgroup_ctablecmd = <<__EOD;
+ CREATE TABLE MatchGroup
+ (ID SERIAL UNIQUE,
+ RID INTEGER NOT NULL,
+ Name VARCHAR(255),
+ Class VARCHAR(10) NOT NULL,
+ PRIMARY KEY (ID));
+__EOD
+
sub cond_create_dbtable {
my ($dbh, $name, $ctablecmd) = @_;
@@ -418,6 +427,7 @@ sub create_ruledb {
Rule_ID INTEGER NOT NULL,
Grouptype INTEGER NOT NULL,
Negate INTEGER NOT NULL DEFAULT 0,
+ MatchGroup INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY (Objectgroup_ID, Rule_ID, Grouptype)
);
@@ -440,6 +450,8 @@ sub create_ruledb {
$userprefs_ctablecmd;
$virusinfo_stat_ctablecmd;
+
+ $matchgroup_ctablecmd;
EOD
);
@@ -495,6 +507,7 @@ sub upgradedb {
'CStatistic', $cstatistic_ctablecmd,
'ClusterInfo', $clusterinfo_ctablecmd,
'VirusInfo', $virusinfo_stat_ctablecmd,
+ 'MatchGroup', $matchgroup_ctablecmd,
};
foreach my $table (keys %$tables) {
@@ -593,6 +606,19 @@ sub upgradedb {
}
}
+ # Allow logical AND for rule objects
+ if (!database_column_exists($dbh, 'RuleGroup', 'MatchGroup')) {
+ eval {
+ $dbh->begin_work;
+ $dbh->do("ALTER TABLE RuleGroup ADD COLUMN MatchGroup 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
next prev parent reply other threads:[~2023-09-14 9:52 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-14 9:52 [pmg-devel] [PATCH WIP api/gui] Extend rule system Leo Nunner
2023-09-14 9:52 ` [pmg-devel] [PATCH WIP api 01/11] negation: add field to database Leo Nunner
2023-09-14 9:52 ` [pmg-devel] [PATCH WIP api 02/11] negation: parse negation value into objects Leo Nunner
2023-09-14 9:52 ` [pmg-devel] [PATCH WIP api 03/11] negation: expand/implement API endpoints Leo Nunner
2023-09-14 9:52 ` [pmg-devel] [PATCH WIP api 04/11] negation: implement matching logic Leo Nunner
2023-09-14 9:52 ` Leo Nunner [this message]
2023-09-14 9:52 ` [pmg-devel] [PATCH WIP api 06/11] match groups: add functions for database access Leo Nunner
2023-09-14 9:52 ` [pmg-devel] [PATCH WIP api 07/11] match groups: parse field into objects Leo Nunner
2023-09-14 9:52 ` [pmg-devel] [PATCH WIP api 08/11] match groups: add API endpoints for create/delete Leo Nunner
2023-09-14 9:52 ` [pmg-devel] [PATCH WIP api 09/11] match groups: list match groups in rule API Leo Nunner
2023-09-14 9:52 ` [pmg-devel] [PATCH WIP api 10/11] match groups: update existing object API endpoints Leo Nunner
2023-09-14 9:52 ` [pmg-devel] [PATCH WIP api 11/11] match groups: implement matching logic Leo Nunner
2023-09-14 9:52 ` [pmg-devel] [PATCH WIP gui 1/2] negate objects inside rules Leo Nunner
2023-09-14 9:52 ` [pmg-devel] [PATCH WIP gui 2/2] introduce logical 'and' for rules Leo Nunner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230914095234.115469-6-l.nunner@proxmox.com \
--to=l.nunner@proxmox.com \
--cc=pmg-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox