Skip to content

Commit

Permalink
fix: replaceJsonColumnsSqliteWorkaround make sure value is an array
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-code-labx committed May 6, 2024
1 parent 2c9db3a commit fc98fcc
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Concerns/InteractsWithDbSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function getAllTableNames(): Collection
}

/**
* @return \Illuminate\Support\Collection<int|string, array<string, mixed>>
* @return \Illuminate\Support\Collection<int|string, array<mixed>>
*/
protected function getTableColumns(string $table, bool $withProperties = false): Collection
{
Expand All @@ -36,7 +36,7 @@ protected function getTableColumns(string $table, bool $withProperties = false):

/**
* @param array<string> $exclude
* @return \Illuminate\Support\Collection<int|string, array<string, mixed>>
* @return \Illuminate\Support\Collection<int|string, array<mixed>>
*/
protected function getTableColumnsForRelation(string $table, array $exclude = []): Collection
{
Expand Down Expand Up @@ -68,19 +68,20 @@ protected function isFieldNullable(array $fieldProperties): bool
}

/**
* @return Collection<int|string, array<string, mixed>>
* @phpstan-ignore-next-line
*/
private function replaceJsonColumnsSqliteWorkaround(string $table): Collection
{
$results = DB::select("PRAGMA table_info({$table})");

return collect($results)->map(function ($column) use ($table) {
$column_value = DB::table($table)->whereNotNull($column->name)->value($column->name);
if (Str::isJson($column_value)) {

if (is_string($column_value) && is_array(json_decode($column_value, true))) {
$column->type_name = $column->type = 'json';
}

return $column;
return (array) $column;
});
}
}

0 comments on commit fc98fcc

Please sign in to comment.