22 import tarfile |
22 import tarfile |
23 import tempfile |
23 import tempfile |
24 import shutil |
24 import shutil |
25 import os.path as osp |
25 import os.path as osp |
26 from datetime import datetime |
26 from datetime import datetime |
|
27 from glob import glob |
|
28 from warnings import warn |
27 |
29 |
28 from logilab.common.deprecation import deprecated |
30 from logilab.common.deprecation import deprecated |
29 from logilab.common.decorators import cached, clear_cache |
31 from logilab.common.decorators import cached, clear_cache |
30 from logilab.common.adbh import get_adv_func_helper |
32 from logilab.common.adbh import get_adv_func_helper |
31 |
33 |
305 self.execscript_confirm = execscript_confirm |
307 self.execscript_confirm = execscript_confirm |
306 if self.config.free_wheel: |
308 if self.config.free_wheel: |
307 self.repo.hm.register_hook(setowner_after_add_entity, |
309 self.repo.hm.register_hook(setowner_after_add_entity, |
308 'after_add_entity', '') |
310 'after_add_entity', '') |
309 self.reactivate_verification_hooks() |
311 self.reactivate_verification_hooks() |
|
312 |
|
313 def install_custom_sql_scripts(self, directory, driver): |
|
314 self.session.set_pool() # ensure pool is set |
|
315 for fpath in glob(osp.join(directory, '*.sql.%s' % driver)): |
|
316 newname = osp.basename(fpath).replace('.sql.%s' % driver, |
|
317 '.%s.sql' % driver) |
|
318 warn('[3.5.6] rename %s into %s' % (fpath, newname), |
|
319 DeprecationWarning) |
|
320 print '-> installing', fpath |
|
321 sqlexec(open(fpath).read(), self.session.system_sql, False, |
|
322 delimiter=';;') |
|
323 for fpath in glob(osp.join(directory, '*.%s.sql' % driver)): |
|
324 print '-> installing', fpath |
|
325 sqlexec(open(fpath).read(), self.session.system_sql, False, |
|
326 delimiter=';;') |
310 |
327 |
311 # schema synchronization internals ######################################## |
328 # schema synchronization internals ######################################## |
312 |
329 |
313 def _synchronize_permissions(self, ertype): |
330 def _synchronize_permissions(self, ertype): |
314 """permission synchronization for an entity or relation type""" |
331 """permission synchronization for an entity or relation type""" |
542 # XXX we have to replace fs_schema, used in cmd_add_relation_type |
559 # XXX we have to replace fs_schema, used in cmd_add_relation_type |
543 # etc. and fsschema of migration script contexts |
560 # etc. and fsschema of migration script contexts |
544 self.fs_schema = self._create_context()['fsschema'] = newcubes_schema |
561 self.fs_schema = self._create_context()['fsschema'] = newcubes_schema |
545 new = set() |
562 new = set() |
546 # execute pre-create files |
563 # execute pre-create files |
|
564 driver = self.repo.system_source.dbdriver |
547 for pack in reversed(newcubes): |
565 for pack in reversed(newcubes): |
548 self.exec_event_script('precreate', self.config.cube_dir(pack)) |
566 cubedir = self.config.cube_dir(pack) |
|
567 self.install_custom_sql_scripts(osp.join(cubedir, 'schema'), driver) |
|
568 self.exec_event_script('precreate', cubedir) |
549 # add new entity and relation types |
569 # add new entity and relation types |
550 for rschema in newcubes_schema.relations(): |
570 for rschema in newcubes_schema.relations(): |
551 if not rschema in self.repo.schema: |
571 if not rschema in self.repo.schema: |
552 self.cmd_add_relation_type(rschema.type) |
572 self.cmd_add_relation_type(rschema.type) |
553 new.add(rschema.type) |
573 new.add(rschema.type) |