author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 21 Aug 2009 16:26:20 +0200 | |
changeset 2968 | 0e3460341023 |
parent 2892 | 7ae3d62a8328 |
parent 2965 | 75ad5cb00b88 |
child 3230 | 1d25e928c299 |
permissions | -rw-r--r-- |
0 | 1 |
"""allways executed before all others in server migration |
2 |
||
3 |
it should only include low level schema changes |
|
4 |
||
5 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1954
diff
changeset
|
6 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 7 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1954
diff
changeset
|
8 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 9 |
""" |
10 |
||
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
11 |
applcubicwebversion, cubicwebversion = versions_map['cubicweb'] |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
12 |
|
2463
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
13 |
if applcubicwebversion < (3, 4, 0) and cubicwebversion >= (3, 4, 0): |
2892
7ae3d62a8328
hooks have been refactored, call [re|de]activate_verification_hooks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2696
diff
changeset
|
14 |
|
2463
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
15 |
session.set_shared_data('do-not-insert-cwuri', True) |
2892
7ae3d62a8328
hooks have been refactored, call [re|de]activate_verification_hooks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2696
diff
changeset
|
16 |
deactivate_verification_hooks() |
2463
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
17 |
add_relation_type('cwuri') |
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
18 |
base_url = session.base_url() |
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
19 |
# use an internal session since some entity might forbid modifications to admin |
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
20 |
isession = repo.internal_session() |
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
21 |
for eid, in rql('Any X', ask_confirm=False): |
2696
b45d852990d5
[3.4 migration] only set cwuri for entities from the system source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2578
diff
changeset
|
22 |
type, source, extid = session.describe(eid) |
b45d852990d5
[3.4 migration] only set cwuri for entities from the system source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2578
diff
changeset
|
23 |
if source == 'system': |
2480
a04caff1322e
take care of sources with no write support (eg ldapuser)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2463
diff
changeset
|
24 |
isession.execute('SET X cwuri %(u)s WHERE X eid %(x)s', |
a04caff1322e
take care of sources with no write support (eg ldapuser)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2463
diff
changeset
|
25 |
{'x': eid, 'u': base_url + u'eid/%s' % eid}) |
2463
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
26 |
isession.commit() |
2892
7ae3d62a8328
hooks have been refactored, call [re|de]activate_verification_hooks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2696
diff
changeset
|
27 |
reactivate_verification_hooks() |
2578
b717ebef04d8
[migration] reset do-not-insert-cwuri once it's properly in the schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2480
diff
changeset
|
28 |
session.set_shared_data('do-not-insert-cwuri', False) |
2463
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
29 |
|
2965
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
30 |
if applcubicwebversion < (3, 5, 0) and cubicwebversion >= (3, 5, 0): |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
31 |
add_entity_type('Workflow') |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
32 |
add_entity_type('BaseTransition') |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
33 |
add_entity_type('WorkflowTransition') |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
34 |
add_entity_type('SubWorkflowExitPoint') |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
35 |
drop_relation_definition('State', 'allowed_transition', 'Transition') # should be infered |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
36 |
schema.rebuild_infered_relations() # need to be explicitly called once everything is in place |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
37 |
|
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
38 |
for et in rql('DISTINCT Any ET,ETN WHERE S state_of ET, ET name ETN', |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
39 |
ask_confirm=False).entities(): |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
40 |
wf = add_workflow(u'default %s workflow' % et.name, et.name, |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
41 |
ask_confirm=False) |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
42 |
rql('SET S state_of WF WHERE S state_of ET, ET eid %(et)s, WF eid %(wf)s', |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
43 |
{'et': et.eid, 'wf': wf.eid}, 'et', ask_confirm=False) |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
44 |
rql('SET T transition_of WF WHERE T transition_of ET, ET eid %(et)s, WF eid %(wf)s', |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
45 |
{'et': et.eid, 'wf': wf.eid}, 'et', ask_confirm=False) |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
46 |
rql('SET WF initial_state S WHERE ET initial_state S, S state_of ET, ET eid %(et)s, WF eid %(wf)s', |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
47 |
{'et': et.eid, 'wf': wf.eid}, 'et', ask_confirm=False) |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
48 |
|
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
49 |
|
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
50 |
rql('DELETE TrInfo TI WHERE NOT TI from_state S') |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
51 |
rql('SET TI by_transition T WHERE TI from_state FS, TI to_state TS, ' |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
52 |
'FS allowed_transition T, T destination_state TS') |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
53 |
checkpoint() |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
54 |
|
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
55 |
drop_relation_definition('State', 'state_of', 'CWEType') |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
56 |
drop_relation_definition('Transition', 'transition_of', 'CWEType') |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
57 |
drop_relation_definition('CWEType', 'initial_state', 'State') |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
58 |
|
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
59 |
sync_schema_props_perms() |
75ad5cb00b88
3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2955
diff
changeset
|
60 |
|
1952
8e19c813750d
fix extid handling: ensure encoded string is given, and store them as base64 (see note in native.py).
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1501
diff
changeset
|
61 |
if applcubicwebversion < (3, 2, 2) and cubicwebversion >= (3, 2, 1): |
2462
9e670072884d
fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2275
diff
changeset
|
62 |
from base64 import b64encode |
9e670072884d
fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2275
diff
changeset
|
63 |
for table in ('entities', 'deleted_entities'): |
9e670072884d
fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2275
diff
changeset
|
64 |
for eid, extid in sql('SELECT eid, extid FROM %s WHERE extid is NOT NULL' |
9e670072884d
fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2275
diff
changeset
|
65 |
% table, ask_confirm=False): |
9e670072884d
fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2275
diff
changeset
|
66 |
sql('UPDATE %s SET extid=%%(extid)s WHERE eid=%%(eid)s' % table, |
9e670072884d
fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2275
diff
changeset
|
67 |
{'extid': b64encode(extid), 'eid': eid}, ask_confirm=False) |
9e670072884d
fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2275
diff
changeset
|
68 |
checkpoint() |
1952
8e19c813750d
fix extid handling: ensure encoded string is given, and store them as base64 (see note in native.py).
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1501
diff
changeset
|
69 |
|
1501
c80ca83a382f
migrate card cube in bootstrap migration
sylvain.thenault@logilab.fr
parents:
1399
diff
changeset
|
70 |
if applcubicwebversion < (3, 2, 0) and cubicwebversion >= (3, 2, 0): |
2462
9e670072884d
fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2275
diff
changeset
|
71 |
add_cube('card', update_database=False) |