201 print '-> database for instance %s initialized.' % config.appid |
201 print '-> database for instance %s initialized.' % config.appid |
202 |
202 |
203 |
203 |
204 def initialize_schema(config, schema, mhandler, event='create'): |
204 def initialize_schema(config, schema, mhandler, event='create'): |
205 from cubicweb.server.schemaserial import serialize_schema |
205 from cubicweb.server.schemaserial import serialize_schema |
|
206 # deactivate every hooks but those responsible to set metadata |
|
207 # so, NO INTEGRITY CHECKS are done, to have quicker db creation |
|
208 oldmode = config.set_hooks_mode(config.DENY_ALL) |
|
209 changes = config.enable_hook_category('metadata') |
206 paths = [p for p in config.cubes_path() + [config.apphome] |
210 paths = [p for p in config.cubes_path() + [config.apphome] |
207 if exists(join(p, 'migration'))] |
211 if exists(join(p, 'migration'))] |
208 # execute cubicweb's pre<event> script |
212 # execute cubicweb's pre<event> script |
209 mhandler.exec_event_script('pre%s' % event) |
213 mhandler.exec_event_script('pre%s' % event) |
210 # execute cubes pre<event> script if any |
214 # execute cubes pre<event> script if any |
211 for path in reversed(paths): |
215 for path in reversed(paths): |
212 mhandler.exec_event_script('pre%s' % event, path) |
216 mhandler.exec_event_script('pre%s' % event, path) |
213 # enter instance'schema into the database |
217 # enter instance'schema into the database |
214 mhandler.session.set_pool() |
218 mhandler.session.set_pool() |
215 config.disabled_hooks_categories.add('syncschema') |
|
216 serialize_schema(mhandler.session, schema) |
219 serialize_schema(mhandler.session, schema) |
217 config.disabled_hooks_categories.remove('syncschema') |
|
218 # execute cubicweb's post<event> script |
220 # execute cubicweb's post<event> script |
219 mhandler.exec_event_script('post%s' % event) |
221 mhandler.exec_event_script('post%s' % event) |
220 # execute cubes'post<event> script if any |
222 # execute cubes'post<event> script if any |
221 for path in reversed(paths): |
223 for path in reversed(paths): |
222 mhandler.exec_event_script('post%s' % event, path) |
224 mhandler.exec_event_script('post%s' % event, path) |
|
225 # restore hooks config |
|
226 if changes: |
|
227 config.disable_hook_category(changes) |
|
228 config.set_hooks_mode(oldmode) |
223 |
229 |
224 |
230 |
225 # sqlite'stored procedures have to be registered at connexion opening time |
231 # sqlite'stored procedures have to be registered at connexion opening time |
226 SQL_CONNECT_HOOKS = {} |
232 SQL_CONNECT_HOOKS = {} |
227 |
233 |