m4_define([CONSTRAINT_SCHEMA],
[[{"name": "constraints",
"tables": {
+ "a": {
+ "columns": {
+ "a": {"type": "integer"},
+ "a2a": {"type": {"key": {"type": "uuid", "refTable": "a"},
+ "min": 0, "max": "unlimited"}},
+ "a2b": {"type": {"key": {"type": "uuid", "refTable": "b"},
+ "min": 0, "max": "unlimited"}}}},
+ "b": {
+ "columns": {
+ "b": {"type": "integer"},
+ "b2a": {"type": {"key": {"type": "uuid", "refTable": "a"},
+ "min": 0, "max": "unlimited"}},
+ "b2b": {"type": {"key": {"type": "uuid", "refTable": "b"},
+ "min": 0, "max": "unlimited"}}}},
"constrained": {
"columns": {
"positive": {"type": {"key": {"type": "integer",
[[[{"details":"0 is less than minimum allowed value 1","error":"constraint violation"}]
[{"details":"-1 is less than minimum allowed value 1","error":"constraint violation"}]
[{"details":"-2 is less than minimum allowed value 1","error":"constraint violation"}]
+]])
+
+OVSDB_CHECK_EXECUTION([referential integrity -- simple],
+ [CONSTRAINT_SCHEMA],
+ [[[[{"op": "insert",
+ "table": "b",
+ "row": {"b": 1},
+ "uuid-name": "brow"},
+ {"op": "insert",
+ "table": "a",
+ "row": {"a": 0,
+ "a2b": ["set", [["named-uuid", "brow"]]]}},
+ {"op": "insert",
+ "table": "a",
+ "row": {"a": 1,
+ "a2b": ["set", [["named-uuid", "brow"]]]}},
+ {"op": "insert",
+ "table": "a",
+ "row": {"a": 2,
+ "a2b": ["set", [["named-uuid", "brow"]]]}}]]],
+ [[[{"op": "delete",
+ "table": "b",
+ "where": []}]]],
+ [[[{"op": "delete",
+ "table": "a",
+ "where": [["a", "==", 0]]}]]],
+ [[[{"op": "delete",
+ "table": "b",
+ "where": []}]]],
+ [[[{"op": "delete",
+ "table": "a",
+ "where": [["a", "==", 1]]}]]],
+ [[[{"op": "delete",
+ "table": "b",
+ "where": []}]]],
+ [[[{"op": "delete",
+ "table": "a",
+ "where": [["a", "==", 2]]}]]],
+ [[[{"op": "delete",
+ "table": "b",
+ "where": []}]]]],
+ [[[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]},{"uuid":["uuid","<3>"]}]
+[{"count":1},{"details":"cannot delete b row <0> because of 3 remaining reference(s)","error":"referential integrity violation"}]
+[{"count":1}]
+[{"count":1},{"details":"cannot delete b row <0> because of 2 remaining reference(s)","error":"referential integrity violation"}]
+[{"count":1}]
+[{"count":1},{"details":"cannot delete b row <0> because of 1 remaining reference(s)","error":"referential integrity violation"}]
+[{"count":1}]
+[{"count":1}]
+]])
+
+OVSDB_CHECK_EXECUTION([referential integrity -- mutual references],
+ [CONSTRAINT_SCHEMA],
+ [[[[{"op": "declare",
+ "uuid-name": "row1"},
+ {"op": "declare",
+ "uuid-name": "row2"},
+ {"op": "insert",
+ "table": "a",
+ "row": {"a": 0,
+ "a2b": ["set", [["named-uuid", "row2"]]],
+ "a2a": ["set", [["named-uuid", "row1"]]]},
+ "uuid-name": "row1"},
+ {"op": "insert",
+ "table": "b",
+ "row": {"b": 1,
+ "b2b": ["set", [["named-uuid", "row2"]]],
+ "b2a": ["set", [["named-uuid", "row1"]]]},
+ "uuid-name": "row2"}]]],
+ [[[{"op": "insert",
+ "table": "a",
+ "row": {"a2b": ["set", [["uuid", "b516b960-5b19-4fc2-bb82-fe1cbd6d0241"]]]}}]]],
+ [[[{"op": "delete",
+ "table": "a",
+ "where": [["a", "==", 0]]}]]],
+ [[[{"op": "delete",
+ "table": "b",
+ "where": [["b", "==", 1]]}]]],
+ dnl Try the deletions again to make sure that the refcounts got rolled back.
+ [[[{"op": "delete",
+ "table": "a",
+ "where": [["a", "==", 0]]}]]],
+ [[[{"op": "delete",
+ "table": "b",
+ "where": [["b", "==", 1]]}]]],
+ [[[{"op": "delete",
+ "table": "a",
+ "where": [["a", "==", 0]]},
+ {"op": "delete",
+ "table": "b",
+ "where": [["b", "==", 1]]}]]]],
+ [[[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]},{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]}]
+[{"uuid":["uuid","<2>"]},{"details":"reference to nonexistent row <3>","error":"referential integrity violation"}]
+[{"count":1},{"details":"cannot delete a row <0> because of 1 remaining reference(s)","error":"referential integrity violation"}]
+[{"count":1},{"details":"cannot delete b row <1> because of 1 remaining reference(s)","error":"referential integrity violation"}]
+[{"count":1},{"details":"cannot delete a row <0> because of 1 remaining reference(s)","error":"referential integrity violation"}]
+[{"count":1},{"details":"cannot delete b row <1> because of 1 remaining reference(s)","error":"referential integrity violation"}]
+[{"count":1},{"count":1}]
]])])
EXECUTION_EXAMPLES