209 repo.vreg.set_schema(repo.schema) |
209 repo.vreg.set_schema(repo.schema) |
210 assert len(repo.sources) == 1, repo.sources |
210 assert len(repo.sources) == 1, repo.sources |
211 handler = config.migration_handler(schema, interactive=False, |
211 handler = config.migration_handler(schema, interactive=False, |
212 cnx=cnx, repo=repo) |
212 cnx=cnx, repo=repo) |
213 # install additional driver specific sql files |
213 # install additional driver specific sql files |
214 handler.install_custom_sql_scripts(join(CW_SOFTWARE_ROOT, 'schemas'), driver) |
214 handler.cmd_install_custom_sql_scripts() |
215 for directory in reversed(config.cubes_path()): |
215 for cube in reversed(config.cubes()): |
216 handler.install_custom_sql_scripts(join(directory, 'schema'), driver) |
216 handler.cmd_install_custom_sql_scripts(cube) |
217 # serialize the schema |
217 # serialize the schema |
218 initialize_schema(config, schema, handler) |
218 initialize_schema(config, schema, handler) |
219 # yoo ! |
219 # yoo ! |
220 cnx.commit() |
220 cnx.commit() |
221 repo.system_source.init_creating() |
221 repo.system_source.init_creating() |
230 |
230 |
231 def initialize_schema(config, schema, mhandler, event='create'): |
231 def initialize_schema(config, schema, mhandler, event='create'): |
232 from cubicweb.server.schemaserial import serialize_schema |
232 from cubicweb.server.schemaserial import serialize_schema |
233 from cubicweb.server.session import hooks_control |
233 from cubicweb.server.session import hooks_control |
234 session = mhandler.session |
234 session = mhandler.session |
235 paths = [p for p in config.cubes_path() + [config.apphome] |
235 cubes = config.cubes() |
236 if exists(join(p, 'migration'))] |
|
237 # deactivate every hooks but those responsible to set metadata |
236 # deactivate every hooks but those responsible to set metadata |
238 # so, NO INTEGRITY CHECKS are done, to have quicker db creation. |
237 # so, NO INTEGRITY CHECKS are done, to have quicker db creation. |
239 # Active integrity is kept else we may pb such as two default |
238 # Active integrity is kept else we may pb such as two default |
240 # workflows for one entity type. |
239 # workflows for one entity type. |
241 with hooks_control(session, session.HOOKS_DENY_ALL, 'metadata', |
240 with hooks_control(session, session.HOOKS_DENY_ALL, 'metadata', |
242 'activeintegrity'): |
241 'activeintegrity'): |
243 # execute cubicweb's pre<event> script |
242 # execute cubicweb's pre<event> script |
244 mhandler.exec_event_script('pre%s' % event) |
243 mhandler.cmd_exec_event_script('pre%s' % event) |
245 # execute cubes pre<event> script if any |
244 # execute cubes pre<event> script if any |
246 for path in reversed(paths): |
245 for cube in reversed(cubes): |
247 mhandler.exec_event_script('pre%s' % event, path) |
246 mhandler.cmd_exec_event_script('pre%s' % event, cube) |
248 # enter instance'schema into the database |
247 # enter instance'schema into the database |
249 session.set_cnxset() |
248 session.set_cnxset() |
250 serialize_schema(session, schema) |
249 serialize_schema(session, schema) |
251 # execute cubicweb's post<event> script |
250 # execute cubicweb's post<event> script |
252 mhandler.exec_event_script('post%s' % event) |
251 mhandler.cmd_exec_event_script('post%s' % event) |
253 # execute cubes'post<event> script if any |
252 # execute cubes'post<event> script if any |
254 for path in reversed(paths): |
253 for cube in reversed(cubes): |
255 mhandler.exec_event_script('post%s' % event, path) |
254 mhandler.cmd_exec_event_script('post%s' % event, cube) |
256 |
255 |
257 |
256 |
258 # sqlite'stored procedures have to be registered at connection opening time |
257 # sqlite'stored procedures have to be registered at connection opening time |
259 from logilab.database import SQL_CONNECT_HOOKS |
258 from logilab.database import SQL_CONNECT_HOOKS |
260 |
259 |