Creating Db2 site rules
Db2® site rules specify how developers should change object definitions in application instances that were provisioned from Db2 applications.
About this task
You can create simple and complex site rules. Simple rules are built using three segments: object, attribute, and verification type. For example, you can create a site rule that specifies that table (object) names (attribute) must start with (verification type) the string "TAB". When applied to an application or environment, developers creating or editing a table in a provisioned application instance are notified if they violate the rule.
Complex site rules are more flexible and powerful. You define them using a small domain-specific programming language that is composed of a subset of the Python syntax. Every valid complex site rule is a Python expression that is evaluated and resolved to either True or False according to normal Python rules. For example, an empty string is False, and the number 7 is True. Expressions can use the following features:
- Python ternary expressions (x if y else z)
- Boolean and/or/not
- Parentheses
- <
- >
- <=
- >=
- ==
- !=
- +
- -
- String subscription (stride not supported)
- The functions:
len,startswith, andendswith
Supported data types are integers, strings (delimited by double or single quotation marks), and Boolean operators.
name.startswith(“T”)
The predefined string variable name holds the value of the table name. The rest is standard Python syntax. Here is another valid way to write that rule:
name[:1] == “T”
For a list of objects and their attribute variables, see Complex Db2 site rule variables.
Rules can be combined to make standard Python expressions. For example, here is one way to create the rule “if a table space name is between 4 and 6 characters, tables in that table space must end their names with the last four characters of their table space”:
name.endswith(TSNAME[-4:]) if 4 <= len(TSNAME) <= 6 else True
log=="LOGGED" works; the rule log=="logged" does not work. The objects and attributes supported by complex site rules are the same as those supported by simple site rules.
To create and apply a site rule, complete the following steps: