Creates the elastic search mapping for the provided table, or just prints it out
to the screen if the `dry-run` option is provided.

@param string $table The table name to inspect and create a mapping for
@return bool
480319
public function main($table)
    {
        $table = $this->loadModel($table);
        $schema = $table->getSchema();
        $mapping = [
            '@timestamp' => ['type' => 'date', 'format' => 'basic_t_time_no_millis||dateOptionalTime||basic_date_time||ordinal_date_time_no_millis||yyyy-MM-dd HH:mm:ss'],
            'transaction' => ['type' => 'text', 'index' => false],
            'type' => ['type' => 'text', 'index' => false],
            'primary_key' => ['type' => 'text', 'index' => false],
            'source' => ['type' => 'text', 'index' => false],
            'parent_source' => ['type' => 'text', 'index' => false],
            'original' => [
                'properties' => []
            ],
            'changed' => [
                'properties' => []
            ],
            'meta' => [
                'properties' => [
                    'ip' => ['type' => 'text', 'index' => false],
                    'url' => ['type' => 'text', 'index' => false],
                    'user' => ['type' => 'text', 'index' => false],
                    'app_name' => ['type' => 'text', 'index' => false]
                ]
            ]
        ];

        $properties = [];
        foreach ($schema->columns() as $column) {
            $properties[$column] = $this->mapType($schema, $column);
        }

        $indexName = $table->getTable();
        $typeName = Inflector::singularize(str_replace('%s', '', $indexName));

        if ($table->hasBehavior('AuditLog')) {
            $whitelist = (array)$table->behaviors()->AuditLog->config('whitelist');
            $blacklist = (array)$table->behaviors()->AuditLog->config('blacklist');
            $properties = empty($whitelist) ? $properties : array_intersect_key($properties, array_flip($whitelist));
            $properties = array_diff_key($properties, array_flip($blacklist));
            $indexName = $table->behaviors()->AuditLog->config('index') ?: $indexName;
            $typeName = $table->behaviors()->AuditLog->config('type') ?: $typeName;
        }

        $mapping['original']['properties'] = $mapping['changed']['properties'] = $properties;
        $client = ConnectionManager::get('auditlog_elastic');
        $index = $client->getIndex(sprintf($indexName, '-' . gmdate('Y.m.d')));
        $type = $index->getType($typeName);
        $elasticMapping = new ElasticaMapping();
        $elasticMapping->setType($type);
        $elasticMapping->setProperties($mapping);

        if ($this->params['dry-run']) {
            $this->out(json_encode($elasticMapping->toArray(), JSON_PRETTY_PRINT));
            return true;
        }

        if ($this->params['use-templates']) {
            $template = [
                'template' => sprintf($indexName, '*'),
                'mappings' => $elasticMapping->toArray()
            ];
            $response = $client->request('_template/template_' . $type->getName(), Request::PUT, $template);
            $this->out('<success>Successfully created the mapping template</success>');
            return $response->isOk();
        }

        if (!$index->exists()) {
            $index->create();
        }

        $elasticMapping->send();
        $this->out('<success>Successfully created the mapping</success>');
        return true;
    }
342891
public function get_indexes($table) {
        $indexes = array();
        $tablename = $this->prefix.$table;

        $sql = "SELECT i.*
                  FROM pg_catalog.pg_indexes i
                  JOIN pg_catalog.pg_namespace as ns ON ns.nspname = i.schemaname
                 WHERE i.tablename = '$tablename'
                       AND (i.schemaname = current_schema() OR ns.oid = pg_my_temp_schema())";

        $this->query_start($sql, null, SQL_QUERY_AUX);
        $result = pg_query($this->pgsql, $sql);
        $this->query_end($result);

        if ($result) {
            while ($row = pg_fetch_assoc($result)) {
                // The index definition could be generated schema-qualifying the target table name
                // for safety, depending on the pgsql version (CVE-2018-1058).
                if (!preg_match('/CREATE (|UNIQUE )INDEX ([^\s]+) ON (|'.$row['schemaname'].'\.)'.$tablename.' USING ([^\s]+) \(([^\)]+)\)/i', $row['indexdef'], $matches)) {
                    continue;
                }
                if ($matches[5] === 'id') {
                    continue;
                }
                $columns = explode(',', $matches[5]);
                foreach ($columns as $k=>$column) {
                    $column = trim($column);
                    if ($pos = strpos($column, ' ')) {
                        // index type is separated by space
                        $column = substr($column, 0, $pos);
                    }
                    $columns[$k] = $this->trim_quotes($column);
                }
                $indexes[$row['indexname']] = array('unique'=>!empty($matches[1]),
                                              'columns'=>$columns);
            }
            pg_free_result($result);
        }
        return $indexes;
    }
837786
final public function table($table) {
      $this->connection();
      if (func_num_args()>1)
         $table = func_get_args();
      else if(is_string($table))
         $table = [$table];
      
      $schema = '';
      if ($this->driver=='pgsql' && $this->schema)
         $schema = $this->schema ? $this->schema.'.' : '';

      $tmp_table = [];
      foreach($table as $table) {
         if (preg_match('/\./', $table)) {
            $tmp_table[] = $table;
         }
         else {
            $tmp_table[] = $schema.$table;
         }
      }

      $table = implode(",", $tmp_table);

      if ($this->extended) {
         if ( $this->table ) {
            $this->table = $schema.$this->table.",".$table;
         } else {
            $this->table = $table;
         }
      }
      else {
         $this->table = $table;
      }

      $this->find_first_data = $this->find_save_data = $this->find_delete_data = FALSE;

      $this->get_instance();
      return $this;
   }
