author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Fri, 24 Jul 2009 10:36:57 +0200 | |
changeset 2466 | c4ccfd38a542 |
parent 2463 | 5200c0f7d2d5 |
child 2480 | a04caff1322e |
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): |
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
14 |
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
|
15 |
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
|
16 |
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
|
17 |
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
|
18 |
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
|
19 |
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
|
20 |
# 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
|
21 |
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
|
22 |
for eid, in rql('Any X', ask_confirm=False): |
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
23 |
isession.execute('SET X cwuri %(u)s WHERE X eid %(x)s', |
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
24 |
{'x': eid, 'u': base_url + u'eid/%s' % eid}) |
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
25 |
isession.commit() |
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
26 |
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
|
27 |
repo.hm.register_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
|
28 |
|
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
|
29 |
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
|
30 |
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
|
31 |
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
|
32 |
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
|
33 |
% 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
|
34 |
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
|
35 |
{'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
|
36 |
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
|
37 |
|
1501
c80ca83a382f
migrate card cube in bootstrap migration
sylvain.thenault@logilab.fr
parents:
1399
diff
changeset
|
38 |
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
|
39 |
add_cube('card', update_database=False) |
1501
c80ca83a382f
migrate card cube in bootstrap migration
sylvain.thenault@logilab.fr
parents:
1399
diff
changeset
|
40 |
|
0 | 41 |
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
|
42 |
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
|
43 |
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
|
44 |
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
|
45 |
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
|
46 |
schemaserial.HAS_FULLTEXT_CONTAINER = True |
0 | 47 |
|
48 |
||
1501
c80ca83a382f
migrate card cube in bootstrap migration
sylvain.thenault@logilab.fr
parents:
1399
diff
changeset
|
49 |
|
0 | 50 |
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
|
51 |
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
|
52 |
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
|
53 |
# 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
|
54 |
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
|
55 |
' 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
|
56 |
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
|
57 |
session.set_shared_data('do-not-insert-is_instance_of', False) |
0 | 58 |
|
59 |
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
|
60 |
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
|
61 |
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
|
62 |
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
|
63 |
sql('''CREATE TABLE deleted_entities ( |
0 | 64 |
eid INTEGER PRIMARY KEY NOT NULL, |
65 |
type VARCHAR(64) NOT NULL, |
|
66 |
source VARCHAR(64) NOT NULL, |
|
67 |
dtime TIMESTAMP NOT NULL, |
|
68 |
extid VARCHAR(256) |
|
69 |
)''') |
|
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
|
70 |
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
|
71 |
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
|
72 |
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
|
73 |
checkpoint() |