Commit 6958f7af authored by Julien Cristau's avatar Julien Cristau
Browse files

wip db-check rql constraints

parent 4befc2e7d531
Pipeline #78054 failed with stages
in 4 minutes and 37 seconds
......@@ -28,6 +28,7 @@ from logilab.common.shellutils import ProgressBar
from yams.constraints import UniqueConstraint
from cubicweb import ValidationError
from cubicweb.toolsutils import underline_title
from cubicweb.schema import PURE_VIRTUAL_RTYPES, VIRTUAL_RTYPES, UNIQUE_CONSTRAINTS
from cubicweb.server.sqlutils import SQL_PREFIX
......@@ -409,6 +410,26 @@ def check_metadata(schema, cnx, eids, fix=1):
notify_fixed(fix)
def check_rqlconstraints(schema, cnx, eids, fix=1):
print('Checking RQL constraints')
for rdefeid, cstreid in cnx.execute('Any RD, C WHERE RD constrained_by C, '
'C cstrtype CT, CT name IN ("RQLConstraint", "RQLUniqueConstraint")'):
rdef = schema.schema_by_eid(rdefeid)
constraint = rdef.constraint_by_eid(cstreid)
msg = '%s (autofix will remove the relation)\n'
for eidfrom, eidto in cnx.execute('Any S, O WHERE S is %(s)s, O is %(o)s, S %(r)s O' %
{'s': rdef.subject.type,
'o': rdef.object.type,
'r': rdef.rtype.type}):
try:
constraint.repo_check(cnx, eidfrom, rdef.rtype.type, eidto)
except ValidationError as exc:
sys.stderr.write(msg % exc)
if fix:
cnx.delete_relation(eidfrom, rdef.rtype.type, eidto)
notify_fixed(fix)
def check(repo, cnx, checks, reindex, fix, withpb=True):
"""check integrity of instance's repository,
using given user and password to locally connect to the repository
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment