author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 31 Jul 2009 10:42:15 +0200 | |
changeset 2585 | d84ea8753290 |
parent 2578 | b717ebef04d8 |
child 2696 | b45d852990d5 |
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): |
2480
a04caff1322e
take care of sources with no write support (eg ldapuser)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2463
diff
changeset
|
24 |
try: |
a04caff1322e
take care of sources with no write support (eg ldapuser)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2463
diff
changeset
|
25 |
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
|
26 |
{'x': eid, 'u': base_url + u'eid/%s' % eid}) |
a04caff1322e
take care of sources with no write support (eg ldapuser)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2463
diff
changeset
|
27 |
except RepositoryError: |
a04caff1322e
take care of sources with no write support (eg ldapuser)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2463
diff
changeset
|
28 |
print 'unable to set cwuri for', eid, session.describe(eid) |
2463
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
29 |
isession.commit() |
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_add_entity', '') |
5200c0f7d2d5
add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2462
diff
changeset
|
31 |
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
|
32 |
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
|
33 |
|
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
|
34 |
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
|
35 |
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
|
36 |
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
|
37 |
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
|
38 |
% 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
|
39 |
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
|
40 |
{'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
|
41 |
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
|
42 |
|
1501
c80ca83a382f
migrate card cube in bootstrap migration
sylvain.thenault@logilab.fr
parents:
1399
diff
changeset
|
43 |
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
|
44 |
add_cube('card', update_database=False) |
1501
c80ca83a382f
migrate card cube in bootstrap migration
sylvain.thenault@logilab.fr
parents:
1399
diff
changeset
|
45 |
|
0 | 46 |
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
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
schemaserial.HAS_FULLTEXT_CONTAINER = True |
0 | 52 |
|
53 |
||
1501
c80ca83a382f
migrate card cube in bootstrap migration
sylvain.thenault@logilab.fr
parents:
1399
diff
changeset
|
54 |
|
0 | 55 |
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
|
56 |
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
|
57 |
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
|
58 |
# 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
|
59 |
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
|
60 |
' 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
|
61 |
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
|
62 |
session.set_shared_data('do-not-insert-is_instance_of', False) |
0 | 63 |
|
64 |
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
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
sql('''CREATE TABLE deleted_entities ( |
0 | 69 |
eid INTEGER PRIMARY KEY NOT NULL, |
70 |
type VARCHAR(64) NOT NULL, |
|
71 |
source VARCHAR(64) NOT NULL, |
|
72 |
dtime TIMESTAMP NOT NULL, |
|
73 |
extid VARCHAR(256) |
|
74 |
)''') |
|
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
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
checkpoint() |