def sync(self, models=None, **context):
context = orb.Context(**context)<EOL>conn = self.__connection<EOL>all_models = orb.system.models(orb.Model).values()<EOL>all_models.sort(cmp=lambda x,y: cmp(x.schema(), y.schema()))<EOL>tables = [model for model in all_models if issubclass(model, orb.Table) and<EOL>not model.schema().testFlags(orb.Schema.Flags.Abstract) and<EOL>(not models or model.schema().name() in models)]<EOL>views = [model for model in all_models if issubclass(model, orb.View) and<EOL>not model.schema().testFlags(orb.Schema.Flags.Abstract) and<EOL>(not models or model.schema().name() in models)]<EOL>event = orb.events.SyncEvent(context=context)<EOL>self.__connection.onSync(event)<EOL>namespaces = set()<EOL>info = conn.schemaInfo(context)<EOL>for model in tables:<EOL><INDENT>if model.schema().dbname() not in info:<EOL><INDENT>namespace = model.schema().namespace()<EOL>if namespace and namespace not in namespaces:<EOL><INDENT>conn.addNamespace(namespace, context)<EOL>namespaces.add(namespace)<EOL><DEDENT>conn.createModel(model, context, includeReferences=False, owner=self.username())<EOL><DEDENT><DEDENT>info = conn.schemaInfo(context)<EOL>for model in tables:<EOL><INDENT>try:<EOL><INDENT>model_info = info[model.schema().dbname()]<EOL><DEDENT>except KeyError:<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>add = defaultdict(list)<EOL>for col in model.schema().columns(recurse=False).values():<EOL><INDENT>if col.field() not in (model_info['<STR_LIT>'] or []) and not col.testFlag(col.Flags.Virtual):<EOL><INDENT>add['<STR_LIT>'].append(col)<EOL><DEDENT><DEDENT>for index in model.schema().indexes(recurse=False).values():<EOL><INDENT>if index.dbname() not in (model_info['<STR_LIT>'] or []):<EOL><INDENT>add['<STR_LIT>'].append(index)<EOL><DEDENT><DEDENT>if add['<STR_LIT>'] or add['<STR_LIT>']:<EOL><INDENT>conn.alterModel(model, context, add=add, owner=self.username())<EOL><DEDENT><DEDENT><DEDENT>for model in tables:<EOL><INDENT>event = orb.events.SyncEvent(model=model)<EOL>if model.processEvent(event):<EOL><INDENT>model.onSync(event)<EOL><DEDENT><DEDENT>for view in views:<EOL><INDENT>conn.createModel(view, context)<EOL>event = orb.events.SyncEvent(model=view)<EOL>if view.processEvent(event):<EOL><INDENT>view.onSync(event)<EOL><DEDENT><DEDENT>
Syncs the database by calling its schema sync method.  If
no specific schema has been set for this database, then
the global database schema will be used.  If the dryRun
flag is specified, then all the resulting commands will
just be logged to the current logger and not actually 
executed on the database.

:note       From version 0.6.0 on, this method now accepts a mutable
            keyword dictionary of values.  You can supply any member 
            value for either the <orb.LookupOptions> or
            <orb.Context>, 'options' for
            an instance of the <orb.Context>

:return     <bool> success