<commit_before><?php

namespace Aozisik\Outport;

use Schema as EloquentSchema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Collection;

class Schema
{
    protected $fields;

    public function __construct(array $fields)
    {
        $this->fields = $fields;
    }

    public static function fromCollection(Collection $collection)
    {
        $fields = [];
        $sample = $collection->first();

        $typeChecks = [
            'text' => 'is_string',
            'integer' => 'is_int',
            'boolean' => 'is_bool',
            'double' => 'is_double'
        ];

        foreach ($sample as $field => $value) {
            $type = 'text';
            foreach ($typeChecks as $type => $checkMethod) {
                if (call_user_func($checkMethod, $value)) {
                    break;
                }
            }
            // TODO: Handle cases where the value is not a string, integer, boolean or a double
            $fields[$field] = $type;
        }

        return new Schema($fields);
    }

    public function create(Connection $connection, $table)
    {
        EloquentSchema::connection($connection->id)->create($table, function (Blueprint $table) {
            foreach ($this->fields as $field => $type) {
                $table->$type($field)->nullable();
            }
        });<commit_msg>add auto incrementing id field to all tables<commit_after><?php

namespace Aozisik\Outport;

use Schema as EloquentSchema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Collection;

class Schema
{
    protected $fields;

    public function __construct(array $fields)
    {
        $this->fields = $fields;
    }

    public static function fromCollection(Collection $collection)
    {
        $fields = [];
        $sample = $collection->first();

        $typeChecks = [
            'text' => 'is_string',
            'integer' => 'is_int',
            'boolean' => 'is_bool',
            'double' => 'is_double'
        ];

        foreach ($sample as $field => $value) {
            $type = 'text';
            foreach ($typeChecks as $type => $checkMethod) {
                if (call_user_func($checkMethod, $value)) {
                    break;
                }
            }
            // TODO: Handle cases where the value is not a string, integer, boolean or a double
            $fields[$field] = $type;
        }

        return new Schema($fields);
    }

    public function create(Connection $connection, $table)
    {
        EloquentSchema::connection($connection->id)->create($table, function (Blueprint $table) {
            $table->increments('id');
            foreach ($this->fields as $field => $type) {
                $table->$type($field)->nullable();
            }
        });
{'fraction_non_alphanumeric': 0.12963629816348576, 'fraction_numerical': 0.0, 'mean_word_length': 1.9427966101694916, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5581312', 'n_tokens_mistral': 760, 'n_tokens_neox': 748, 'n_words': 186}