fix #544758 by calling custom sql scripts in add_cubes. stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 23 Nov 2009 18:13:20 +0100
branchstable
changeset 3903 7967d3766ecf
parent 3902 a0efb0326021
child 3904 dc7d315165fc
child 3906 b79f361839a7
fix #544758 by calling custom sql scripts in add_cubes. Refactor to benefit from code of db initialization on the migration handler.
server/__init__.py
server/migractions.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()
--- 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: