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