I'm working on something of a wizard-type application to allow users to build simple "scripts" that basically perform actions based on certain conditions. Scripts that they build will be stored in a database, and modification will be common, so some sort of forward-only text generation is not an option. My program converts this internal database structure to the actual script output I need, so I will just be re-generating the output whenever they modify their script.
I'm looking for some advice about a good database structure to be able to store this information in. I have one working at the moment, but I'm just curious if I missed anything obvious that would make it a little cleaner. Any suggestions are appreciated.
To give some more detail, here's an genericized example of the type of "script" a user can create through picking conditions and actions in the GUI:
if ($variableA == 100 && $variableB > 25 && $variableC < 10)
{
performAction();
performAnotherAction();
if ($variableC == 0)
{
performYetAnotherAction();
}
else if ($variableC == 1 || $variableC == 2)
{
performEvenMoreActions();
}
}
else
{
performDefaultAction();
}
Some notes about what is and isn't possible, just so that it's clear:
- "if" conditionals can have any number of "else if" conditionals attached, as well as an optional "else".
- each conditional can have any number of "tests" (
$variableA == 100
, etc), however every test can be considered to be represented as(<variable>,<operator>,<test value>)
, there's no need to worry about more complex conditions. - even though each conditional can have any number of tests, they will always be joined by the same boolean operator. That is, if there are multiple tests in a conditional, they are either always joined by
&&
, or always joined by||
, there is no mixing. - Conditionals can be nested infinitely, so some sort of hierarchical structure is necessary.
- Inside conditionals there may be any number of actions, which must be performed in the same sequence they are defined in. Actions can simply be represented as a function name, there's no need to worry about any other "action types".