misc/scripts/repair_file_1-9_migration.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 09 Feb 2011 18:06:17 +0100 (2011-02-09)
changeset 6957 ffda12be2e9f
parent 6109 47d9c0e0f7b7
child 7056 51f88f13d6f3
permissions -rw-r--r--
[repository] #1460066: backport datafeed cube as cubicweb source * add some attributes to CWSource to handle this kind of source (not natural to put everything in 'config' string). Adding a CWSource subclass has been attempted then rollbacked because it adds pain to handle multi-sources planning and it introduce an ambiguity on a generic relation (cw_source), which may be a penalty in multiple case * data feed sources are a new kind of source, namely 'copy based', which have no effect on the query planner * a data feed source is associated to a list of url and a parser (appobjects in the 'parsers' registry * entities imported by a data feed have cwuri set to their url on the distant site, their cw_source relation point to the data feed source, though their source stored in the entities table (returned by cw_metainformation) is their physical source, hence 'system'
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6001
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     1
"""execute this script if you've migration to file >= 1.9.0 with cubicweb <= 3.9.2
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
6109
47d9c0e0f7b7 integrate Celso's work on translation file: proper/complete spanish translation, fixed some typos in french translation, occured -> occurred fix in various places
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6001
diff changeset
     3
FYI, this migration occurred :
6001
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     4
* on our intranet on July 07 2010
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     5
* on our extranet on July 16 2010
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     6
"""
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     7
from __future__ import with_statement
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     8
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     9
try:
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    10
    backupinstance, = __args__
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    11
except ValueError:
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    12
    print 'USAGE: cubicweb-ctl shell <instance> repair_file_1-9_migration.py -- <backup instance id>'
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    13
    print
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    14
    print 'you should restored the backup on a new instance, accessible through pyro'
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    15
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    16
from cubicweb import cwconfig, dbapi
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    17
from cubicweb.server.session import hooks_control
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    18
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    19
sourcescfg = repo.config.sources()
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    20
backupcfg = cwconfig.instance_configuration(backupinstance)
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
backupcfg.repairing = True
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
backuprepo, backupcnx = dbapi.in_memory_cnx(backupcfg, sourcescfg['admin']['login'],
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    23
                                            password=sourcescfg['admin']['password'],
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
                                            host='localhost')
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    25
backupcu = backupcnx.cursor()
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
with hooks_control(session, session.HOOKS_DENY_ALL):
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    28
    rql('SET X is Y WHERE X is File, Y name "File", NOT X is Y')
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    29
    rql('SET X is_instance_of Y WHERE X is File, Y name "File", NOT X is_instance_of Y')
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    30
    for rtype, in backupcu.execute('DISTINCT Any RTN WHERE X relation_type RT, RT name RTN,'
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    31
                                   'X from_entity Y, Y name "Image", X is CWRelation, '
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    32
                                   'EXISTS(XX is CWRelation, XX relation_type RT, '
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    33
                                   'XX from_entity YY, YY name "File")'):
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    34
        if rtype in ('is', 'is_instance_of'):
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    35
            continue
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    36
        print rtype
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    37
        for feid, xeid in backupcu.execute('Any F,X WHERE F %s X, F is IN (File,Image)' % rtype):
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    38
            print 'restoring relation %s between file %s and %s' % (rtype, feid, xeid),
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    39
            print rql('SET F %s X WHERE F eid %%(f)s, X eid %%(x)s, NOT F %s X' % (rtype, rtype),
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    40
                      {'f': feid, 'x': xeid})
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    41
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    42
    for rtype, in backupcu.execute('DISTINCT Any RTN WHERE X relation_type RT, RT name RTN,'
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    43
                                   'X to_entity Y, Y name "Image", X is CWRelation, '
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    44
                                   'EXISTS(XX is CWRelation, XX relation_type RT, '
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    45
                                   'XX to_entity YY, YY name "File")'):
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    46
        print rtype
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    47
        for feid, xeid in backupcu.execute('Any F,X WHERE X %s F, F is IN (File,Image)' % rtype):
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    48
            print 'restoring relation %s between %s and file %s' % (rtype, xeid, feid),
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    49
            print rql('SET X %s F WHERE F eid %%(f)s, X eid %%(x)s, NOT X %s F' % (rtype, rtype),
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    50
                      {'f': feid, 'x': xeid})
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    51
1a21d7d2c959 [migration] add script to repair instances which have lost some relation due to 3.9 + file 1.9 migration (bad Image -> File entity type renaming)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    52
commit()