author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 17 Dec 2009 16:17:57 +0100 | |
branch | stable |
changeset 4129 | 887e3edc30c5 |
parent 3881 | a192bc3c13b7 |
child 4212 | ab6573088b4a |
permissions | -rw-r--r-- |
0 | 1 |
"""schema hooks: |
2 |
||
3 |
- synchronize the living schema object with the persistent schema |
|
4 |
- perform physical update on the source when necessary |
|
5 |
||
6 |
checking for schema consistency is done in hooks.py |
|
7 |
||
8 |
:organization: Logilab |
|
1981
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1802
diff
changeset
|
9 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 10 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1981
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1802
diff
changeset
|
11 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 12 |
""" |
13 |
__docformat__ = "restructuredtext en" |
|
14 |
||
15 |
from yams.schema import BASE_TYPES |
|
16 |
from yams.buildobjs import EntityType, RelationType, RelationDefinition |
|
2019
399a930e10ef
#343488: SQL error in migration script (depends on a new release of yams and lgc)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2011
diff
changeset
|
17 |
from yams.schema2sql import eschema2sql, rschema2sql, type_from_constraints |
0 | 18 |
|
3774
1eca47d59fd9
on precommit / rollback of schema update op, clear order_relations cache of entity schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
19 |
from logilab.common.decorators import clear_cache |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
20 |
|
0 | 21 |
from cubicweb import ValidationError, RepositoryError |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
22 |
from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES, CONSTRAINTS |
0 | 23 |
from cubicweb.server import schemaserial as ss |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
24 |
from cubicweb.server.sqlutils import SQL_PREFIX |
0 | 25 |
from cubicweb.server.pool import Operation, SingleLastOperation, PreCommitOperation |
3869
ec6463886ac4
[server] remove not-so-useful entity_name and entity_attr functions, introduce entity_oldnewvalue
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3774
diff
changeset
|
26 |
from cubicweb.server.hookhelper import entity_oldnewvalue, check_internal_entity |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
27 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
28 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
29 |
TYPE_CONVERTER = { # XXX |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
30 |
'Boolean': bool, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
31 |
'Int': int, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
32 |
'Float': float, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
33 |
'Password': str, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
34 |
'String': unicode, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
35 |
'Date' : unicode, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
36 |
'Datetime' : unicode, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
37 |
'Time' : unicode, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
38 |
} |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
39 |
|
0 | 40 |
# core entity and relation types which can't be removed |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
41 |
CORE_ETYPES = list(BASE_TYPES) + ['CWEType', 'CWRType', 'CWUser', 'CWGroup', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
42 |
'CWConstraint', 'CWAttribute', 'CWRelation'] |
2456
aa25d6b244c8
new cwuri metadata + a few tests fixes on the way
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2455
diff
changeset
|
43 |
CORE_RTYPES = ['eid', 'creation_date', 'modification_date', 'cwuri', |
0 | 44 |
'login', 'upassword', 'name', |
45 |
'is', 'instanceof', 'owned_by', 'created_by', 'in_group', |
|
46 |
'relation_type', 'from_entity', 'to_entity', |
|
47 |
'constrainted_by', |
|
48 |
'read_permission', 'add_permission', |
|
49 |
'delete_permission', 'updated_permission', |
|
50 |
] |
|
51 |
||
52 |
def get_constraints(session, entity): |
|
53 |
constraints = [] |
|
2101
08003e0354a7
update transaction data api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2056
diff
changeset
|
54 |
for cstreid in session.transaction_data.get(entity.eid, ()): |
2195
58bef4f707ce
update calls to a deprecated method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2101
diff
changeset
|
55 |
cstrent = session.entity_from_eid(cstreid) |
0 | 56 |
cstr = CONSTRAINTS[cstrent.type].deserialize(cstrent.value) |
57 |
cstr.eid = cstreid |
|
58 |
constraints.append(cstr) |
|
59 |
return constraints |
|
60 |
||
61 |
def add_inline_relation_column(session, etype, rtype): |
|
62 |
"""add necessary column and index for an inlined relation""" |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
63 |
table = SQL_PREFIX + etype |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
64 |
column = SQL_PREFIX + rtype |
0 | 65 |
try: |
66 |
session.system_sql(str('ALTER TABLE %s ADD COLUMN %s integer' |
|
2618
ff9b0d5bd884
[F repo sqlite schema changes] don't rollback on potentially expected schema changes failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2617
diff
changeset
|
67 |
% (table, column)), rollback_on_failure=False) |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
68 |
session.info('added column %s to table %s', column, table) |
0 | 69 |
except: |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
70 |
# silent exception here, if this error has not been raised because the |
0 | 71 |
# column already exists, index creation will fail anyway |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
72 |
session.exception('error while adding column %s to table %s', |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
73 |
table, column) |
0 | 74 |
# create index before alter table which may expectingly fail during test |
75 |
# (sqlite) while index creation should never fail (test for index existence |
|
76 |
# is done by the dbhelper) |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
77 |
session.pool.source('system').create_index(session, table, column) |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
78 |
session.info('added index on %s(%s)', table, column) |
2101
08003e0354a7
update transaction data api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2056
diff
changeset
|
79 |
session.transaction_data.setdefault('createdattrs', []).append( |
08003e0354a7
update transaction data api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2056
diff
changeset
|
80 |
'%s.%s' % (etype, rtype)) |
0 | 81 |
|
82 |
||
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
83 |
# operations for low-level database alteration ################################ |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
84 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
85 |
class DropTable(PreCommitOperation): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2462
diff
changeset
|
86 |
"""actually remove a database from the instance's schema""" |
1138
22f634977c95
make pylint happy, fix some bugs on the way
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
87 |
table = None # make pylint happy |
0 | 88 |
def precommit_event(self): |
2101
08003e0354a7
update transaction data api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2056
diff
changeset
|
89 |
dropped = self.session.transaction_data.setdefault('droppedtables', |
08003e0354a7
update transaction data api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2056
diff
changeset
|
90 |
set()) |
0 | 91 |
if self.table in dropped: |
92 |
return # already processed |
|
93 |
dropped.add(self.table) |
|
94 |
self.session.system_sql('DROP TABLE %s' % self.table) |
|
95 |
self.info('dropped table %s', self.table) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
96 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
97 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
98 |
class DropRelationTable(DropTable): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
99 |
def __init__(self, session, rtype): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
100 |
super(DropRelationTable, self).__init__( |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
101 |
session, table='%s_relation' % rtype) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
102 |
session.transaction_data.setdefault('pendingrtypes', set()).add(rtype) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
103 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
104 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
105 |
class DropColumn(PreCommitOperation): |
0 | 106 |
"""actually remove the attribut's column from entity table in the system |
107 |
database |
|
108 |
""" |
|
1138
22f634977c95
make pylint happy, fix some bugs on the way
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
109 |
table = column = None # make pylint happy |
0 | 110 |
def precommit_event(self): |
111 |
session, table, column = self.session, self.table, self.column |
|
112 |
# drop index if any |
|
113 |
session.pool.source('system').drop_index(session, table, column) |
|
114 |
try: |
|
115 |
session.system_sql('ALTER TABLE %s DROP COLUMN %s' |
|
2618
ff9b0d5bd884
[F repo sqlite schema changes] don't rollback on potentially expected schema changes failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2617
diff
changeset
|
116 |
% (table, column), rollback_on_failure=False) |
0 | 117 |
self.info('dropped column %s from table %s', column, table) |
118 |
except Exception, ex: |
|
119 |
# not supported by sqlite for instance |
|
120 |
self.error('error while altering table %s: %s', table, ex) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
121 |
|
0 | 122 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
123 |
# base operations for in-memory schema synchronization ######################## |
0 | 124 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
125 |
class MemSchemaNotifyChanges(SingleLastOperation): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
126 |
"""the update schema operation: |
0 | 127 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
128 |
special operation which should be called once and after all other schema |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
129 |
operations. It will trigger internal structures rebuilding to consider |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
130 |
schema changes |
0 | 131 |
""" |
132 |
||
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
133 |
def __init__(self, session): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
134 |
self.repo = session.repo |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
135 |
SingleLastOperation.__init__(self, session) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
136 |
|
3774
1eca47d59fd9
on precommit / rollback of schema update op, clear order_relations cache of entity schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
137 |
def precommit_event(self): |
1eca47d59fd9
on precommit / rollback of schema update op, clear order_relations cache of entity schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
138 |
for eschema in self.repo.schema.entities(): |
1eca47d59fd9
on precommit / rollback of schema update op, clear order_relations cache of entity schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
139 |
if not eschema.final: |
1eca47d59fd9
on precommit / rollback of schema update op, clear order_relations cache of entity schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
140 |
clear_cache(eschema, 'ordered_relations') |
1eca47d59fd9
on precommit / rollback of schema update op, clear order_relations cache of entity schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
141 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
142 |
def commit_event(self): |
2963
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
143 |
rebuildinfered = self.session.data.get('rebuild-infered', True) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
144 |
self.repo.set_schema(self.repo.schema, rebuildinfered=rebuildinfered) |
3870
a6b029aa0f44
[hooks] update CWUser class after schema changes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3869
diff
changeset
|
145 |
# CWUser class might have changed, update current session users |
a6b029aa0f44
[hooks] update CWUser class after schema changes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3869
diff
changeset
|
146 |
cwuser_cls = self.session.vreg['etypes'].etype_class('CWUser') |
a6b029aa0f44
[hooks] update CWUser class after schema changes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3869
diff
changeset
|
147 |
for session in self.repo._sessions.values(): |
a6b029aa0f44
[hooks] update CWUser class after schema changes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3869
diff
changeset
|
148 |
session.user.__class__ = cwuser_cls |
0 | 149 |
|
3774
1eca47d59fd9
on precommit / rollback of schema update op, clear order_relations cache of entity schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
150 |
def rollback_event(self): |
1eca47d59fd9
on precommit / rollback of schema update op, clear order_relations cache of entity schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
151 |
self.precommit_event() |
1eca47d59fd9
on precommit / rollback of schema update op, clear order_relations cache of entity schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
152 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
153 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
154 |
class MemSchemaOperation(Operation): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
155 |
"""base class for schema operations""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
156 |
def __init__(self, session, kobj=None, **kwargs): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
157 |
self.schema = session.schema |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
158 |
self.kobj = kobj |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
159 |
# once Operation.__init__ has been called, event may be triggered, so |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
160 |
# do this last ! |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
161 |
Operation.__init__(self, session, **kwargs) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
162 |
# every schema operation is triggering a schema update |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
163 |
MemSchemaNotifyChanges(session) |
0 | 164 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
165 |
def prepare_constraints(self, subjtype, rtype, objtype): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
166 |
constraints = rtype.rproperty(subjtype, objtype, 'constraints') |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
167 |
self.constraints = list(constraints) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
168 |
rtype.set_rproperty(subjtype, objtype, 'constraints', self.constraints) |
0 | 169 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
170 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
171 |
class MemSchemaEarlyOperation(MemSchemaOperation): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
172 |
def insert_index(self): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
173 |
"""schema operation which are inserted at the begining of the queue |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
174 |
(typically to add/remove entity or relation types) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
175 |
""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
176 |
i = -1 |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
177 |
for i, op in enumerate(self.session.pending_operations): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
178 |
if not isinstance(op, MemSchemaEarlyOperation): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
179 |
return i |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
180 |
return i + 1 |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
181 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
182 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
183 |
class MemSchemaPermissionOperation(MemSchemaOperation): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
184 |
"""base class to synchronize schema permission definitions""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
185 |
def __init__(self, session, perm, etype_eid): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
186 |
self.perm = perm |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
187 |
try: |
3869
ec6463886ac4
[server] remove not-so-useful entity_name and entity_attr functions, introduce entity_oldnewvalue
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3774
diff
changeset
|
188 |
self.name = session.entity_from_eid(etype_eid).name |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
189 |
except IndexError: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
190 |
self.error('changing permission of a no more existant type #%s', |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
191 |
etype_eid) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
192 |
else: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
193 |
Operation.__init__(self, session) |
0 | 194 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
195 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
196 |
# operations for high-level source database alteration ######################## |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
197 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
198 |
class SourceDbCWETypeRename(PreCommitOperation): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
199 |
"""this operation updates physical storage accordingly""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
200 |
oldname = newname = None # make pylint happy |
0 | 201 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
202 |
def precommit_event(self): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
203 |
# we need sql to operate physical changes on the system database |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
204 |
sqlexec = self.session.system_sql |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
205 |
sqlexec('ALTER TABLE %s%s RENAME TO %s%s' % (SQL_PREFIX, self.oldname, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
206 |
SQL_PREFIX, self.newname)) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
207 |
self.info('renamed table %s to %s', self.oldname, self.newname) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
208 |
sqlexec('UPDATE entities SET type=%s WHERE type=%s', |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
209 |
(self.newname, self.oldname)) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
210 |
sqlexec('UPDATE deleted_entities SET type=%s WHERE type=%s', |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
211 |
(self.newname, self.oldname)) |
0 | 212 |
|
213 |
||
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
214 |
class SourceDbCWRTypeUpdate(PreCommitOperation): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
215 |
"""actually update some properties of a relation definition""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
216 |
rschema = values = entity = None # make pylint happy |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
217 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
218 |
def precommit_event(self): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
219 |
session = self.session |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
220 |
rschema = self.rschema |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3550
diff
changeset
|
221 |
if rschema.final or not 'inlined' in self.values: |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
222 |
return # nothing to do |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
223 |
inlined = self.values['inlined'] |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
224 |
entity = self.entity |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
225 |
# check in-lining is necessary / possible |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
226 |
if not entity.inlined_changed(inlined): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
227 |
return # nothing to do |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
228 |
# inlined changed, make necessary physical changes! |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
229 |
sqlexec = self.session.system_sql |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
230 |
rtype = rschema.type |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
231 |
eidcolumn = SQL_PREFIX + 'eid' |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
232 |
if not inlined: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
233 |
# need to create the relation if it has not been already done by |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
234 |
# another event of the same transaction |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
235 |
if not rschema.type in session.transaction_data.get('createdtables', ()): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
236 |
tablesql = rschema2sql(rschema) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
237 |
# create the necessary table |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
238 |
for sql in tablesql.split(';'): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
239 |
if sql.strip(): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
240 |
sqlexec(sql) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
241 |
session.transaction_data.setdefault('createdtables', []).append( |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
242 |
rschema.type) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
243 |
# copy existant data |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
244 |
column = SQL_PREFIX + rtype |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
245 |
for etype in rschema.subjects(): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
246 |
table = SQL_PREFIX + str(etype) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
247 |
sqlexec('INSERT INTO %s_relation SELECT %s, %s FROM %s WHERE NOT %s IS NULL' |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
248 |
% (rtype, eidcolumn, column, table, column)) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
249 |
# drop existant columns |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
250 |
for etype in rschema.subjects(): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
251 |
DropColumn(session, table=SQL_PREFIX + str(etype), |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
252 |
column=SQL_PREFIX + rtype) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
253 |
else: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
254 |
for etype in rschema.subjects(): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
255 |
try: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
256 |
add_inline_relation_column(session, str(etype), rtype) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
257 |
except Exception, ex: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
258 |
# the column probably already exists. this occurs when the |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
259 |
# entity's type has just been added or if the column has not |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
260 |
# been previously dropped |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
261 |
self.error('error while altering table %s: %s', etype, ex) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
262 |
# copy existant data. |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
263 |
# XXX don't use, it's not supported by sqlite (at least at when i tried it) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
264 |
#sqlexec('UPDATE %(etype)s SET %(rtype)s=eid_to ' |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
265 |
# 'FROM %(rtype)s_relation ' |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
266 |
# 'WHERE %(etype)s.eid=%(rtype)s_relation.eid_from' |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
267 |
# % locals()) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
268 |
table = SQL_PREFIX + str(etype) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
269 |
cursor = sqlexec('SELECT eid_from, eid_to FROM %(table)s, ' |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
270 |
'%(rtype)s_relation WHERE %(table)s.%(eidcolumn)s=' |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
271 |
'%(rtype)s_relation.eid_from' % locals()) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
272 |
args = [{'val': eid_to, 'x': eid} for eid, eid_to in cursor.fetchall()] |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
273 |
if args: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
274 |
column = SQL_PREFIX + rtype |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
275 |
cursor.executemany('UPDATE %s SET %s=%%(val)s WHERE %s=%%(x)s' |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
276 |
% (table, column, eidcolumn), args) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
277 |
# drop existant table |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
278 |
DropRelationTable(session, rtype) |
0 | 279 |
|
280 |
||
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
281 |
class SourceDbCWAttributeAdd(PreCommitOperation): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
282 |
"""an attribute relation (CWAttribute) has been added: |
0 | 283 |
* add the necessary column |
284 |
* set default on this column if any and possible |
|
285 |
* register an operation to add the relation definition to the |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2462
diff
changeset
|
286 |
instance's schema on commit |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
287 |
|
0 | 288 |
constraints are handled by specific hooks |
289 |
""" |
|
1138
22f634977c95
make pylint happy, fix some bugs on the way
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
290 |
entity = None # make pylint happy |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
291 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
292 |
def init_rdef(self, **kwargs): |
0 | 293 |
entity = self.entity |
2599
79bd12769c55
[R schema hooks] use new accessors on CWRelation and CWAttribute entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
294 |
fromentity = entity.stype |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
295 |
self.session.execute('SET X ordernum Y+1 ' |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
296 |
'WHERE X from_entity SE, SE eid %(se)s, X ordernum Y, ' |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
297 |
'X ordernum >= %(order)s, NOT X eid %(x)s', |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
298 |
{'x': entity.eid, 'se': fromentity.eid, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
299 |
'order': entity.ordernum or 0}) |
2624 | 300 |
subj = str(fromentity.name) |
301 |
rtype = entity.rtype.name |
|
2599
79bd12769c55
[R schema hooks] use new accessors on CWRelation and CWAttribute entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
302 |
obj = str(entity.otype.name) |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
303 |
constraints = get_constraints(self.session, entity) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
304 |
rdef = RelationDefinition(subj, rtype, obj, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
305 |
description=entity.description, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
306 |
cardinality=entity.cardinality, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
307 |
constraints=constraints, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
308 |
order=entity.ordernum, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
309 |
eid=entity.eid, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
310 |
**kwargs) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
311 |
MemSchemaRDefAdd(self.session, rdef) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
312 |
return rdef |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
313 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
314 |
def precommit_event(self): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
315 |
session = self.session |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
316 |
entity = self.entity |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
317 |
# entity.defaultval is a string or None, but we need a correctly typed |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
318 |
# value |
0 | 319 |
default = entity.defaultval |
320 |
if default is not None: |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
321 |
default = TYPE_CONVERTER[entity.otype.name](default) |
3526
dfb2ebb765e2
[migration]Â fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
322 |
props = {'default': default, |
dfb2ebb765e2
[migration]Â fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
323 |
'indexed': entity.indexed, |
dfb2ebb765e2
[migration]Â fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
324 |
'fulltextindexed': entity.fulltextindexed, |
dfb2ebb765e2
[migration]Â fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
325 |
'internationalizable': entity.internationalizable} |
dfb2ebb765e2
[migration]Â fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
326 |
rdef = self.init_rdef(**props) |
0 | 327 |
sysource = session.pool.source('system') |
2019
399a930e10ef
#343488: SQL error in migration script (depends on a new release of yams and lgc)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2011
diff
changeset
|
328 |
attrtype = type_from_constraints(sysource.dbhelper, rdef.object, |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
329 |
rdef.constraints) |
0 | 330 |
# XXX should be moved somehow into lgc.adbh: sqlite doesn't support to |
331 |
# add a new column with UNIQUE, it should be added after the ALTER TABLE |
|
332 |
# using ADD INDEX |
|
333 |
if sysource.dbdriver == 'sqlite' and 'UNIQUE' in attrtype: |
|
334 |
extra_unique_index = True |
|
335 |
attrtype = attrtype.replace(' UNIQUE', '') |
|
336 |
else: |
|
337 |
extra_unique_index = False |
|
338 |
# added some str() wrapping query since some backend (eg psycopg) don't |
|
339 |
# allow unicode queries |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
340 |
table = SQL_PREFIX + rdef.subject |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
341 |
column = SQL_PREFIX + rdef.name |
0 | 342 |
try: |
343 |
session.system_sql(str('ALTER TABLE %s ADD COLUMN %s %s' |
|
2618
ff9b0d5bd884
[F repo sqlite schema changes] don't rollback on potentially expected schema changes failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2617
diff
changeset
|
344 |
% (table, column, attrtype)), |
ff9b0d5bd884
[F repo sqlite schema changes] don't rollback on potentially expected schema changes failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2617
diff
changeset
|
345 |
rollback_on_failure=False) |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
346 |
self.info('added column %s to table %s', table, column) |
0 | 347 |
except Exception, ex: |
348 |
# the column probably already exists. this occurs when |
|
349 |
# the entity's type has just been added or if the column |
|
350 |
# has not been previously dropped |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
351 |
self.error('error while altering table %s: %s', table, ex) |
0 | 352 |
if extra_unique_index or entity.indexed: |
353 |
try: |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
354 |
sysource.create_index(session, table, column, |
0 | 355 |
unique=extra_unique_index) |
356 |
except Exception, ex: |
|
357 |
self.error('error while creating index for %s.%s: %s', |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
358 |
table, column, ex) |
3526
dfb2ebb765e2
[migration]Â fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
359 |
# final relations are not infered, propagate |
3531
c095f5f54873
[migration] take care to entity being added
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3526
diff
changeset
|
360 |
try: |
c095f5f54873
[migration] take care to entity being added
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3526
diff
changeset
|
361 |
eschema = self.schema.eschema(rdef.subject) |
c095f5f54873
[migration] take care to entity being added
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3526
diff
changeset
|
362 |
except KeyError: |
c095f5f54873
[migration] take care to entity being added
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3526
diff
changeset
|
363 |
return # entity type currently being added |
3543
ed152fe5aa8b
[migration] when adding a new attribute with a default value, set this value on existing entities (test and fix)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3531
diff
changeset
|
364 |
# propagate attribute to children classes |
3526
dfb2ebb765e2
[migration]Â fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
365 |
rschema = self.schema.rschema(rdef.name) |
3550
f9bdcfeb12ee
[migration] fix bug when propagating newly inserted relation type to children classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3546
diff
changeset
|
366 |
# if relation type has been inserted in the same transaction, its final |
f9bdcfeb12ee
[migration] fix bug when propagating newly inserted relation type to children classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3546
diff
changeset
|
367 |
# attribute is still set to False, so we've to ensure it's False |
f9bdcfeb12ee
[migration] fix bug when propagating newly inserted relation type to children classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3546
diff
changeset
|
368 |
rschema.final = True |
f9bdcfeb12ee
[migration] fix bug when propagating newly inserted relation type to children classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3546
diff
changeset
|
369 |
# XXX 'infered': True/False, not clear actually |
3526
dfb2ebb765e2
[migration]Â fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
370 |
props.update({'constraints': rdef.constraints, |
dfb2ebb765e2
[migration]Â fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
371 |
'description': rdef.description, |
dfb2ebb765e2
[migration]Â fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
372 |
'cardinality': rdef.cardinality, |
dfb2ebb765e2
[migration]Â fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
373 |
'constraints': rdef.constraints, |
dfb2ebb765e2
[migration]Â fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
374 |
'order': rdef.order}) |
dfb2ebb765e2
[migration]Â fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
375 |
for specialization in eschema.specialized_by(False): |
dfb2ebb765e2
[migration]Â fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
376 |
if rschema.has_rdef(specialization, rdef.object): |
dfb2ebb765e2
[migration]Â fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
377 |
continue |
dfb2ebb765e2
[migration]Â fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
378 |
for rql, args in ss.frdef2rql(rschema, str(specialization), |
dfb2ebb765e2
[migration]Â fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
379 |
rdef.object, props): |
dfb2ebb765e2
[migration]Â fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
380 |
session.execute(rql, args) |
3543
ed152fe5aa8b
[migration] when adding a new attribute with a default value, set this value on existing entities (test and fix)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3531
diff
changeset
|
381 |
# set default value, using sql for performance and to avoid |
ed152fe5aa8b
[migration] when adding a new attribute with a default value, set this value on existing entities (test and fix)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3531
diff
changeset
|
382 |
# modification_date update |
ed152fe5aa8b
[migration] when adding a new attribute with a default value, set this value on existing entities (test and fix)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3531
diff
changeset
|
383 |
if default: |
ed152fe5aa8b
[migration] when adding a new attribute with a default value, set this value on existing entities (test and fix)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3531
diff
changeset
|
384 |
session.system_sql('UPDATE %s SET %s=%%(default)s' % (table, column), |
ed152fe5aa8b
[migration] when adding a new attribute with a default value, set this value on existing entities (test and fix)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3531
diff
changeset
|
385 |
{'default': default}) |
0 | 386 |
|
387 |
||
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
388 |
class SourceDbCWRelationAdd(SourceDbCWAttributeAdd): |
0 | 389 |
"""an actual relation has been added: |
390 |
* if this is an inlined relation, add the necessary column |
|
391 |
else if it's the first instance of this relation type, add the |
|
392 |
necessary table and set default permissions |
|
393 |
* register an operation to add the relation definition to the |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2462
diff
changeset
|
394 |
instance's schema on commit |
0 | 395 |
|
396 |
constraints are handled by specific hooks |
|
397 |
""" |
|
1138
22f634977c95
make pylint happy, fix some bugs on the way
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
398 |
entity = None # make pylint happy |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
399 |
|
0 | 400 |
def precommit_event(self): |
401 |
session = self.session |
|
402 |
entity = self.entity |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
403 |
rdef = self.init_rdef(composite=entity.composite) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
404 |
schema = session.schema |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
405 |
rtype = rdef.name |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
406 |
rschema = session.schema.rschema(rtype) |
0 | 407 |
# this have to be done before permissions setting |
408 |
if rschema.inlined: |
|
409 |
# need to add a column if the relation is inlined and if this is the |
|
410 |
# first occurence of "Subject relation Something" whatever Something |
|
411 |
# and if it has not been added during other event of the same |
|
412 |
# transaction |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
413 |
key = '%s.%s' % (rdef.subject, rtype) |
0 | 414 |
try: |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
415 |
alreadythere = bool(rschema.objects(rdef.subject)) |
0 | 416 |
except KeyError: |
417 |
alreadythere = False |
|
418 |
if not (alreadythere or |
|
2101
08003e0354a7
update transaction data api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2056
diff
changeset
|
419 |
key in session.transaction_data.get('createdattrs', ())): |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
420 |
add_inline_relation_column(session, rdef.subject, rtype) |
0 | 421 |
else: |
422 |
# need to create the relation if no relation definition in the |
|
423 |
# schema and if it has not been added during other event of the same |
|
424 |
# transaction |
|
425 |
if not (rschema.subjects() or |
|
2101
08003e0354a7
update transaction data api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2056
diff
changeset
|
426 |
rtype in session.transaction_data.get('createdtables', ())): |
0 | 427 |
try: |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
428 |
rschema = session.schema.rschema(rtype) |
0 | 429 |
tablesql = rschema2sql(rschema) |
430 |
except KeyError: |
|
431 |
# fake we add it to the schema now to get a correctly |
|
432 |
# initialized schema but remove it before doing anything |
|
433 |
# more dangerous... |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
434 |
rschema = session.schema.add_relation_type(rdef) |
0 | 435 |
tablesql = rschema2sql(rschema) |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
436 |
session.schema.del_relation_type(rtype) |
0 | 437 |
# create the necessary table |
438 |
for sql in tablesql.split(';'): |
|
439 |
if sql.strip(): |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
440 |
session.system_sql(sql) |
2101
08003e0354a7
update transaction data api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2056
diff
changeset
|
441 |
session.transaction_data.setdefault('createdtables', []).append( |
08003e0354a7
update transaction data api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2056
diff
changeset
|
442 |
rtype) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
443 |
|
0 | 444 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
445 |
class SourceDbRDefUpdate(PreCommitOperation): |
0 | 446 |
"""actually update some properties of a relation definition""" |
1138
22f634977c95
make pylint happy, fix some bugs on the way
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
447 |
rschema = values = None # make pylint happy |
0 | 448 |
|
449 |
def precommit_event(self): |
|
2019
399a930e10ef
#343488: SQL error in migration script (depends on a new release of yams and lgc)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2011
diff
changeset
|
450 |
etype = self.kobj[0] |
399a930e10ef
#343488: SQL error in migration script (depends on a new release of yams and lgc)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2011
diff
changeset
|
451 |
table = SQL_PREFIX + etype |
399a930e10ef
#343488: SQL error in migration script (depends on a new release of yams and lgc)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2011
diff
changeset
|
452 |
column = SQL_PREFIX + self.rschema.type |
0 | 453 |
if 'indexed' in self.values: |
454 |
sysource = self.session.pool.source('system') |
|
455 |
if self.values['indexed']: |
|
456 |
sysource.create_index(self.session, table, column) |
|
457 |
else: |
|
458 |
sysource.drop_index(self.session, table, column) |
|
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3550
diff
changeset
|
459 |
if 'cardinality' in self.values and self.rschema.final: |
2019
399a930e10ef
#343488: SQL error in migration script (depends on a new release of yams and lgc)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2011
diff
changeset
|
460 |
adbh = self.session.pool.source('system').dbhelper |
399a930e10ef
#343488: SQL error in migration script (depends on a new release of yams and lgc)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2011
diff
changeset
|
461 |
if not adbh.alter_column_support: |
1981
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1802
diff
changeset
|
462 |
# not supported (and NOT NULL not set by yams in that case, so |
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1802
diff
changeset
|
463 |
# no worry) |
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1802
diff
changeset
|
464 |
return |
2019
399a930e10ef
#343488: SQL error in migration script (depends on a new release of yams and lgc)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2011
diff
changeset
|
465 |
atype = self.rschema.objects(etype)[0] |
399a930e10ef
#343488: SQL error in migration script (depends on a new release of yams and lgc)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2011
diff
changeset
|
466 |
constraints = self.rschema.rproperty(etype, atype, 'constraints') |
399a930e10ef
#343488: SQL error in migration script (depends on a new release of yams and lgc)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2011
diff
changeset
|
467 |
coltype = type_from_constraints(adbh, atype, constraints, |
399a930e10ef
#343488: SQL error in migration script (depends on a new release of yams and lgc)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2011
diff
changeset
|
468 |
creating=False) |
2056 | 469 |
# XXX check self.values['cardinality'][0] actually changed? |
2019
399a930e10ef
#343488: SQL error in migration script (depends on a new release of yams and lgc)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2011
diff
changeset
|
470 |
sql = adbh.sql_set_null_allowed(table, column, coltype, |
399a930e10ef
#343488: SQL error in migration script (depends on a new release of yams and lgc)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2011
diff
changeset
|
471 |
self.values['cardinality'][0] != '1') |
399a930e10ef
#343488: SQL error in migration script (depends on a new release of yams and lgc)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2011
diff
changeset
|
472 |
self.session.system_sql(sql) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
473 |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
474 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
475 |
class SourceDbCWConstraintAdd(PreCommitOperation): |
0 | 476 |
"""actually update constraint of a relation definition""" |
1138
22f634977c95
make pylint happy, fix some bugs on the way
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
477 |
entity = None # make pylint happy |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
478 |
cancelled = False |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
479 |
|
0 | 480 |
def precommit_event(self): |
481 |
rdef = self.entity.reverse_constrained_by[0] |
|
482 |
session = self.session |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
483 |
# when the relation is added in the same transaction, the constraint |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
484 |
# object is created by the operation adding the attribute or relation, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
485 |
# so there is nothing to do here |
2101
08003e0354a7
update transaction data api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2056
diff
changeset
|
486 |
if rdef.eid in session.transaction_data.get('neweids', ()): |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
487 |
return |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
488 |
subjtype, rtype, objtype = session.schema.schema_by_eid(rdef.eid) |
0 | 489 |
cstrtype = self.entity.type |
2697
a0c4bc933a1b
[schema hooks] rename variable, check unique constraint actually changed before creating the index
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
490 |
oldcstr = rtype.constraint_by_type(subjtype, objtype, cstrtype) |
a0c4bc933a1b
[schema hooks] rename variable, check unique constraint actually changed before creating the index
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
491 |
newcstr = CONSTRAINTS[cstrtype].deserialize(self.entity.value) |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
492 |
table = SQL_PREFIX + str(subjtype) |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
493 |
column = SQL_PREFIX + str(rtype) |
0 | 494 |
# alter the physical schema on size constraint changes |
2697
a0c4bc933a1b
[schema hooks] rename variable, check unique constraint actually changed before creating the index
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
495 |
if newcstr.type() == 'SizeConstraint' and ( |
a0c4bc933a1b
[schema hooks] rename variable, check unique constraint actually changed before creating the index
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
496 |
oldcstr is None or oldcstr.max != newcstr.max): |
2019
399a930e10ef
#343488: SQL error in migration script (depends on a new release of yams and lgc)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2011
diff
changeset
|
497 |
adbh = self.session.pool.source('system').dbhelper |
399a930e10ef
#343488: SQL error in migration script (depends on a new release of yams and lgc)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2011
diff
changeset
|
498 |
card = rtype.rproperty(subjtype, objtype, 'cardinality') |
2697
a0c4bc933a1b
[schema hooks] rename variable, check unique constraint actually changed before creating the index
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
499 |
coltype = type_from_constraints(adbh, objtype, [newcstr], |
2019
399a930e10ef
#343488: SQL error in migration script (depends on a new release of yams and lgc)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2011
diff
changeset
|
500 |
creating=False) |
399a930e10ef
#343488: SQL error in migration script (depends on a new release of yams and lgc)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2011
diff
changeset
|
501 |
sql = adbh.sql_change_col_type(table, column, coltype, card != '1') |
0 | 502 |
try: |
2618
ff9b0d5bd884
[F repo sqlite schema changes] don't rollback on potentially expected schema changes failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2617
diff
changeset
|
503 |
session.system_sql(sql, rollback_on_failure=False) |
0 | 504 |
self.info('altered column %s of table %s: now VARCHAR(%s)', |
2697
a0c4bc933a1b
[schema hooks] rename variable, check unique constraint actually changed before creating the index
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
505 |
column, table, newcstr.max) |
0 | 506 |
except Exception, ex: |
507 |
# not supported by sqlite for instance |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
508 |
self.error('error while altering table %s: %s', table, ex) |
2697
a0c4bc933a1b
[schema hooks] rename variable, check unique constraint actually changed before creating the index
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
509 |
elif cstrtype == 'UniqueConstraint' and oldcstr is None: |
0 | 510 |
session.pool.source('system').create_index( |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
511 |
self.session, table, column, unique=True) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
512 |
|
0 | 513 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
514 |
class SourceDbCWConstraintDel(PreCommitOperation): |
0 | 515 |
"""actually remove a constraint of a relation definition""" |
1138
22f634977c95
make pylint happy, fix some bugs on the way
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
516 |
rtype = subjtype = objtype = None # make pylint happy |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
517 |
|
0 | 518 |
def precommit_event(self): |
519 |
cstrtype = self.cstr.type() |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
520 |
table = SQL_PREFIX + str(self.subjtype) |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
521 |
column = SQL_PREFIX + str(self.rtype) |
0 | 522 |
# alter the physical schema on size/unique constraint changes |
523 |
if cstrtype == 'SizeConstraint': |
|
524 |
try: |
|
525 |
self.session.system_sql('ALTER TABLE %s ALTER COLUMN %s TYPE TEXT' |
|
2618
ff9b0d5bd884
[F repo sqlite schema changes] don't rollback on potentially expected schema changes failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2617
diff
changeset
|
526 |
% (table, column), |
ff9b0d5bd884
[F repo sqlite schema changes] don't rollback on potentially expected schema changes failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2617
diff
changeset
|
527 |
rollback_on_failure=False) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
528 |
self.info('altered column %s of table %s: now TEXT', |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
529 |
column, table) |
0 | 530 |
except Exception, ex: |
531 |
# not supported by sqlite for instance |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
532 |
self.error('error while altering table %s: %s', table, ex) |
0 | 533 |
elif cstrtype == 'UniqueConstraint': |
534 |
self.session.pool.source('system').drop_index( |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
535 |
self.session, table, column, unique=True) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
536 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
537 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
538 |
# operations for in-memory schema synchronization ############################# |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
539 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
540 |
class MemSchemaCWETypeAdd(MemSchemaEarlyOperation): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
541 |
"""actually add the entity type to the instance's schema""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
542 |
eid = None # make pylint happy |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
543 |
def commit_event(self): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
544 |
self.schema.add_entity_type(self.kobj) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
545 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
546 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
547 |
class MemSchemaCWETypeRename(MemSchemaOperation): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
548 |
"""this operation updates physical storage accordingly""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
549 |
oldname = newname = None # make pylint happy |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
550 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
551 |
def commit_event(self): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
552 |
self.session.schema.rename_entity_type(self.oldname, self.newname) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
553 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
554 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
555 |
class MemSchemaCWETypeDel(MemSchemaOperation): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
556 |
"""actually remove the entity type from the instance's schema""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
557 |
def commit_event(self): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
558 |
try: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
559 |
# del_entity_type also removes entity's relations |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
560 |
self.schema.del_entity_type(self.kobj) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
561 |
except KeyError: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
562 |
# s/o entity type have already been deleted |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
563 |
pass |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
564 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
565 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
566 |
class MemSchemaCWRTypeAdd(MemSchemaEarlyOperation): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
567 |
"""actually add the relation type to the instance's schema""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
568 |
eid = None # make pylint happy |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
569 |
def commit_event(self): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
570 |
rschema = self.schema.add_relation_type(self.kobj) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
571 |
rschema.set_default_groups() |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
572 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
573 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
574 |
class MemSchemaCWRTypeUpdate(MemSchemaOperation): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
575 |
"""actually update some properties of a relation definition""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
576 |
rschema = values = None # make pylint happy |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
577 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
578 |
def commit_event(self): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
579 |
# structure should be clean, not need to remove entity's relations |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
580 |
# at this point |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
581 |
self.rschema.__dict__.update(self.values) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
582 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
583 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
584 |
class MemSchemaCWRTypeDel(MemSchemaOperation): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
585 |
"""actually remove the relation type from the instance's schema""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
586 |
def commit_event(self): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
587 |
try: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
588 |
self.schema.del_relation_type(self.kobj) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
589 |
except KeyError: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
590 |
# s/o entity type have already been deleted |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
591 |
pass |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
592 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
593 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
594 |
class MemSchemaRDefAdd(MemSchemaEarlyOperation): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
595 |
"""actually add the attribute relation definition to the instance's |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
596 |
schema |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
597 |
""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
598 |
def commit_event(self): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
599 |
self.schema.add_relation_def(self.kobj) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
600 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
601 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
602 |
class MemSchemaRDefUpdate(MemSchemaOperation): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
603 |
"""actually update some properties of a relation definition""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
604 |
rschema = values = None # make pylint happy |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
605 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
606 |
def commit_event(self): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
607 |
# structure should be clean, not need to remove entity's relations |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
608 |
# at this point |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
609 |
self.rschema._rproperties[self.kobj].update(self.values) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
610 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
611 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
612 |
class MemSchemaRDefDel(MemSchemaOperation): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
613 |
"""actually remove the relation definition from the instance's schema""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
614 |
def commit_event(self): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
615 |
subjtype, rtype, objtype = self.kobj |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
616 |
try: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
617 |
self.schema.del_relation_def(subjtype, rtype, objtype) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
618 |
except KeyError: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
619 |
# relation type may have been already deleted |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
620 |
pass |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
621 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
622 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
623 |
class MemSchemaCWConstraintAdd(MemSchemaOperation): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
624 |
"""actually update constraint of a relation definition |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
625 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
626 |
has to be called before SourceDbCWConstraintAdd |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
627 |
""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
628 |
cancelled = False |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
629 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
630 |
def precommit_event(self): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
631 |
rdef = self.entity.reverse_constrained_by[0] |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
632 |
# when the relation is added in the same transaction, the constraint |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
633 |
# object is created by the operation adding the attribute or relation, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
634 |
# so there is nothing to do here |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
635 |
if rdef.eid in self.session.transaction_data.get('neweids', ()): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
636 |
self.cancelled = True |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
637 |
return |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
638 |
subjtype, rtype, objtype = self.session.schema.schema_by_eid(rdef.eid) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
639 |
self.prepare_constraints(subjtype, rtype, objtype) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
640 |
cstrtype = self.entity.type |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
641 |
self.cstr = rtype.constraint_by_type(subjtype, objtype, cstrtype) |
2697
a0c4bc933a1b
[schema hooks] rename variable, check unique constraint actually changed before creating the index
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
642 |
self.newcstr = CONSTRAINTS[cstrtype].deserialize(self.entity.value) |
a0c4bc933a1b
[schema hooks] rename variable, check unique constraint actually changed before creating the index
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
643 |
self.newcstr.eid = self.entity.eid |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
644 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
645 |
def commit_event(self): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
646 |
if self.cancelled: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
647 |
return |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
648 |
# in-place modification |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
649 |
if not self.cstr is None: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
650 |
self.constraints.remove(self.cstr) |
2697
a0c4bc933a1b
[schema hooks] rename variable, check unique constraint actually changed before creating the index
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
651 |
self.constraints.append(self.newcstr) |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
652 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
653 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
654 |
class MemSchemaCWConstraintDel(MemSchemaOperation): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
655 |
"""actually remove a constraint of a relation definition |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
656 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
657 |
has to be called before SourceDbCWConstraintDel |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
658 |
""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
659 |
rtype = subjtype = objtype = None # make pylint happy |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
660 |
def precommit_event(self): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
661 |
self.prepare_constraints(self.subjtype, self.rtype, self.objtype) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
662 |
|
0 | 663 |
def commit_event(self): |
664 |
self.constraints.remove(self.cstr) |
|
665 |
||
666 |
||
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
667 |
class MemSchemaPermissionCWGroupAdd(MemSchemaPermissionOperation): |
0 | 668 |
"""synchronize schema when a *_permission relation has been added on a group |
669 |
""" |
|
670 |
def __init__(self, session, perm, etype_eid, group_eid): |
|
3869
ec6463886ac4
[server] remove not-so-useful entity_name and entity_attr functions, introduce entity_oldnewvalue
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3774
diff
changeset
|
671 |
self.group = session.entity_from_eid(group_eid).name |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
672 |
super(MemSchemaPermissionCWGroupAdd, self).__init__( |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
673 |
session, perm, etype_eid) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
674 |
|
0 | 675 |
def commit_event(self): |
676 |
"""the observed connections pool has been commited""" |
|
677 |
try: |
|
678 |
erschema = self.schema[self.name] |
|
679 |
except KeyError: |
|
680 |
# duh, schema not found, log error and skip operation |
|
681 |
self.error('no schema for %s', self.name) |
|
682 |
return |
|
683 |
groups = list(erschema.get_groups(self.perm)) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
684 |
try: |
0 | 685 |
groups.index(self.group) |
686 |
self.warning('group %s already have permission %s on %s', |
|
687 |
self.group, self.perm, erschema.type) |
|
688 |
except ValueError: |
|
689 |
groups.append(self.group) |
|
690 |
erschema.set_groups(self.perm, groups) |
|
691 |
||
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
692 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
693 |
class MemSchemaPermissionCWGroupDel(MemSchemaPermissionCWGroupAdd): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
694 |
"""synchronize schema when a *_permission relation has been deleted from a |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
695 |
group |
0 | 696 |
""" |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
697 |
|
0 | 698 |
def commit_event(self): |
699 |
"""the observed connections pool has been commited""" |
|
700 |
try: |
|
701 |
erschema = self.schema[self.name] |
|
702 |
except KeyError: |
|
703 |
# duh, schema not found, log error and skip operation |
|
704 |
self.error('no schema for %s', self.name) |
|
705 |
return |
|
706 |
groups = list(erschema.get_groups(self.perm)) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
707 |
try: |
0 | 708 |
groups.remove(self.group) |
709 |
erschema.set_groups(self.perm, groups) |
|
710 |
except ValueError: |
|
711 |
self.error('can\'t remove permission %s on %s to group %s', |
|
712 |
self.perm, erschema.type, self.group) |
|
713 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
714 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
715 |
class MemSchemaPermissionRQLExpressionAdd(MemSchemaPermissionOperation): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
716 |
"""synchronize schema when a *_permission relation has been added on a rql |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
717 |
expression |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
718 |
""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
719 |
def __init__(self, session, perm, etype_eid, expression): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
720 |
self.expr = expression |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
721 |
super(MemSchemaPermissionRQLExpressionAdd, self).__init__( |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
722 |
session, perm, etype_eid) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
723 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
724 |
def commit_event(self): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
725 |
"""the observed connections pool has been commited""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
726 |
try: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
727 |
erschema = self.schema[self.name] |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
728 |
except KeyError: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
729 |
# duh, schema not found, log error and skip operation |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
730 |
self.error('no schema for %s', self.name) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
731 |
return |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
732 |
exprs = list(erschema.get_rqlexprs(self.perm)) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
733 |
exprs.append(erschema.rql_expression(self.expr)) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
734 |
erschema.set_rqlexprs(self.perm, exprs) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
735 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
736 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
737 |
class MemSchemaPermissionRQLExpressionDel(MemSchemaPermissionRQLExpressionAdd): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
738 |
"""synchronize schema when a *_permission relation has been deleted from an |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
739 |
rql expression |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
740 |
""" |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
741 |
|
0 | 742 |
def commit_event(self): |
743 |
"""the observed connections pool has been commited""" |
|
744 |
try: |
|
745 |
erschema = self.schema[self.name] |
|
746 |
except KeyError: |
|
747 |
# duh, schema not found, log error and skip operation |
|
748 |
self.error('no schema for %s', self.name) |
|
749 |
return |
|
750 |
rqlexprs = list(erschema.get_rqlexprs(self.perm)) |
|
751 |
for i, rqlexpr in enumerate(rqlexprs): |
|
752 |
if rqlexpr.expression == self.expr: |
|
753 |
rqlexprs.pop(i) |
|
754 |
break |
|
755 |
else: |
|
756 |
self.error('can\'t remove permission %s on %s for expression %s', |
|
757 |
self.perm, erschema.type, self.expr) |
|
758 |
return |
|
759 |
erschema.set_rqlexprs(self.perm, rqlexprs) |
|
760 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
761 |
|
2963
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
762 |
class MemSchemaSpecializesAdd(MemSchemaOperation): |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
763 |
|
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
764 |
def commit_event(self): |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
765 |
eschema = self.session.schema.schema_by_eid(self.etypeeid) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
766 |
parenteschema = self.session.schema.schema_by_eid(self.parentetypeeid) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
767 |
eschema._specialized_type = parenteschema.type |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
768 |
parenteschema._specialized_by.append(eschema.type) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
769 |
|
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
770 |
|
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
771 |
class MemSchemaSpecializesDel(MemSchemaOperation): |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
772 |
|
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
773 |
def commit_event(self): |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
774 |
try: |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
775 |
eschema = self.session.schema.schema_by_eid(self.etypeeid) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
776 |
parenteschema = self.session.schema.schema_by_eid(self.parentetypeeid) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
777 |
except KeyError: |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
778 |
# etype removed, nothing to do |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
779 |
return |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
780 |
eschema._specialized_type = None |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
781 |
parenteschema._specialized_by.remove(eschema.type) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
782 |
|
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
783 |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
784 |
# deletion hooks ############################################################### |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
785 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
786 |
def before_del_eetype(session, eid): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
787 |
"""before deleting a CWEType entity: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
788 |
* check that we don't remove a core entity type |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
789 |
* cascade to delete related CWAttribute and CWRelation entities |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
790 |
* instantiate an operation to delete the entity type on commit |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
791 |
""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
792 |
# final entities can't be deleted, don't care about that |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
793 |
name = check_internal_entity(session, eid, CORE_ETYPES) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
794 |
# delete every entities of this type |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
795 |
session.unsafe_execute('DELETE %s X' % name) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
796 |
DropTable(session, table=SQL_PREFIX + name) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
797 |
MemSchemaCWETypeDel(session, name) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
798 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
799 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
800 |
def after_del_eetype(session, eid): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
801 |
# workflow cleanup |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
802 |
session.execute('DELETE Workflow X WHERE NOT X workflow_of Y') |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
803 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
804 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
805 |
def before_del_ertype(session, eid): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
806 |
"""before deleting a CWRType entity: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
807 |
* check that we don't remove a core relation type |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
808 |
* cascade to delete related CWAttribute and CWRelation entities |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
809 |
* instantiate an operation to delete the relation type on commit |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
810 |
""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
811 |
name = check_internal_entity(session, eid, CORE_RTYPES) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
812 |
# delete relation definitions using this relation type |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
813 |
session.execute('DELETE CWAttribute X WHERE X relation_type Y, Y eid %(x)s', |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
814 |
{'x': eid}) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
815 |
session.execute('DELETE CWRelation X WHERE X relation_type Y, Y eid %(x)s', |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
816 |
{'x': eid}) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
817 |
MemSchemaCWRTypeDel(session, name) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
818 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
819 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
820 |
def after_del_relation_type(session, rdefeid, rtype, rteid): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
821 |
"""before deleting a CWAttribute or CWRelation entity: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
822 |
* if this is a final or inlined relation definition, instantiate an |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
823 |
operation to drop necessary column, else if this is the last instance |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
824 |
of a non final relation, instantiate an operation to drop necessary |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
825 |
table |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
826 |
* instantiate an operation to delete the relation definition on commit |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
827 |
* delete the associated relation type when necessary |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
828 |
""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
829 |
subjschema, rschema, objschema = session.schema.schema_by_eid(rdefeid) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
830 |
pendings = session.transaction_data.get('pendingeids', ()) |
3546
f0aecddf367e
fix bug when renaming a full text indexed attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3543
diff
changeset
|
831 |
pendingrdefs = session.transaction_data.setdefault('pendingrdefs', set()) |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
832 |
# first delete existing relation if necessary |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3550
diff
changeset
|
833 |
if rschema.final: |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
834 |
rdeftype = 'CWAttribute' |
3546
f0aecddf367e
fix bug when renaming a full text indexed attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3543
diff
changeset
|
835 |
pendingrdefs.add((subjschema, rschema)) |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
836 |
else: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
837 |
rdeftype = 'CWRelation' |
3546
f0aecddf367e
fix bug when renaming a full text indexed attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3543
diff
changeset
|
838 |
pendingrdefs.add((subjschema, rschema, objschema)) |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
839 |
if not (subjschema.eid in pendings or objschema.eid in pendings): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
840 |
session.execute('DELETE X %s Y WHERE X is %s, Y is %s' |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
841 |
% (rschema, subjschema, objschema)) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
842 |
execute = session.unsafe_execute |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
843 |
rset = execute('Any COUNT(X) WHERE X is %s, X relation_type R,' |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
844 |
'R eid %%(x)s' % rdeftype, {'x': rteid}) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
845 |
lastrel = rset[0][0] == 0 |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
846 |
# we have to update physical schema systematically for final and inlined |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
847 |
# relations, but only if it's the last instance for this relation type |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
848 |
# for other relations |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
849 |
|
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3550
diff
changeset
|
850 |
if (rschema.final or rschema.inlined): |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
851 |
rset = execute('Any COUNT(X) WHERE X is %s, X relation_type R, ' |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
852 |
'R eid %%(x)s, X from_entity E, E name %%(name)s' |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
853 |
% rdeftype, {'x': rteid, 'name': str(subjschema)}) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
854 |
if rset[0][0] == 0 and not subjschema.eid in pendings: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
855 |
ptypes = session.transaction_data.setdefault('pendingrtypes', set()) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
856 |
ptypes.add(rschema.type) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
857 |
DropColumn(session, table=SQL_PREFIX + subjschema.type, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
858 |
column=SQL_PREFIX + rschema.type) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
859 |
elif lastrel: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
860 |
DropRelationTable(session, rschema.type) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
861 |
# if this is the last instance, drop associated relation type |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
862 |
if lastrel and not rteid in pendings: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
863 |
execute('DELETE CWRType X WHERE X eid %(x)s', {'x': rteid}, 'x') |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
864 |
MemSchemaRDefDel(session, (subjschema, rschema, objschema)) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
865 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
866 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
867 |
# addition hooks ############################################################### |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
868 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
869 |
def before_add_eetype(session, entity): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
870 |
"""before adding a CWEType entity: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
871 |
* check that we are not using an existing entity type, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
872 |
""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
873 |
name = entity['name'] |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
874 |
schema = session.schema |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
875 |
if name in schema and schema[name].eid is not None: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
876 |
raise RepositoryError('an entity type %s already exists' % name) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
877 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
878 |
def after_add_eetype(session, entity): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
879 |
"""after adding a CWEType entity: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
880 |
* create the necessary table |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
881 |
* set creation_date and modification_date by creating the necessary |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
882 |
CWAttribute entities |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
883 |
* add owned_by relation by creating the necessary CWRelation entity |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
884 |
* register an operation to add the entity type to the instance's |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
885 |
schema on commit |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
886 |
""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
887 |
if entity.get('final'): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
888 |
return |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
889 |
schema = session.schema |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
890 |
name = entity['name'] |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
891 |
etype = EntityType(name=name, description=entity.get('description'), |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
892 |
meta=entity.get('meta')) # don't care about final |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
893 |
# fake we add it to the schema now to get a correctly initialized schema |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
894 |
# but remove it before doing anything more dangerous... |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
895 |
schema = session.schema |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
896 |
eschema = schema.add_entity_type(etype) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
897 |
eschema.set_default_groups() |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
898 |
# generate table sql and rql to add metadata |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
899 |
tablesql = eschema2sql(session.pool.source('system').dbhelper, eschema, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
900 |
prefix=SQL_PREFIX) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
901 |
relrqls = [] |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
902 |
for rtype in (META_RTYPES - VIRTUAL_RTYPES): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
903 |
rschema = schema[rtype] |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
904 |
sampletype = rschema.subjects()[0] |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
905 |
desttype = rschema.objects()[0] |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
906 |
props = rschema.rproperties(sampletype, desttype) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
907 |
relrqls += list(ss.rdef2rql(rschema, name, desttype, props)) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
908 |
# now remove it ! |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
909 |
schema.del_entity_type(name) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
910 |
# create the necessary table |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
911 |
for sql in tablesql.split(';'): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
912 |
if sql.strip(): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
913 |
session.system_sql(sql) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
914 |
# register operation to modify the schema on commit |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
915 |
# this have to be done before adding other relations definitions |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
916 |
# or permission settings |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
917 |
etype.eid = entity.eid |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
918 |
MemSchemaCWETypeAdd(session, etype) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
919 |
# add meta relations |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
920 |
for rql, kwargs in relrqls: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
921 |
session.execute(rql, kwargs) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
922 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
923 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
924 |
def before_add_ertype(session, entity): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
925 |
"""before adding a CWRType entity: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
926 |
* check that we are not using an existing relation type, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
927 |
* register an operation to add the relation type to the instance's |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
928 |
schema on commit |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
929 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
930 |
We don't know yeat this point if a table is necessary |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
931 |
""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
932 |
name = entity['name'] |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
933 |
if name in session.schema.relations(): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
934 |
raise RepositoryError('a relation type %s already exists' % name) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
935 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
936 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
937 |
def after_add_ertype(session, entity): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
938 |
"""after a CWRType entity has been added: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
939 |
* register an operation to add the relation type to the instance's |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
940 |
schema on commit |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
941 |
We don't know yeat this point if a table is necessary |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
942 |
""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
943 |
rtype = RelationType(name=entity['name'], |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
944 |
description=entity.get('description'), |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
945 |
meta=entity.get('meta', False), |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
946 |
inlined=entity.get('inlined', False), |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
947 |
symetric=entity.get('symetric', False)) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
948 |
rtype.eid = entity.eid |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
949 |
MemSchemaCWRTypeAdd(session, rtype) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
950 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
951 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
952 |
def after_add_efrdef(session, entity): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
953 |
SourceDbCWAttributeAdd(session, entity=entity) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
954 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
955 |
def after_add_enfrdef(session, entity): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
956 |
SourceDbCWRelationAdd(session, entity=entity) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
957 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
958 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
959 |
# update hooks ################################################################# |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
960 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
961 |
def check_valid_changes(session, entity, ro_attrs=('name', 'final')): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
962 |
errors = {} |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
963 |
# don't use getattr(entity, attr), we would get the modified value if any |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
964 |
for attr in ro_attrs: |
3869
ec6463886ac4
[server] remove not-so-useful entity_name and entity_attr functions, introduce entity_oldnewvalue
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3774
diff
changeset
|
965 |
if attr in entity.edited_attributes: |
3881 | 966 |
origval, newval = entity_oldnewvalue(entity, attr) |
3869
ec6463886ac4
[server] remove not-so-useful entity_name and entity_attr functions, introduce entity_oldnewvalue
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3774
diff
changeset
|
967 |
if newval != origval: |
ec6463886ac4
[server] remove not-so-useful entity_name and entity_attr functions, introduce entity_oldnewvalue
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3774
diff
changeset
|
968 |
errors[attr] = session._("can't change the %s attribute") % \ |
ec6463886ac4
[server] remove not-so-useful entity_name and entity_attr functions, introduce entity_oldnewvalue
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3774
diff
changeset
|
969 |
display_name(session, attr) |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
970 |
if errors: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
971 |
raise ValidationError(entity.eid, errors) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
972 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
973 |
def before_update_eetype(session, entity): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
974 |
"""check name change, handle final""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
975 |
check_valid_changes(session, entity, ro_attrs=('final',)) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
976 |
# don't use getattr(entity, attr), we would get the modified value if any |
4129
887e3edc30c5
check name changed first
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3881
diff
changeset
|
977 |
if 'name' in entity.edited_attributes: |
887e3edc30c5
check name changed first
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3881
diff
changeset
|
978 |
oldname, newname = entity_oldnewvalue(entity, 'name') |
887e3edc30c5
check name changed first
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3881
diff
changeset
|
979 |
if newname.lower() != oldname.lower(): |
887e3edc30c5
check name changed first
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3881
diff
changeset
|
980 |
SourceDbCWETypeRename(session, oldname=oldname, newname=newname) |
887e3edc30c5
check name changed first
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3881
diff
changeset
|
981 |
MemSchemaCWETypeRename(session, oldname=oldname, newname=newname) |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
982 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
983 |
def before_update_ertype(session, entity): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
984 |
"""check name change, handle final""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
985 |
check_valid_changes(session, entity) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
986 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
987 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
988 |
def after_update_erdef(session, entity): |
2740
7ab70fad02df
[schema changes] check entity is not being deleted and get only actually modified attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2697
diff
changeset
|
989 |
if entity.eid in session.transaction_data.get('pendingeids', ()): |
7ab70fad02df
[schema changes] check entity is not being deleted and get only actually modified attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2697
diff
changeset
|
990 |
return |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
991 |
desttype = entity.otype.name |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
992 |
rschema = session.schema[entity.rtype.name] |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
993 |
newvalues = {} |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
994 |
for prop in rschema.rproperty_defs(desttype): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
995 |
if prop == 'constraints': |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
996 |
continue |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
997 |
if prop == 'order': |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
998 |
prop = 'ordernum' |
2740
7ab70fad02df
[schema changes] check entity is not being deleted and get only actually modified attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2697
diff
changeset
|
999 |
if prop in entity.edited_attributes: |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1000 |
newvalues[prop] = entity[prop] |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1001 |
if newvalues: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1002 |
subjtype = entity.stype.name |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1003 |
MemSchemaRDefUpdate(session, kobj=(subjtype, desttype), |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1004 |
rschema=rschema, values=newvalues) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1005 |
SourceDbRDefUpdate(session, kobj=(subjtype, desttype), |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1006 |
rschema=rschema, values=newvalues) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1007 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1008 |
def after_update_ertype(session, entity): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1009 |
rschema = session.schema.rschema(entity.name) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1010 |
newvalues = {} |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1011 |
for prop in ('meta', 'symetric', 'inlined'): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1012 |
if prop in entity: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1013 |
newvalues[prop] = entity[prop] |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1014 |
if newvalues: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1015 |
MemSchemaCWRTypeUpdate(session, rschema=rschema, values=newvalues) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1016 |
SourceDbCWRTypeUpdate(session, rschema=rschema, values=newvalues, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1017 |
entity=entity) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1018 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1019 |
# constraints synchronization hooks ############################################ |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1020 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1021 |
def after_add_econstraint(session, entity): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1022 |
MemSchemaCWConstraintAdd(session, entity=entity) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1023 |
SourceDbCWConstraintAdd(session, entity=entity) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1024 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1025 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1026 |
def after_update_econstraint(session, entity): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1027 |
MemSchemaCWConstraintAdd(session, entity=entity) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1028 |
SourceDbCWConstraintAdd(session, entity=entity) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1029 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1030 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1031 |
def before_delete_constrained_by(session, fromeid, rtype, toeid): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1032 |
if not fromeid in session.transaction_data.get('pendingeids', ()): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1033 |
schema = session.schema |
2680
66472d85d548
[R] use req.entity_from_eid
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2641
diff
changeset
|
1034 |
entity = session.entity_from_eid(toeid) |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1035 |
subjtype, rtype, objtype = schema.schema_by_eid(fromeid) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1036 |
try: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1037 |
cstr = rtype.constraint_by_type(subjtype, objtype, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1038 |
entity.cstrtype[0].name) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1039 |
except IndexError: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1040 |
session.critical('constraint type no more accessible') |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1041 |
else: |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1042 |
SourceDbCWConstraintDel(session, subjtype=subjtype, rtype=rtype, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1043 |
objtype=objtype, cstr=cstr) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1044 |
MemSchemaCWConstraintDel(session, subjtype=subjtype, rtype=rtype, |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1045 |
objtype=objtype, cstr=cstr) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1046 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1047 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1048 |
def after_add_constrained_by(session, fromeid, rtype, toeid): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1049 |
if fromeid in session.transaction_data.get('neweids', ()): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1050 |
session.transaction_data.setdefault(fromeid, []).append(toeid) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1051 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1052 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1053 |
# permissions synchronization hooks ############################################ |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1054 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1055 |
def after_add_permission(session, subject, rtype, object): |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1056 |
"""added entity/relation *_permission, need to update schema""" |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1057 |
perm = rtype.split('_', 1)[0] |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1058 |
if session.describe(object)[0] == 'CWGroup': |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1059 |
MemSchemaPermissionCWGroupAdd(session, perm, subject, object) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1060 |
else: # RQLExpression |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1061 |
expr = session.execute('Any EXPR WHERE X eid %(x)s, X expression EXPR', |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1062 |
{'x': object}, 'x')[0][0] |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1063 |
MemSchemaPermissionRQLExpressionAdd(session, perm, subject, expr) |
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1064 |
|
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1065 |
|
0 | 1066 |
def before_del_permission(session, subject, rtype, object): |
1067 |
"""delete entity/relation *_permission, need to update schema |
|
1068 |
||
1069 |
skip the operation if the related type is being deleted |
|
1070 |
""" |
|
2101
08003e0354a7
update transaction data api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2056
diff
changeset
|
1071 |
if subject in session.transaction_data.get('pendingeids', ()): |
0 | 1072 |
return |
1073 |
perm = rtype.split('_', 1)[0] |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1074 |
if session.describe(object)[0] == 'CWGroup': |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1075 |
MemSchemaPermissionCWGroupDel(session, perm, subject, object) |
0 | 1076 |
else: # RQLExpression |
1077 |
expr = session.execute('Any EXPR WHERE X eid %(x)s, X expression EXPR', |
|
1078 |
{'x': object}, 'x')[0][0] |
|
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2624
diff
changeset
|
1079 |
MemSchemaPermissionRQLExpressionDel(session, perm, subject, expr) |
0 | 1080 |
|
1081 |
||
2963
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
1082 |
def after_add_specializes(session, subject, rtype, object): |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
1083 |
MemSchemaSpecializesAdd(session, etypeeid=subject, parentetypeeid=object) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
1084 |
|
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
1085 |
def after_del_specializes(session, subject, rtype, object): |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
1086 |
MemSchemaSpecializesDel(session, etypeeid=subject, parentetypeeid=object) |
0 | 1087 |
|
1088 |
||
1089 |
def _register_schema_hooks(hm): |
|
1090 |
"""register schema related hooks on the hooks manager""" |
|
1091 |
# schema synchronisation ##################### |
|
1092 |
# before/after add |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1093 |
hm.register_hook(before_add_eetype, 'before_add_entity', 'CWEType') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1094 |
hm.register_hook(before_add_ertype, 'before_add_entity', 'CWRType') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1095 |
hm.register_hook(after_add_eetype, 'after_add_entity', 'CWEType') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1096 |
hm.register_hook(after_add_ertype, 'after_add_entity', 'CWRType') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1097 |
hm.register_hook(after_add_efrdef, 'after_add_entity', 'CWAttribute') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1098 |
hm.register_hook(after_add_enfrdef, 'after_add_entity', 'CWRelation') |
0 | 1099 |
# before/after update |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1100 |
hm.register_hook(before_update_eetype, 'before_update_entity', 'CWEType') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1101 |
hm.register_hook(before_update_ertype, 'before_update_entity', 'CWRType') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1102 |
hm.register_hook(after_update_ertype, 'after_update_entity', 'CWRType') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1103 |
hm.register_hook(after_update_erdef, 'after_update_entity', 'CWAttribute') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1104 |
hm.register_hook(after_update_erdef, 'after_update_entity', 'CWRelation') |
0 | 1105 |
# before/after delete |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1106 |
hm.register_hook(before_del_eetype, 'before_delete_entity', 'CWEType') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1107 |
hm.register_hook(after_del_eetype, 'after_delete_entity', 'CWEType') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1108 |
hm.register_hook(before_del_ertype, 'before_delete_entity', 'CWRType') |
0 | 1109 |
hm.register_hook(after_del_relation_type, 'after_delete_relation', 'relation_type') |
2963
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
1110 |
hm.register_hook(after_add_specializes, 'after_add_relation', 'specializes') |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
1111 |
hm.register_hook(after_del_specializes, 'after_delete_relation', 'specializes') |
0 | 1112 |
# constraints synchronization hooks |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1113 |
hm.register_hook(after_add_econstraint, 'after_add_entity', 'CWConstraint') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1114 |
hm.register_hook(after_update_econstraint, 'after_update_entity', 'CWConstraint') |
0 | 1115 |
hm.register_hook(before_delete_constrained_by, 'before_delete_relation', 'constrained_by') |
1116 |
hm.register_hook(after_add_constrained_by, 'after_add_relation', 'constrained_by') |
|
1117 |
# permissions synchronisation ################ |
|
1118 |
for perm in ('read_permission', 'add_permission', |
|
1119 |
'delete_permission', 'update_permission'): |
|
1120 |
hm.register_hook(after_add_permission, 'after_add_relation', perm) |
|
1121 |
hm.register_hook(before_del_permission, 'before_delete_relation', perm) |