# HG changeset patch # User Sylvain Thénault # Date 1258996400 -3600 # Node ID 7967d3766ecf2da6c7d02def53d3ef08928ee1b9 # Parent a0efb0326021f5e0c75f1981925733375916697d fix #544758 by calling custom sql scripts in add_cubes. Refactor to benefit from code of db initialization on the migration handler. diff -r a0efb0326021 -r 7967d3766ecf server/__init__.py --- a/server/__init__.py Mon Nov 23 17:13:48 2009 +0100 +++ b/server/__init__.py Mon Nov 23 18:13:20 2009 +0100 @@ -143,14 +143,6 @@ #skip_entities=[str(e) for e in schema.entities() # if not repo.system_source.support_entity(str(e))]) sqlexec(schemasql, execute, pbtitle=_title) - # install additional driver specific sql files - for fpath in glob(join(CW_SOFTWARE_ROOT, 'schemas', '*.sql.%s' % driver)): - print '-> installing', fpath - sqlexec(open(fpath).read(), execute, False, delimiter=';;') - for directory in reversed(config.cubes_path()): - for fpath in glob(join(directory, 'schema', '*.sql.%s' % driver)): - print '-> installing', fpath - sqlexec(open(fpath).read(), execute, False, delimiter=';;') sqlcursor.close() sqlcnx.commit() sqlcnx.close() @@ -183,6 +175,10 @@ assert len(repo.sources) == 1, repo.sources handler = config.migration_handler(schema, interactive=False, cnx=cnx, repo=repo) + # install additional driver specific sql files + handler.install_custom_sql_scripts(join(CW_SOFTWARE_ROOT, 'schemas'), driver) + for directory in reversed(config.cubes_path()): + handler.install_custom_sql_scripts(join(directory, 'schema'), driver) initialize_schema(config, schema, handler) # yoo ! cnx.commit() diff -r a0efb0326021 -r 7967d3766ecf server/migractions.py --- a/server/migractions.py Mon Nov 23 17:13:48 2009 +0100 +++ b/server/migractions.py Mon Nov 23 18:13:20 2009 +0100 @@ -24,6 +24,8 @@ import shutil import os.path as osp from datetime import datetime +from glob import glob +from warnings import warn from logilab.common.deprecation import deprecated from logilab.common.decorators import cached, clear_cache @@ -308,6 +310,21 @@ 'after_add_entity', '') self.reactivate_verification_hooks() + def install_custom_sql_scripts(self, directory, driver): + self.session.set_pool() # ensure pool is set + for fpath in glob(osp.join(directory, '*.sql.%s' % driver)): + newname = osp.basename(fpath).replace('.sql.%s' % driver, + '.%s.sql' % driver) + warn('[3.5.6] rename %s into %s' % (fpath, newname), + DeprecationWarning) + print '-> installing', fpath + sqlexec(open(fpath).read(), self.session.system_sql, False, + delimiter=';;') + for fpath in glob(osp.join(directory, '*.%s.sql' % driver)): + print '-> installing', fpath + sqlexec(open(fpath).read(), self.session.system_sql, False, + delimiter=';;') + # schema synchronization internals ######################################## def _synchronize_permissions(self, ertype): @@ -544,8 +561,11 @@ self.fs_schema = self._create_context()['fsschema'] = newcubes_schema new = set() # execute pre-create files + driver = self.repo.system_source.dbdriver for pack in reversed(newcubes): - self.exec_event_script('precreate', self.config.cube_dir(pack)) + cubedir = self.config.cube_dir(pack) + self.install_custom_sql_scripts(osp.join(cubedir, 'schema'), driver) + self.exec_event_script('precreate', cubedir) # add new entity and relation types for rschema in newcubes_schema.relations(): if not rschema in self.repo.schema: