author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 13 Aug 2009 10:20:57 +0200 | |
changeset 2799 | b703639614e7 |
parent 2696 | b45d852990d5 |
child 2892 | 7ae3d62a8328 |
child 2955 | 6bb5025c9fc7 |
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): |
2480
a04caff1322e
take care of sources with no write support (eg ldapuser)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2463
diff
changeset
|
14 |
from cubicweb import RepositoryError |
2463
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
15 |
from cubicweb.server.hooks import uniquecstrcheck_before_modification |
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
16 |
session.set_shared_data('do-not-insert-cwuri', True) |
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
17 |
repo.hm.unregister_hook(uniquecstrcheck_before_modification, 'before_add_entity', '') |
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
18 |
repo.hm.unregister_hook(uniquecstrcheck_before_modification, 'before_update_entity', '') |
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
19 |
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
|
20 |
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
|
21 |
# 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
|
22 |
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
|
23 |
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
|
24 |
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
|
25 |
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
|
26 |
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
|
27 |
{'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
|
28 |
isession.commit() |
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
29 |
repo.hm.register_hook(uniquecstrcheck_before_modification, 'before_add_entity', '') |
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
30 |
repo.hm.register_hook(uniquecstrcheck_before_modification, 'before_update_entity', '') |
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
|
31 |
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
|
32 |
|
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
|
33 |
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
|
34 |
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
|
35 |
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
|
36 |
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
|
37 |
% 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
|
38 |
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
|
39 |
{'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
|
40 |
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
|
41 |
|
1501
c80ca83a382f
migrate card cube in bootstrap migration
sylvain.thenault@logilab.fr
parents:
1399
diff
changeset
|
42 |
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
|
43 |
add_cube('card', update_database=False) |
1501
c80ca83a382f
migrate card cube in bootstrap migration
sylvain.thenault@logilab.fr
parents:
1399
diff
changeset
|
44 |
|
0 | 45 |
if applcubicwebversion < (2, 47, 0) and cubicwebversion >= (2, 47, 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
|
46 |
from cubicweb.server import schemaserial |
9e670072884d
fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2275
diff
changeset
|
47 |
schemaserial.HAS_FULLTEXT_CONTAINER = 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
|
48 |
session.set_shared_data('do-not-insert-is_instance_of', True) |
9e670072884d
fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2275
diff
changeset
|
49 |
add_attribute('CWRType', 'fulltext_container') |
9e670072884d
fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2275
diff
changeset
|
50 |
schemaserial.HAS_FULLTEXT_CONTAINER = True |
0 | 51 |
|
52 |
||
1501
c80ca83a382f
migrate card cube in bootstrap migration
sylvain.thenault@logilab.fr
parents:
1399
diff
changeset
|
53 |
|
0 | 54 |
if applcubicwebversion < (2, 50, 0) and cubicwebversion >= (2, 50, 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
|
55 |
session.set_shared_data('do-not-insert-is_instance_of', True) |
9e670072884d
fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2275
diff
changeset
|
56 |
add_relation_type('is_instance_of') |
9e670072884d
fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2275
diff
changeset
|
57 |
# fill the relation using an efficient sql query instead of using rql |
9e670072884d
fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2275
diff
changeset
|
58 |
sql('INSERT INTO is_instance_of_relation ' |
9e670072884d
fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2275
diff
changeset
|
59 |
' SELECT * from is_relation') |
9e670072884d
fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2275
diff
changeset
|
60 |
checkpoint() |
9e670072884d
fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2275
diff
changeset
|
61 |
session.set_shared_data('do-not-insert-is_instance_of', False) |
0 | 62 |
|
63 |
if applcubicwebversion < (2, 42, 0) and cubicwebversion >= (2, 42, 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
|
64 |
sql('ALTER TABLE entities ADD COLUMN mtime TIMESTAMP') |
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 |
sql('UPDATE entities SET mtime=CURRENT_TIMESTAMP') |
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('CREATE INDEX entities_mtime_idx ON entities(mtime)') |
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 |
sql('''CREATE TABLE deleted_entities ( |
0 | 68 |
eid INTEGER PRIMARY KEY NOT NULL, |
69 |
type VARCHAR(64) NOT NULL, |
|
70 |
source VARCHAR(64) NOT NULL, |
|
71 |
dtime TIMESTAMP NOT NULL, |
|
72 |
extid VARCHAR(256) |
|
73 |
)''') |
|
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
|
74 |
sql('CREATE INDEX deleted_entities_type_idx ON deleted_entities(type)') |
9e670072884d
fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2275
diff
changeset
|
75 |
sql('CREATE INDEX deleted_entities_dtime_idx ON deleted_entities(dtime)') |
9e670072884d
fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2275
diff
changeset
|
76 |
sql('CREATE INDEX deleted_entities_extid_idx ON deleted_entities(extid)') |
9e670072884d
fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2275
diff
changeset
|
77 |
checkpoint() |