Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a59fc36
Dispatch MigrationFailed when a migration throws
binaryfire Nov 14, 2026
e3fa451
Enforce the email address length limit on both validation paths
binaryfire Nov 14, 2026
a6fd6c9
Preserve canonical JSON API identities and association metadata
binaryfire Nov 14, 2026
f0e824a
Preserve migration failures when notification listeners throw
binaryfire Nov 15, 2026
68d88da
Clarify related resource variables in JSON API resolution
binaryfire Nov 15, 2026
a26bd0b
Add URI origin inspection
binaryfire Nov 15, 2026
710f1ab
Cover reconnection after a lost transaction commit
binaryfire Nov 15, 2026
ceccbdc
Honor the integer key alias across schema and identity handling
binaryfire Nov 15, 2026
e7c1353
Preserve JSON sessions containing invalid UTF-8
binaryfire Nov 15, 2026
ed427e2
Preserve PostgreSQL extension-owned views and tables during resets
binaryfire Nov 15, 2026
55f9556
Preserve validation semantics while retaining safe database batching
binaryfire Nov 15, 2026
cb36fb7
Avoid backtracking in decimal validation
binaryfire Nov 15, 2026
425623d
Add blank checks to fluent strings
binaryfire Nov 15, 2026
77d2a26
Resolve automatic write columns after applying model scopes
binaryfire Nov 15, 2026
f29db78
Protect literal PHAR archive boundaries on POSIX
binaryfire Nov 15, 2026
d53e27d
Avoid reporting manually failed jobs as successful
binaryfire Nov 15, 2026
12951e9
Avoid unnecessary hashing work and real waits in tests
binaryfire Nov 15, 2026
09ccf7d
Preserve migration failures when listener reporting also fails
binaryfire Nov 15, 2026
5a05c67
Keep PostgreSQL metadata filters within their owning catalogs
binaryfire Nov 15, 2026
09ae77c
Preserve JSON API relationship occurrence state and discovery ownership
binaryfire Nov 15, 2026
b9ac775
Preserve database rule overrides and typed JSON presence candidates
binaryfire Nov 15, 2026
674258c
Compare MariaDB JSON booleans without string or numeric coercion
binaryfire Nov 15, 2026
070ccb9
Align Foundation URI dependency with the origin helper
binaryfire Nov 15, 2026
0c79a74
Isolate integer role key coverage from custom UUID role fixtures
binaryfire Nov 15, 2026
4ba9a9c
Make response preparation comparisons independent of clock boundaries
binaryfire Nov 15, 2026
cfeaecf
Respect exported bcrypt rounds in Testbench configuration assertions
binaryfire Nov 15, 2026
6dc8615
Merge 0.4 validation improvements into the upstream update branch
binaryfire Nov 15, 2026
15d30d0
Preserve JSON API metadata values and bounded relationship expansion
binaryfire Nov 15, 2026
34e1b82
Own migration reporter test files through the test lifecycle
binaryfire Nov 15, 2026
9361c0c
Honor response JSON options when comparing relationship metadata
binaryfire Nov 16, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"league/flysystem-path-prefixing": "^3.25.1",
"league/flysystem-read-only": "^3.25.1",
"league/oauth2-server": "^9.4",
"league/uri": "^7.5.1",
"league/uri": "^7.6",
"monolog/monolog": "^3.10",
"nesbot/carbon": "^3.13.1",
"nikic/php-parser": "^5.7",
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<ini name="display_startup_errors" value="on"/>
<ini name="memory_limit" value="1024M"/>
<server name="HYPERVEL_PARALLEL_TESTING" value="1"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<!--
Fix terminal dimensions so console-output assertions do not depend
on the developer's terminal size.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Hypervel\Database\Eloquent\Attributes\UseResource;
use Hypervel\Database\Eloquent\Attributes\UseResourceCollection;
use Hypervel\Http\Resources\Exceptions\ResourceClassNotFoundException;
use Hypervel\Http\Resources\Json\JsonResource;
use Hypervel\Http\Resources\Json\ResourceCollection;
use LogicException;
Expand Down Expand Up @@ -81,7 +82,7 @@ protected function guessResourceCollection(): ResourceCollection
}
}

throw new LogicException(sprintf('Failed to find resource class for model [%s].', $className));
throw ResourceClassNotFoundException::forModel($model);
}

/**
Expand Down
39 changes: 29 additions & 10 deletions src/database/src/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,9 @@ public function forceCreateQuietly(array $attributes = []): Model
*/
public function update(array $values): int
{
return $this->toBase()->update($this->addUpdatedAtColumn($values));
$builder = $this->applyScopes()->withoutGlobalScopes();

return $builder->toBase()->update($builder->addUpdatedAtColumn($values));
}

