def VerifyOrCreate(self, client, callback, verify_only=False):
    def _OnDescribeTable(table, verify_cb, result):
      """Verifies the table description in schema matches the
      table in the database.
      """
      if verify_only:
        verify_cb((table.name, result))
        return

      assert isinstance(result, db_client.DescribeTableResult), result
      if options.options.verify_provisioning:
        # TODO(mike): Longer term, consider using values read from dymamodb for provisioned throughput as authoritative
        #   or consider some other mechanism for monitoring mismatches. We shouldn't prevent server startup just
        #   because of a mismatch in provisioned read or write units.
        if table.read_units != result.schema.read_units:
          logging.warning('%s: read units mismatch %d != %d', table.name, table.read_units, result.schema.read_units)
        if table.write_units != result.schema.write_units:
          logging.warning('%s: write units mismatch %d != %d', table.name, table.write_units, result.schema.write_units)
      assert table.hash_key_schema == result.schema.hash_key_schema, \
          '%s: hash key schema mismatch %r != %r' % \
          (table.name, table.hash_key_schema, result.schema.hash_key_schema)
      assert table.range_key_schema == result.schema.range_key_schema, \
          '%s: range key schema mismatch %r != %r' % \
          (table.name, table.range_key_schema, result.schema.range_key_schema)
      assert result.schema.status in ['CREATING', 'ACTIVE'], \
          '%s: table status invalid: %s' % (table.name, result.schema.status)
      if result.schema.status == 'CREATING':
        logging.info('table %s still in CREATING state...waiting 1s' % table.name)
        client.AddTimeout(1.0, partial(_VerifyTable, table, verify_cb))
        return
      else:
        logging.debug('verified table %s' % table.name)
      verify_cb((table.name, result))

    def _VerifyTable(table, verify_cb):
      """Gets table description and verifies via _OnDescribeTable."""
      client.DescribeTable(table=table.name,
                           callback=partial(_OnDescribeTable, table, verify_cb))

    def _OnCreateTable(table, verify_cb, result):
      """Invoked on creation of a table; moves to verification step."""
      assert isinstance(result, db_client.CreateTableResult), result
      logging.debug('created table %s: %s' % (table.name, repr(result.schema)))
      _VerifyTable(table, verify_cb)

    def _OnListTables(result):
      """First callback with results of a list-tables command.
      Creates a results barrier which will collect all table schemas
      and return 'callback' on successful verification of all tables.
      """
      # Create and/or verifies all tables in schema.
      with util.ArrayBarrier(callback) as b:
        read_capacity = 0
        write_capacity = 0
        for table in self._tables.values():
          read_capacity += table.read_units
          write_capacity += table.write_units
          if table.name not in result.tables:
            if verify_only:
              b.Callback()((table.name, None))
            else:
              logging.debug('creating table %s...' % table.name)
              client.CreateTable(table=table.name, hash_key_schema=table.hash_key_schema,
                                 range_key_schema=table.range_key_schema,
                                 read_units=table.read_units, write_units=table.write_units,
                                 callback=partial(_OnCreateTable, table, b.Callback()))
          else:
            _VerifyTable(table, b.Callback())

      # Warn of vestigial tables.
      for table in result.tables:
        if table.lower() not in self._tables:
          logging.warning('vestigial table %s exists in DB, not in schema' % table)
          if options.options.delete_vestigial and options.options.localdb:
            logging.warning('deleting vestigial table %s')
            client.DeleteTable(table=table, callback=util.NoCallback)

      # Cost metric.
      def _CostPerMonth(units, read=True):
        return 30 * 24 * 0.01 * (units / (50 if read else 10))

      logging.debug('total tables: %d' % len(self._tables))
      logging.debug('total read capacity: %d, $%.2f/month' % (read_capacity, _CostPerMonth(read_capacity, True)))
      logging.debug('total write capacity: %d, $%.2f/month' % (write_capacity, _CostPerMonth(write_capacity, False)))

    client.ListTables(callback=_OnListTables)
Verifies the schema if it exists or creates it if not.
dataset/ETHPy150Open viewfinderco/viewfinder/backend/db/schema.py/Schema.VerifyOrCreate