author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Sun, 16 Jun 2013 23:36:06 +0200 | |
changeset 9446 | 18a186b02970 |
parent 9395 | 96dba2efd16d |
child 9406 | 38debfa8b536 |
child 9460 | a2a0bc984863 |
permissions | -rw-r--r-- |
9375
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
1 |
driver = config.sources()['system']['db-driver'] |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
2 |
if not (driver == 'postgres' or driver.startswith('sqlserver')): |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
3 |
import sys |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
4 |
print >>sys.stderr, 'This migration is not supported for backends other than sqlserver or postgres (yet).' |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
5 |
sys.exit(1) |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
6 |
|
9299
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
7 |
sync_schema_props_perms('defaultval') |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
8 |
|
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
9 |
def convert_defaultval(cwattr, default): |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
10 |
from decimal import Decimal |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
11 |
import yams |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
12 |
from cubicweb import Binary |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
13 |
if default is None: |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
14 |
return |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
15 |
atype = cwattr.to_entity[0].name |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
16 |
if atype == 'Boolean': |
9360
eda5071e30a1
[migration] fix handling of default value for boolean attributes
Julien Cristau <julien.cristau@logilab.fr>
parents:
9300
diff
changeset
|
17 |
# boolean attributes with default=False were stored as '' |
eda5071e30a1
[migration] fix handling of default value for boolean attributes
Julien Cristau <julien.cristau@logilab.fr>
parents:
9300
diff
changeset
|
18 |
assert default in ('True', 'False', ''), repr(default) |
9299
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
19 |
default = default == 'True' |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
20 |
elif atype in ('Int', 'BigInt'): |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
21 |
default = int(default) |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
22 |
elif atype == 'Float': |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
23 |
default = float(default) |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
24 |
elif atype == 'Decimal': |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
25 |
default = Decimal(default) |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
26 |
elif atype in ('Date', 'Datetime', 'TZDatetime', 'Time'): |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
27 |
try: |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
28 |
# handle NOW and TODAY, keep them stored as strings |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
29 |
yams.KEYWORD_MAP[atype][default.upper()] |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
30 |
default = default.upper() |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
31 |
except KeyError: |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
32 |
# otherwise get an actual date or datetime |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
33 |
default = yams.DATE_FACTORY_MAP[atype](default) |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
34 |
else: |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
35 |
assert atype == 'String', atype |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
36 |
default = unicode(default) |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
37 |
return Binary.zpickle(default) |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
38 |
|
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
39 |
dbh = repo.system_source.dbhelper |
9300
5f10cd13224d
defaultval migration for sqlite
Julien Cristau <julien.cristau@logilab.fr>
parents:
9299
diff
changeset
|
40 |
|
5f10cd13224d
defaultval migration for sqlite
Julien Cristau <julien.cristau@logilab.fr>
parents:
9299
diff
changeset
|
41 |
|
9375
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
42 |
sql('ALTER TABLE cw_cwattribute ADD new_defaultval %s' % dbh.TYPE_MAPPING['Bytes']) |
9300
5f10cd13224d
defaultval migration for sqlite
Julien Cristau <julien.cristau@logilab.fr>
parents:
9299
diff
changeset
|
43 |
|
9375
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
44 |
for cwattr in rql('CWAttribute X').entities(): |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
45 |
olddefault = cwattr.defaultval |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
46 |
if olddefault is not None: |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
47 |
req = "UPDATE cw_cwattribute SET new_defaultval = %(val)s WHERE cw_eid = %(eid)s" |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
48 |
args = {'val': dbh.binary_value(convert_defaultval(cwattr, olddefault).getvalue()), 'eid': cwattr.eid} |
9300
5f10cd13224d
defaultval migration for sqlite
Julien Cristau <julien.cristau@logilab.fr>
parents:
9299
diff
changeset
|
49 |
sql(req, args, ask_confirm=False) |
5f10cd13224d
defaultval migration for sqlite
Julien Cristau <julien.cristau@logilab.fr>
parents:
9299
diff
changeset
|
50 |
|
9375
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
51 |
sql('ALTER TABLE cw_cwattribute DROP COLUMN cw_defaultval') |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
52 |
if driver == 'postgres': |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
53 |
sql('ALTER TABLE cw_cwattribute RENAME COLUMN new_defaultval TO cw_defaultval') |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
54 |
else: # sqlserver |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
55 |
sql("sp_rename 'cw_cwattribute.new_defaultval', 'cw_defaultval', 'COLUMN'") |
9300
5f10cd13224d
defaultval migration for sqlite
Julien Cristau <julien.cristau@logilab.fr>
parents:
9299
diff
changeset
|
56 |
|
9299
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
57 |
|
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
58 |
# Set object type to "Bytes" for CWAttribute's "defaultval" attribute |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
59 |
rql('SET X to_entity B WHERE X is CWAttribute, X from_entity Y, Y name "CWAttribute", ' |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
60 |
'X relation_type Z, Z name "defaultval", B name "Bytes"') |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
61 |
|
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
62 |
from yams import buildobjs as ybo |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
63 |
schema.add_relation_def(ybo.RelationDefinition('CWAttribute', 'defaultval', 'Bytes')) |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
64 |
schema.del_relation_def('CWAttribute', 'defaultval', 'String') |
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
65 |
|
c5eed908117d
[schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
66 |
commit() |
9361
0542a85fe667
symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9360
diff
changeset
|
67 |
|
0542a85fe667
symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9360
diff
changeset
|
68 |
for rschema in schema.relations(): |
0542a85fe667
symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9360
diff
changeset
|
69 |
if rschema.symmetric: |
9370
15c695d8d865
[migration/3.18] add sanity checks before changing symmetric relations
Julien Cristau <julien.cristau@logilab.fr>
parents:
9369
diff
changeset
|
70 |
subjects = set(repr(e.type) for e in rschema.subjects()) |
15c695d8d865
[migration/3.18] add sanity checks before changing symmetric relations
Julien Cristau <julien.cristau@logilab.fr>
parents:
9369
diff
changeset
|
71 |
objects = set(repr(e.type) for e in rschema.objects()) |
15c695d8d865
[migration/3.18] add sanity checks before changing symmetric relations
Julien Cristau <julien.cristau@logilab.fr>
parents:
9369
diff
changeset
|
72 |
assert subjects == objects |
15c695d8d865
[migration/3.18] add sanity checks before changing symmetric relations
Julien Cristau <julien.cristau@logilab.fr>
parents:
9369
diff
changeset
|
73 |
martians = set(str(eid) for eid, in sql('SELECT eid_to FROM %s_relation, entities WHERE eid_to = eid AND type NOT IN (%s)' % |
15c695d8d865
[migration/3.18] add sanity checks before changing symmetric relations
Julien Cristau <julien.cristau@logilab.fr>
parents:
9369
diff
changeset
|
74 |
(rschema.type, ','.join(subjects)))) |
15c695d8d865
[migration/3.18] add sanity checks before changing symmetric relations
Julien Cristau <julien.cristau@logilab.fr>
parents:
9369
diff
changeset
|
75 |
martians |= set(str(eid) for eid, in sql('SELECT eid_from FROM %s_relation, entities WHERE eid_from = eid AND type NOT IN (%s)' % |
15c695d8d865
[migration/3.18] add sanity checks before changing symmetric relations
Julien Cristau <julien.cristau@logilab.fr>
parents:
9369
diff
changeset
|
76 |
(rschema.type, ','.join(subjects)))) |
15c695d8d865
[migration/3.18] add sanity checks before changing symmetric relations
Julien Cristau <julien.cristau@logilab.fr>
parents:
9369
diff
changeset
|
77 |
if martians: |
15c695d8d865
[migration/3.18] add sanity checks before changing symmetric relations
Julien Cristau <julien.cristau@logilab.fr>
parents:
9369
diff
changeset
|
78 |
martians = ','.join(martians) |
15c695d8d865
[migration/3.18] add sanity checks before changing symmetric relations
Julien Cristau <julien.cristau@logilab.fr>
parents:
9369
diff
changeset
|
79 |
print 'deleting broken relations %s for eids %s' % (rschema.type, martians) |
15c695d8d865
[migration/3.18] add sanity checks before changing symmetric relations
Julien Cristau <julien.cristau@logilab.fr>
parents:
9369
diff
changeset
|
80 |
sql('DELETE FROM %s_relation WHERE eid_from IN (%s) OR eid_to IN (%s)' % (rschema.type, martians, martians)) |
9369
176c1edf51b0
[migration/3.18] disable all hooks when setting up symmetric relations
Julien Cristau <julien.cristau@logilab.fr>
parents:
9361
diff
changeset
|
81 |
with session.deny_all_hooks_but(): |
9361
0542a85fe667
symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9360
diff
changeset
|
82 |
rql('SET X %(r)s Y WHERE Y %(r)s X, NOT X %(r)s Y' % {'r': rschema.type}) |
0542a85fe667
symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9360
diff
changeset
|
83 |
commit() |
9375
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
84 |
|
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
85 |
|
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
86 |
# multi columns unique constraints regeneration |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
87 |
from cubicweb.server import schemaserial |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
88 |
|
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
89 |
# syncschema hooks would try to remove indices but |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
90 |
# 1) we already do that below |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
91 |
# 2) the hook expects the CWUniqueTogetherConstraint.name attribute that hasn't |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
92 |
# yet been added |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
93 |
with session.allow_all_hooks_but('syncschema'): |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
94 |
rql('DELETE CWUniqueTogetherConstraint C') |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
95 |
commit() |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
96 |
|
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
97 |
add_attribute('CWUniqueTogetherConstraint', 'name') |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
98 |
|
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
99 |
# low-level wipe code for postgres & sqlserver, plain sql ... |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
100 |
if driver == 'postgres': |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
101 |
for indexname, in sql('select indexname from pg_indexes'): |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
102 |
if indexname.startswith('unique_'): |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
103 |
print 'dropping index', indexname |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
104 |
sql('DROP INDEX %s' % indexname) |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
105 |
commit() |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
106 |
elif driver.startswith('sqlserver'): |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
107 |
for viewname, in sql('select name from sys.views'): |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
108 |
if viewname.startswith('utv_'): |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
109 |
print 'dropping view (index should be cascade-deleted)', viewname |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
110 |
sql('DROP VIEW %s' % viewname) |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
111 |
commit() |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
112 |
|
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
113 |
# recreate the constraints, hook will lead to low-level recreation |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
114 |
for eschema in sorted(schema.entities()): |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
115 |
if eschema._unique_together: |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
116 |
rql_args = schemaserial.uniquetogether2rqls(eschema) |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
117 |
for rql, args in rql_args: |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
118 |
args['x'] = eschema.eid |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
119 |
session.execute(rql, args) |
8e88576787c3
[schema] fix unique together index handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9370
diff
changeset
|
120 |
commit() |
9395
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9375
diff
changeset
|
121 |
|
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9375
diff
changeset
|
122 |
|
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9375
diff
changeset
|
123 |
add_relation_definition('CWAttribute', 'add_permission', 'CWGroup') |
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9375
diff
changeset
|
124 |
add_relation_definition('CWAttribute', 'add_permission', 'RQLExpression') |
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9375
diff
changeset
|
125 |
|
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9375
diff
changeset
|
126 |
# all attributes perms have to be refreshed ... |
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9375
diff
changeset
|
127 |
for rschema in schema.relations(): |
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9375
diff
changeset
|
128 |
if relation.final: |
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9375
diff
changeset
|
129 |
sync_schema_props_perms(rschema.type, syncprops=False) |