386312
public function getTableIndexes( $table )
    {
        $query = "SELECT * FROM information_schema.statistics WHERE table_schema =
                 ? AND table_name = ?";

        $params = [ $this->name, $table ];

        $statement = $this->database->prepare( $query );
        $statement->execute( $params );

        $results = $statement->fetchAll();

        $indexes = [ ];

        if ( !empty( $results ) )
        {
            $name = NULL;

            $i = 0;

            foreach ( $results as $result )
            {
                if ( !in_array( $result[ 'INDEX_NAME' ], $indexes ) )
                {
                    $indexes[ ] = $result[ 'INDEX_NAME' ];
                }
            }
        }

        return $indexes;
    }
986834
public function table($table, bool $mapped = false)
    {
        return $mapped ?
            new TableQueryMapped($this, $this->definition($table)) :
            new TableQuery($this, $this->definition($table));
    }
444045
public function hasTable($table)
    {
        $sql = $this->grammar->compileTableExists();

        $table = $this->connection->getTablePrefix().$table;

        return count($this->connection->select($sql, array($table))) > 0;
    }
534595
public function describeTable($table)
    {
        if (null !== $this->logger) {
            $this->log('Describe table '.$table);
        }

        $parameters = array(
            'TableName' => $table,
        );

        if (null !== $this->logger) {
            $this->log('DescribeTable request paramaters : '.print_r($parameters, true), Logger::DEBUG);
        }

        $response = $this->connector->describeTable($parameters);

        if (null !== $this->logger) {
            $this->log('DescribeTable request response : '.print_r($response, true), Logger::DEBUG);
        }

        $tableDescription = new Table\TableDescription();
        $tableDescription->populateFromDynamoDB($response['Table']);

        return $tableDescription;
    }
1345639
final public function drop($table)
    {
        $table = $this->getTablePrefixed($table);

        $sql = sprintf('DROP TABLE `%s`;', $table);

        return $this->executeSqlQuery($sql);
    }
646464
protected function tableIgnored(string $table): bool
    {
        foreach ($this->ignoredTables as $ignoredTable) {
            if (preg_match("/^$ignoredTable\$/", $table)) {
                return true;
            }
        }

        return false;
    }
266734
public function search($table = null)
    {
        $search = $this->resolve(Search::class, $this);

        if ($table) {
            $search->setTable($table);
        }

        return $search;
    }
677831
public function getTableKeys($table)
	{
		$this->connect();

		// To check if table exists and prevent SQL injection
		$tableList = $this->getTableList();

		if (\in_array($table, $tableList, true))
		{
			// Get the details columns information.
			$this->setQuery('
				SELECT indexname AS "idxName", indisprimary AS "isPrimary", indisunique  AS "isUnique",
					CASE WHEN indisprimary = true THEN
						( SELECT \'ALTER TABLE \' || tablename || \' ADD \' || pg_catalog.pg_get_constraintdef(const.oid, true)
							FROM pg_constraint AS const WHERE const.conname= pgClassFirst.relname )
					ELSE pg_catalog.pg_get_indexdef(indexrelid, 0, true)
					END AS "Query"
				FROM pg_indexes
				LEFT JOIN pg_class AS pgClassFirst ON indexname=pgClassFirst.relname
				LEFT JOIN pg_index AS pgIndex ON pgClassFirst.oid=pgIndex.indexrelid
				WHERE tablename=' . $this->quote($table) . ' ORDER BY indkey'
			);

			return $this->loadObjectList();
		}

		return false;
	}
613590
protected function checkTable(string $table)
    {
        if (! property_exists($this, $table) || ! $this->$table instanceof Table) {
            throw new \InvalidArgumentException("Invalid table name: `{$table}`.");
        }
    }
637707
private function prefixTableCallback(string $table) : string
    {
        $prefix = $this->getTablePrefix();
        if (!empty($prefix) && is_string($prefix) && trim($prefix)) {
            $table = (strpos($table, $prefix) === 0)
                ? $table
                : $prefix.$table;
        }

        return $table;
    }
779241
public static function query($table)
    {
        $query = new Builder(
            $connection = static::user()->getConnection(),
            $connection->getQueryGrammar(),
            $connection->getPostProcessor()
        );

        return $query->from(static::table($table));
    }
385756
public function table($table)
    {
        $this->table = $table;
        $alias = $this->alias ?? $this->table;

        if (!in_array('`' . $table . '`.*', $this->select) && !in_array('`' . $alias . '`.*', $this->select)) {
            $this->select[] = '`' . $table . '`.*';
        }

        return $this;
    }
1095254
final public function fetchTableDef(string $table) {
        $tableKey = strtolower($table);

        // First check the table cache.
        if (isset($this->tables[$tableKey])) {
            $tableDef = $this->tables[$tableKey];

            if (isset($tableDef['columns'], $tableDef['indexes'])) {
                return $tableDef;
            }
        } elseif ($this->tableNames !== null && !isset($this->tableNames[$tableKey])) {
            return null;
        }

        $tableDef = $this->fetchTableDefDb($table);
        if ($tableDef !== null) {
            $this->fixIndexes($tableDef['name'], $tableDef);
            $this->tables[$tableKey] = $tableDef;
        }

        return $tableDef;
    }
932744
protected function getTableKey($table) {
        if (empty(static::$tableKeys)) {
            $this->loadTableKeys();
        }

        return isset(static::$tableKeys[$table]) ? static::$tableKeys[$table] : static::$tableKeys['__default__'];
    }