180 |
180 |
181 * `option_added(oldname, newname)`, indicates that an option has been added. |
181 * `option_added(oldname, newname)`, indicates that an option has been added. |
182 |
182 |
183 * `option_removed(oldname, newname)`, indicates that an option has been deleted. |
183 * `option_removed(oldname, newname)`, indicates that an option has been deleted. |
184 |
184 |
|
185 The `config` variable is an object which can be used to access the |
|
186 configuration values, for reading and updating, with a dictionary-like |
|
187 syntax. |
|
188 |
|
189 Example 1: migration script changing the variable 'sender-addr' in |
|
190 all-in-one.conf. The script also checks that in that the instance is |
|
191 configured with a known value for that variable, and only updates the |
|
192 value in that case. |
|
193 |
|
194 .. sourcecode:: python |
|
195 |
|
196 wrong_addr = 'cubicweb@loiglab.fr' # known wrong address |
|
197 fixed_addr = 'cubicweb@logilab.fr' |
|
198 configured_addr = config.get('sender-addr') |
|
199 # check that the address has not been hand fixed by a sysadmin |
|
200 if configured_addr == wrong_addr: |
|
201 config['sender-addr'] = fixed-addr |
|
202 config.save() |
|
203 |
|
204 Example 2: checking the value of the database backend driver, which |
|
205 can be useful in case you need to issue backend-dependent raw SQL |
|
206 queries in a migration script. |
|
207 |
|
208 .. sourcecode:: python |
|
209 |
|
210 dbdriver = config.sources()['system']['db-driver'] |
|
211 if dbdriver == "sqlserver2005": |
|
212 # this is now correctly handled by CW :-) |
|
213 sql('ALTER TABLE cw_Xxxx ALTER COLUMN cw_name varchar(64) NOT NULL;') |
|
214 commit() |
|
215 else: # postgresql |
|
216 sync_schema_props_perms(ertype=('Xxxx', 'name', 'String'), |
|
217 syncperms=False) |
|
218 |
185 |
219 |
186 Others migration functions |
220 Others migration functions |
187 -------------------------- |
221 -------------------------- |
188 Those functions are only used for low level operations that could not be |
222 Those functions are only used for low level operations that could not be |
189 accomplished otherwise or to repair damaged databases during interactive |
223 accomplished otherwise or to repair damaged databases during interactive |