cubicweb/misc/migration/3.10.0_Any.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Tue, 04 Apr 2017 16:28:50 +0200
branch3.25
changeset 12142 db2fc87348ab
parent 11279 e4f11ef1face
child 12567 26744ad37953
permissions -rw-r--r--
[server] Make "sources_by_uri" and "sources_by_eid" properties of repository I.e. do not populate these dict as repo initialization (bootstrap step) but always use information from database. This is needed because when multiple instances of the same application run, if one instance adds a CWSource the other ones will not see it. In particular, when using a scheduler instance, new CWSource will be added by the web instance and not seen by the scheduler which is supposed to update them. We thus define properties for sources_by_eid and sources_by_uri instead attributes on repository instance. CWSource entities are thus retrieved from database every time these properties are accessed. We factor out initialization of the "source" instance (subclass of cubicweb.server.source.AbstractSource) in a _sources() method. Note that this method takes care of calling "init" method on the source as well as "set_schema" (previously done in repo.set_schema(), which now only touches system_source). Accordingly the "init_sources_from_database" method is dropped along with "add_source"/"remove_source" methods. In syncsources hook, we thus drop: * SourceAddedOp operation which called repo.add_source() so that the SourceAddedHook only cares about checking source configuration now; * SourceRemovedOp and SourceRenamedOp operations for the same reason; * SourceConfigUpdatedOp as updating the live config of source is meaningless once we rely on them being retrieved from the database; * SourceHostConfigUpdatedHook hook which is now useless without call to SourceConfigUpdatedOp; In 3.10 migration script, remove usage of sources_by_uri repo attribute which, unless I'm missing something, appears useless (at least now). In tests: * unittest_datafeed: remove test_update_url method since we dropped respective hook; * unittest_ldapsource: LDAPFeedUserDeletionTC.test_a_filter_inactivate() currently fails because it still relies on live config being updated, this will be fixed in the next changeset once all "live source" logic will be removed.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10684
7e9c9a32f24f [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9460
diff changeset
     1
from six import text_type
7e9c9a32f24f [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9460
diff changeset
     2
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
     3
add_entity_type('CWSource')
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
     4
add_relation_definition('CWSource', 'cw_source', 'CWSource')
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
     5
add_entity_type('CWSourceHostConfig')
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
     6
11178
b3d3e23be27b [migration/3.10] fix AttributeError
Julien Cristau <julien.cristau@logilab.fr>
parents: 9460
diff changeset
     7
with session.allow_all_hooks_but('cw.sources'):
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
     8
    create_entity('CWSource', type=u'native', name=u'system')
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
     9
commit()
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    10
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    11
sql('INSERT INTO cw_source_relation(eid_from,eid_to) '
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    12
    'SELECT e.eid,s.cw_eid FROM entities as e, cw_CWSource as s '
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    13
    'WHERE s.cw_name=e.type')
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    14
commit()
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    15
9460
a2a0bc984863 [config] cleanup/refactor server sources file values handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8694
diff changeset
    16
for uri, cfg in config.read_sources_file().items():
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    17
    if uri in ('system', 'admin'):
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    18
        continue
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    19
    config = u'\n'.join('%s=%s' % (key, value) for key, value in cfg.items()
6546
31586c7b63f6 [3.10 migration] must skip None values
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6488
diff changeset
    20
                        if key != 'adapter' and value is not None)
10684
7e9c9a32f24f [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9460
diff changeset
    21
    create_entity('CWSource', name=text_type(uri), type=text_type(cfg['adapter']),
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    22
                  config=config)
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    23
commit()
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    24
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    25
# rename cwprops for boxes/contentnavigation
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
for x in rql('Any X,XK WHERE X pkey XK, '
7508
48398bf8a33a fix 3.10 cwproperties migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6945
diff changeset
    27
             'X pkey ~= "boxes.%" OR '
48398bf8a33a fix 3.10 cwproperties migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6945
diff changeset
    28
             'X pkey ~= "contentnavigation.%"').entities():
8483
4ba11607d84a [entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7508
diff changeset
    29
    x.cw_set(pkey=u'ctxcomponents.' + x.pkey.split('.', 1)[1])