code: def create_missing_perms(self):
          
          from superset import db
          from superset.models import core as models
  
          logging.info(
              'Fetching a set of all perms to lookup which ones are missing')
          all_pvs = set()
          for pv in self.get_session.query(self.permissionview_model).all():
              if pv.permission and pv.view_menu:
                  all_pvs.add((pv.permission.name, pv.view_menu.name))
  
          def merge_pv(view_menu, perm):
              """Create permission view menu only if it doesn't exist"""
              if view_menu and perm and (view_menu, perm) not in all_pvs:
                  self.merge_perm(view_menu, perm)
  
          logging.info('Creating missing datasource permissions.')
          datasources = ConnectorRegistry.get_all_datasources(db.session)
          for datasource in datasources:
              merge_pv('datasource_access', datasource.get_perm())
              merge_pv('schema_access', datasource.schema_perm)
  
          logging.info('Creating missing database permissions.')
          databases = db.session.query(models.Database).all()
          for database in databases:
              merge_pv('database_access', database.perm)
  
          logging.info('Creating missing metrics permissions')
          metrics = []
          for datasource_class in ConnectorRegistry.sources.values():
              metrics += list(db.session.query(datasource_class.metric_class).all())
  
          for metric in metrics:
              if metric.is_restricted:
                  merge_pv('metric_access', metric.perm)
docs: Creates missing perms for datasources, schemas and metrics