add a command to compare db schema and file system schema (closes #464991)
authorAlexandre Richardson <alexandre.richardson@logilab.fr>
Fri, 30 Nov 2012 16:43:36 +0100
changeset 8749 9db7580d6427
parent 8748 f5027f8d2478
child 8750 405d63b8fa6f
add a command to compare db schema and file system schema (closes #464991)
server/serverctl.py
--- a/server/serverctl.py	Tue Mar 12 12:50:05 2013 +0100
+++ b/server/serverctl.py	Fri Nov 30 16:43:36 2012 +0100
@@ -39,6 +39,7 @@
 from cubicweb.server.serverconfig import (
     USER_OPTIONS, ServerConfiguration, SourceConfiguration,
     ask_source_config, generate_source_config)
+from yams.diff import schema_diff
 
 # utility functions ###########################################################
 
@@ -1065,12 +1066,31 @@
             if val:
                 print key, ':', val
 
+class SchemaDiffCommand(Command):
+    """ generate a diff between schema and fsschema description
+    <instance>
+      the name of a diff tool to compare the two generated file
+    <diff-tool>
+    """
+    name = 'schema-diff'
+    arguments = '<instance> <diff-tool>'
+    min_args = max_args = 2
+
+    def run(self, args):
+        appid = args.pop(0)
+        diff_tool = args.pop(0)
+        config = ServerConfiguration.config_for(appid)
+        repo, cnx = repo_cnx(config)
+        session = repo._get_session(cnx.sessionid, setcnxset=True)
+        fsschema = config.load_schema(expand_cubes=True)
+        schema_diff(repo.schema, fsschema, diff_tool)
+
 
 for cmdclass in (CreateInstanceDBCommand, InitInstanceCommand,
                  GrantUserOnInstanceCommand, ResetAdminPasswordCommand,
                  StartRepositoryCommand,
                  DBDumpCommand, DBRestoreCommand, DBCopyCommand,
                  AddSourceCommand, CheckRepositoryCommand, RebuildFTICommand,
-                 SynchronizeInstanceSchemaCommand, SynchronizeSourceCommand
+                 SynchronizeInstanceSchemaCommand, SynchronizeSourceCommand, SchemaDiffCommand,
                  ):
     CWCTL.register(cmdclass)