GRAPH.CONSTRAIN DROP UNIQUE/MANDATORY [NODE label / RELATIONSHIP type] PROPERTIES prop_count prop0, prop1...
| 136 | |
| 137 | // GRAPH.CONSTRAIN <key> DROP UNIQUE/MANDATORY [NODE label / RELATIONSHIP type] PROPERTIES prop_count prop0, prop1... |
| 138 | static bool _Constraint_Drop |
| 139 | ( |
| 140 | RedisModuleCtx *ctx, // redis module context |
| 141 | RedisModuleString *key, // graph key to operate on |
| 142 | ConstraintType ct, // constraint type |
| 143 | GraphEntityType et, // entity type |
| 144 | const char *lbl, // label / rel-type |
| 145 | uint8_t n, // properties count |
| 146 | const char **props // properties |
| 147 | ) { |
| 148 | bool res = true; // optimistic |
| 149 | Attribute_ID attrs[n]; |
| 150 | |
| 151 | //-------------------------------------------------------------------------- |
| 152 | // try to get graph |
| 153 | //-------------------------------------------------------------------------- |
| 154 | |
| 155 | GraphContext *gc = GraphContext_Retrieve(ctx, key, false, false); |
| 156 | if(!gc) { |
| 157 | // graph doesn't exists |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | //-------------------------------------------------------------------------- |
| 162 | // try to get schema |
| 163 | //-------------------------------------------------------------------------- |
| 164 | |
| 165 | // determine schema type |
| 166 | SchemaType st = (et == GETYPE_NODE) ? SCHEMA_NODE : SCHEMA_EDGE; |
| 167 | |
| 168 | Schema *s = GraphContext_GetSchema(gc, lbl, st); |
| 169 | if(s == NULL) { |
| 170 | res = false; |
| 171 | goto cleanup; |
| 172 | } |
| 173 | |
| 174 | //-------------------------------------------------------------------------- |
| 175 | // try to get attribute IDs |
| 176 | //-------------------------------------------------------------------------- |
| 177 | |
| 178 | for(uint8_t i = 0; i < n; i++) { |
| 179 | const char *prop = props[i]; |
| 180 | |
| 181 | // try to get property ID |
| 182 | Attribute_ID id = GraphContext_GetAttributeID(gc, prop); |
| 183 | |
| 184 | if(id == ATTRIBUTE_ID_NONE) { |
| 185 | // attribute missing |
| 186 | res = false; |
| 187 | goto cleanup; |
| 188 | } |
| 189 | |
| 190 | attrs[i] = id; |
| 191 | } |
| 192 | |
| 193 | //-------------------------------------------------------------------------- |
| 194 | // try to get constraint |
| 195 | //-------------------------------------------------------------------------- |
no test coverage detected