misc/scripts/repair_file_1-9_migration.py
changeset 10589 7c23b7de2b8d
parent 9460 a2a0bc984863
equal deleted inserted replaced
10588:fdaa0e4b7eaf 10589:7c23b7de2b8d
     2 
     2 
     3 FYI, this migration occurred :
     3 FYI, this migration occurred :
     4 * on our intranet on July 07 2010
     4 * on our intranet on July 07 2010
     5 * on our extranet on July 16 2010
     5 * on our extranet on July 16 2010
     6 """
     6 """
       
     7 from __future__ import print_function
     7 
     8 
     8 try:
     9 try:
     9     backupinstance, = __args__
    10     backupinstance, = __args__
    10 except ValueError:
    11 except ValueError:
    11     print 'USAGE: cubicweb-ctl shell <instance> repair_file_1-9_migration.py -- <backup instance id>'
    12     print('USAGE: cubicweb-ctl shell <instance> repair_file_1-9_migration.py -- <backup instance id>')
    12     print
    13     print()
    13     print 'you should restored the backup on a new instance, accessible through pyro'
    14     print('you should restored the backup on a new instance, accessible through pyro')
    14 
    15 
    15 from cubicweb import cwconfig, dbapi
    16 from cubicweb import cwconfig, dbapi
    16 from cubicweb.server.session import hooks_control
    17 from cubicweb.server.session import hooks_control
    17 
    18 
    18 defaultadmin = repo.config.default_admin_config
    19 defaultadmin = repo.config.default_admin_config
    30                                    'X from_entity Y, Y name "Image", X is CWRelation, '
    31                                    'X from_entity Y, Y name "Image", X is CWRelation, '
    31                                    'EXISTS(XX is CWRelation, XX relation_type RT, '
    32                                    'EXISTS(XX is CWRelation, XX relation_type RT, '
    32                                    'XX from_entity YY, YY name "File")'):
    33                                    'XX from_entity YY, YY name "File")'):
    33         if rtype in ('is', 'is_instance_of'):
    34         if rtype in ('is', 'is_instance_of'):
    34             continue
    35             continue
    35         print rtype
    36         print(rtype)
    36         for feid, xeid in backupcu.execute('Any F,X WHERE F %s X, F is IN (File,Image)' % rtype):
    37         for feid, xeid in backupcu.execute('Any F,X WHERE F %s X, F is IN (File,Image)' % rtype):
    37             print 'restoring relation %s between file %s and %s' % (rtype, feid, xeid),
    38             print('restoring relation %s between file %s and %s' % (rtype, feid, xeid), end=' ')
    38             print rql('SET F %s X WHERE F eid %%(f)s, X eid %%(x)s, NOT F %s X' % (rtype, rtype),
    39             print(rql('SET F %s X WHERE F eid %%(f)s, X eid %%(x)s, NOT F %s X' % (rtype, rtype),
    39                       {'f': feid, 'x': xeid})
    40                       {'f': feid, 'x': xeid}))
    40 
    41 
    41     for rtype, in backupcu.execute('DISTINCT Any RTN WHERE X relation_type RT, RT name RTN,'
    42     for rtype, in backupcu.execute('DISTINCT Any RTN WHERE X relation_type RT, RT name RTN,'
    42                                    'X to_entity Y, Y name "Image", X is CWRelation, '
    43                                    'X to_entity Y, Y name "Image", X is CWRelation, '
    43                                    'EXISTS(XX is CWRelation, XX relation_type RT, '
    44                                    'EXISTS(XX is CWRelation, XX relation_type RT, '
    44                                    'XX to_entity YY, YY name "File")'):
    45                                    'XX to_entity YY, YY name "File")'):
    45         print rtype
    46         print(rtype)
    46         for feid, xeid in backupcu.execute('Any F,X WHERE X %s F, F is IN (File,Image)' % rtype):
    47         for feid, xeid in backupcu.execute('Any F,X WHERE X %s F, F is IN (File,Image)' % rtype):
    47             print 'restoring relation %s between %s and file %s' % (rtype, xeid, feid),
    48             print('restoring relation %s between %s and file %s' % (rtype, xeid, feid), end=' ')
    48             print rql('SET X %s F WHERE F eid %%(f)s, X eid %%(x)s, NOT X %s F' % (rtype, rtype),
    49             print(rql('SET X %s F WHERE F eid %%(f)s, X eid %%(x)s, NOT X %s F' % (rtype, rtype),
    49                       {'f': feid, 'x': xeid})
    50                       {'f': feid, 'x': xeid}))
    50 
    51 
    51 commit()
    52 commit()