/**
Expand Down Expand Up @@ -1372,18 +1374,28 @@ public function touch(array|string|null $column = null): false|int
return false;
}

return $this->toBase()->update([$column => $time]);
// Global scopes may add joins or alias the table, so qualify against the scoped builder.
$builder = $this->applyScopes()->withoutGlobalScopes();
$query = $builder->toBase();

if (! empty($query->joins)) {
$column = $builder->qualifyColumn($column);
}
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved

return $query->update([$column => $time]);
}

/**
* Increment a column's value by a given amount.
*/
public function increment(Expression|string $column, mixed $amount = 1, array $extra = []): int
{
return $this->toBase()->increment(
$builder = $this->applyScopes()->withoutGlobalScopes();

return $builder->toBase()->increment(
$column,
$amount,
$this->addUpdatedAtColumn($extra)
$builder->addUpdatedAtColumn($extra)
);
}

Expand All @@ -1392,10 +1404,12 @@ public function increment(Expression|string $column, mixed $amount = 1, array $e
*/
public function decrement(Expression|string $column, mixed $amount = 1, array $extra = []): int
{
return $this->toBase()->decrement(
$builder = $this->applyScopes()->withoutGlobalScopes();

return $builder->toBase()->decrement(
$column,
$amount,
$this->addUpdatedAtColumn($extra)
$builder->addUpdatedAtColumn($extra)
);
}

Expand All @@ -1407,9 +1421,11 @@ public function decrement(Expression|string $column, mixed $amount = 1, array $e
*/
public function incrementEach(array $columns, array $extra = []): int
{
return $this->toBase()->incrementEach(
$builder = $this->applyScopes()->withoutGlobalScopes();

return $builder->toBase()->incrementEach(
$columns,
$this->addUpdatedAtColumn($extra)
$builder->addUpdatedAtColumn($extra)
);
}

Expand All @@ -1421,9 +1437,11 @@ public function incrementEach(array $columns, array $extra = []): int
*/
public function decrementEach(array $columns, array $extra = []): int
{
return $this->toBase()->decrementEach(
$builder = $this->applyScopes()->withoutGlobalScopes();

return $builder->toBase()->decrementEach(
$columns,
$this->addUpdatedAtColumn($extra)
$builder->addUpdatedAtColumn($extra)
);
}

Expand All @@ -1439,6 +1457,7 @@ protected function addUpdatedAtColumn(array $values): array

$column = $this->model->getUpdatedAtColumn();

// Scopes may alias the table; writes that retain this qualifier must prepare scopes first.
$alias = $this->query->getFromAlias();

// Opaque raw sources cannot safely qualify an automatic timestamp.
Expand Down
6 changes: 3 additions & 3 deletions src/database/src/Eloquent/Concerns/TransformsToResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Hypervel\Database\Eloquent\Concerns;

use Hypervel\Database\Eloquent\Attributes\UseResource;
use Hypervel\Http\Resources\Exceptions\ResourceClassNotFoundException;
use Hypervel\Http\Resources\Json\JsonResource;
use Hypervel\Support\Str;
use LogicException;
use ReflectionClass;

/**
Expand All @@ -32,7 +32,7 @@ public function toResource(?string $resourceClass = null): JsonResource
/**
* Guess the resource class for the model.
*
* @throws LogicException
* @throws ResourceClassNotFoundException
*/
protected function guessResource(): JsonResource
{
Expand All @@ -48,7 +48,7 @@ protected function guessResource(): JsonResource
}
}

throw new LogicException(sprintf('Failed to find resource class for model [%s].', get_class($this)));
throw ResourceClassNotFoundException::forModel($this);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/database/src/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -2955,7 +2955,7 @@ public function resolveRouteBindingQuery(self|Builder|Relation $query, mixed $va

// Non-incrementing integer keys are validated too: MySQL and MariaDB would
// otherwise coerce a value such as "12abc" and resolve the model with key 12.
if ($this->getKeyType() === 'int'
if (in_array($this->getKeyType(), ['int', 'integer'], true)
&& Str::afterLast($field, '.') === $this->getKeyName()
&& ! $this->isValidIntegerRouteKey($value)) {
$this->handleInvalidRouteKey($value, $field);
Expand Down
3 changes: 3 additions & 0 deletions src/database/src/Eloquent/SoftDeletingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function extend(Builder $builder): void
}

$builder->onDelete(function (Builder $builder) {
$builder = $builder->applyScopes()->withoutGlobalScopes();
$column = $this->getDeletedAtColumn($builder);

return $builder->update([
Expand All @@ -56,6 +57,7 @@ public function extend(Builder $builder): void
*/
protected function getDeletedAtColumn(Builder $builder): string
{
// Scopes may add joins or aliases, so callers pass the scope-prepared builder.
if ((array) $builder->getQuery()->joins !== []) {
return $builder->qualifyColumn($builder->getModel()->getQualifiedDeletedAtColumn());
}
Expand All @@ -72,6 +74,7 @@ protected function addRestore(Builder $builder): void
{
$builder->macro('restore', function (Builder $builder) {
$builder->withTrashed();
$builder = $builder->applyScopes()->withoutGlobalScopes();

return $builder->update([$this->getDeletedAtColumn($builder) => null]);
});
Expand Down
25 changes: 25 additions & 0 deletions src/database/src/Events/MigrationFailed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Hypervel\Database\Events;

use Hypervel\Database\Migrations\Migration;
use Throwable;

class MigrationFailed extends MigrationEvent
{
/**
* Create a new event instance.
*
* @param Throwable $exception the exception that caused the migration to fail
*/
public function __construct(
Migration $migration,
string $method,
?string $name,
public Throwable $exception,
) {
parent::__construct($migration, $method, $name);
}
}
24 changes: 20 additions & 4 deletions src/database/src/Migrations/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Hypervel\Database\ConnectionResolver;
use Hypervel\Database\ConnectionResolverInterface as Resolver;
use Hypervel\Database\Events\MigrationEnded;
use Hypervel\Database\Events\MigrationFailed;
use Hypervel\Database\Events\MigrationsEnded;
use Hypervel\Database\Events\MigrationSkipped;
use Hypervel\Database\Events\MigrationsStarted;
Expand All @@ -30,9 +31,11 @@
use Hypervel\Support\Attributes\BootOnly;
use Hypervel\Support\Attributes\BootOrTestsOnly;
use Hypervel\Support\Collection;
use Hypervel\Support\FailureReporter;
use Hypervel\Support\Str;
use InvalidArgumentException;
use ReflectionClass;
use Throwable;
use WeakReference;

class Migrator
Expand Down Expand Up @@ -454,10 +457,23 @@ protected function runMigration(object $migration, string $method, ?string $name
}
};

$this->getSchemaGrammar($connection)->supportsSchemaTransactions()
&& $migration->withinTransaction
? $connection->transaction($callback)
: $callback();
try {
$this->getSchemaGrammar($connection)->supportsSchemaTransactions()
&& $migration->withinTransaction
? $connection->transaction($callback)
: $callback();
} catch (Throwable $exception) {
if ($this->hasMigrationEventListeners(MigrationFailed::class)) {
try {
$this->fireMigrationEvent(new MigrationFailed($migration, $method, $name, $exception));
} catch (Throwable $listenerException) {
// Unlike Laravel, report listener failures without replacing the migration failure, unless they carry cancellation.
$exception = FailureReporter::preferCancellation($exception, $listenerException);
}
}

throw $exception;
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/database/src/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ public function foreignIdFor(Model|string $model, ?string $column = null): Forei

$column = $column ?: $model->getForeignKey();

if ($model->getKeyType() === 'int') {
if (in_array($model->getKeyType(), ['int', 'integer'], true)) {
return $this->foreignId($column)
->table($model->getTable())
->referencesModelColumn($model->getKeyName());
Expand Down
12 changes: 8 additions & 4 deletions src/database/src/Schema/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public function compileTables(string|array|null $schema): string
. 'join pg_namespace pn on pn.oid = pc.relnamespace '
. 'where c.relispartition and i.inhrelid = c.oid) as partition_of from pg_class c, pg_namespace n '
. "where c.relkind in ('r', 'p') and n.oid = c.relnamespace and "
. "not exists (select 1 from pg_depend d where d.classid = 'pg_class'::regclass and d.objid = c.oid and d.deptype = 'e') and "
. $this->compileSchemaWhereClause($schema, 'n.nspname')
. ' order by n.nspname, c.relname';
}
Expand All @@ -97,9 +98,12 @@ public function compileTables(string|array|null $schema): string
*/
public function compileViews(string|array|null $schema): string
{
return 'select viewname as name, schemaname as schema, definition from pg_views where '
. $this->compileSchemaWhereClause($schema, 'schemaname')
. ' order by schemaname, viewname';
// Read catalog OIDs directly: resolving view names requires schema USAGE privileges.
return 'select c.relname as name, n.nspname as schema, pg_get_viewdef(c.oid) as definition '
. "from pg_class c join pg_namespace n on n.oid = c.relnamespace where c.relkind = 'v' and "
. "not exists (select 1 from pg_depend d where d.classid = 'pg_class'::regclass and d.objid = c.oid and d.deptype = 'e') and "
. $this->compileSchemaWhereClause($schema, 'n.nspname')
. ' order by n.nspname, c.relname';
}

/**
Expand All @@ -114,7 +118,7 @@ public function compileTypes(string|array|null $schema): string
. 'left join pg_type el on el.oid = t.typelem '
. 'left join pg_class ce on ce.oid = el.typrelid '
. "where ((t.typrelid = 0 and (ce.relkind = 'c' or ce.relkind is null)) or c.relkind = 'c') "
. "and not exists (select 1 from pg_depend d where d.objid in (t.oid, t.typelem) and d.deptype = 'e') and "
. "and not exists (select 1 from pg_depend d where d.classid = 'pg_type'::regclass and d.objid in (t.oid, t.typelem) and d.deptype = 'e') and "
. $this->compileSchemaWhereClause($schema, 'n.nspname');
}

Expand Down
43 changes: 43 additions & 0 deletions src/docs/eloquent-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,8 @@ return $post->load('author', 'comments')
->includePreviouslyLoadedRelationships();
```

When several resources of the same class wrap the same model instance, each previously loaded relationship keeps its first result. Relationships requested through the `include` query parameter are resolved by each resource.

<a name="jsonapi-links-and-meta"></a>
### Links and Meta

Expand Down Expand Up @@ -1315,6 +1317,47 @@ This will add `links` and `meta` keys to the resource object in the response:
}
```

<a name="jsonapi-identifier-meta"></a>
#### Relationship Identifier Metadata

Each JSON:API resource appears once per type and ID, and each relationship lists a related identity once. Included resources omit the pivot relation. To expose data about an association, define `toIdentifierMeta` on the related resource:

```php
/**
* Get metadata for this resource's relationship identifier.
*/
public function toIdentifierMeta(Request $request): array
{
return [
'role' => $this->whenPivotLoaded('team_user', fn () => $this->pivot->role),
];
}
```

The result appears in the relationship identifier's `meta` object. The pivot is available to this method, and conditional helpers such as `whenPivotLoadedAs` and `mergeWhen` are supported. Returning an empty array omits `meta`.

Identifier metadata describes one association between the parent and related resource. If multiple rows connect the same pair, expose those associations as resources with their own IDs; repeated identifiers with metadata are rejected when encountered. For example, a normal `Membership` model mapped to `team_user` can be exposed through a user's `memberships` relationship:

```php
use Hypervel\Http\Request;
use Hypervel\Http\Resources\JsonApi\JsonApiResource;

class MembershipResource extends JsonApiResource
{
public array $relationships = ['team' => TeamResource::class];

/**
* Transform the membership attributes.
*/
public function toAttributes(Request $request): array
{
return ['role' => $this->role];
}
}
```

Map `memberships` to this resource on `UserResource`, then request `include=memberships.team`. Each membership retains its own attributes while the shared team appears once. Standard JSON resources retain their usual `whenPivotLoaded` behavior.

<a name="resource-responses"></a>
## Resource Responses

Expand Down
3 changes: 3 additions & 0 deletions src/docs/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -3968,12 +3968,15 @@ $scheme = $uri->scheme();
$authority = $uri->authority();
$host = $uri->host();
$port = $uri->port();
$origin = $uri->origin();
$path = $uri->path();
$segments = $uri->pathSegments();
$query = $uri->query();
$fragment = $uri->fragment();
```

The `origin` method returns the URI's scheme, host, and non-default port, without credentials, path, query, or fragment. Relative URIs and opaque origins, such as `mailto:` and `file:`, return `null`.

<a name="manipulating-query-strings"></a>
#### Manipulating Query Strings

Expand Down
3 changes: 2 additions & 1 deletion src/docs/migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -1887,6 +1887,7 @@ For convenience, each migration operation will dispatch an [event](/docs/{{versi
| `Hypervel\Database\Events\MigrationsEnded` | A batch of migrations has finished. |
| `Hypervel\Database\Events\MigrationStarted` | A single migration is about to be executed. |
| `Hypervel\Database\Events\MigrationEnded` | A single migration has finished. |
| `Hypervel\Database\Events\MigrationFailed` | A single migration has failed. |
| `Hypervel\Database\Events\MigrationSkipped` | A single migration has been skipped. |
| `Hypervel\Database\Events\NoPendingMigrations` | A migration command found no pending migrations. |
| `Hypervel\Database\Events\SchemaDumped` | A database schema dump has finished. |
Expand All @@ -1895,4 +1896,4 @@ For convenience, each migration operation will dispatch an [event](/docs/{{versi

</div>

The `MigrationStarted` and `MigrationEnded` events expose the migration filename through their `$name` property. The `MigrationEnded` event also exposes how long the migration took to run, in milliseconds, through its `$duration` property.
The `MigrationStarted`, `MigrationEnded`, and `MigrationFailed` events expose the migration filename through their `$name` property. The `MigrationEnded` event also exposes how long the migration took to run, in milliseconds, through its `$duration` property. The `MigrationFailed` event exposes the exception through its `$exception` property.
Loading
Loading