开发者

AlertRules/AlertAction database design

I have a program that can iterate through a group of messages, compare each message against a collection of rules, and if it passes, perform a action such as send an email, send a text message, or write the message to a directory

This question is about designing a database that will house all the rules and the action that will be take for each rule.

This is how I think I want to design my database:

    ========Rules========
UniqueID        int 
DateStamp       dateTime
RuleStartDate   dateTime
RuleEndDate     dateTime
[condition 1]   varchar
[condition 2]   varchar
...
ActionMethod    int <--Related to the ID of the ActionMethod table
ActionMethodID  int <--what table it relates to depends on the value of ActionMethod

=====ActionMethod=======    
ID              int
ActionMethod    开发者_Go百科varchar

{this table will have entries like:
10  E-Mail
20  WriteToDir
30  Text}

=======E-mail===========    
ActionMethodID  int
MailTo          varchar
MailFrom        varchar
MailSubject     varchar
MailBody        varchar
IsUrgent        bool

======WriteToDir======= 
ActionMethodID  int
DirToWriteTo    varchar

=======Text============ 
ActionMethodID  int
phoneNumber     varchar

By doing this way, I should be able to add more actions later on down the line without having to restructure my Rules table. It avoids a design that looks like this:

    ========Rules========
UniqueID        int 
DateStamp       dateTime
RuleStartDate   dateTime
RuleEndDate     dateTime
[condition 1]   varchar
[condition 2]   varchar
...
ActionMethod    varchar
MailTo          varchar
MailFrom        varchar
MailSubject     varchar
MailBody        varchar
IsUrgent        bool
DirToWriteTo    varchar
phoneNumber     varchar

With the assumption that if a person wants an email than “ActionMethod” would equal “email” and all the email fields are filled in or if a person wants an text message then “ActionMethod” would equal “text” and phone field would be filled in.

Is there a better design for what I am trying to accomplish?


Storing rules in a database is not a good practice. I think you are reinventing the wheel for no real reason. Just use one of free business rules engines.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