Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [6.0.0] - 2026-03-25

### Added
- `Database::EVENT_CACHE_READ_FAILURE` event constant, emitted when a cache load fails during a document read. Previously these failures incorrectly emitted `EVENT_CACHE_PURGE_FAILURE`, making it impossible to distinguish a read-side cache miss from a write-side purge failure.

### Changed
- Cache purge in `updateDocument` is now performed **outside** the database transaction. Previously a cache failure inside the transaction would roll back the committed write; now the DB write is always committed first and the cache is invalidated afterward (half-open / fail-open pattern).
- Cache purge in `deleteDocument` follows the same transactional ordering fix: the row is deleted inside the transaction and the cache entry is evicted only after the transaction commits.
- All event-listener invocations for cache-related events (`EVENT_CACHE_PURGE_FAILURE`, `EVENT_CACHE_READ_FAILURE`, `EVENT_DOCUMENT_PURGE`) are now wrapped in an inner `try/catch`. A listener that throws no longer propagates the exception up to the caller — the error is logged via `Console::error` and execution continues.

### Fixed
- `getDocument` no longer emits `EVENT_CACHE_PURGE_FAILURE` when the cache is unavailable for a read. It now correctly emits `EVENT_CACHE_READ_FAILURE`, so callers that distinguish the two events receive the right signal.
- A broken or unavailable cache can no longer cause `updateDocument` or `deleteDocument` to surface an exception to the caller. Both operations are now fully fail-open with respect to the cache layer.
- A throwing `EVENT_CACHE_PURGE_FAILURE` or `EVENT_CACHE_READ_FAILURE` listener can no longer abort an in-progress database operation.
- Fixed 6 `MariaDBTest` E2E tests that failed with `Incorrect table name` due to collection IDs derived from long method names exceeding MariaDB's 64-character identifier limit.

[Unreleased]: https://github.com/utopia-php/database/compare/6.0.0...HEAD
[6.0.0]: https://github.com/utopia-php/database/compare/5.3.17...6.0.0
59 changes: 47 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,28 +315,41 @@ $database->exists(
// Listen to events

// Event Types
Database::EVENT_ALL
Database::EVENT_DATABASE_CREATE,
Database::EVENT_ALL,
Database::EVENT_DATABASE_LIST,
Database::EVENT_COLLECTION_CREATE,
Database::EVENT_DATABASE_CREATE,
Database::EVENT_DATABASE_DELETE,
Database::EVENT_COLLECTION_LIST,
Database::EVENT_COLLECTION_CREATE,
Database::EVENT_COLLECTION_UPDATE,
Database::EVENT_COLLECTION_READ,
Database::EVENT_ATTRIBUTE_CREATE,
Database::EVENT_ATTRIBUTE_UPDATE,
Database::EVENT_INDEX_CREATE,
Database::EVENT_COLLECTION_DELETE,
Database::EVENT_DOCUMENT_FIND,
Database::EVENT_DOCUMENT_PURGE,
Database::EVENT_DOCUMENT_CREATE,
Database::EVENT_DOCUMENT_UPDATE,
Database::EVENT_DOCUMENTS_CREATE,
Database::EVENT_DOCUMENT_READ,
Database::EVENT_DOCUMENT_FIND,
Database::EVENT_DOCUMENT_UPDATE,
Database::EVENT_DOCUMENTS_UPDATE,
Database::EVENT_DOCUMENTS_UPSERT,
Database::EVENT_DOCUMENT_DELETE,
Database::EVENT_DOCUMENTS_DELETE,
Database::EVENT_DOCUMENT_COUNT,
Database::EVENT_DOCUMENT_SUM,
Database::EVENT_DOCUMENT_INCREASE,
Database::EVENT_DOCUMENT_DECREASE,
Database::EVENT_INDEX_DELETE,
Database::EVENT_DOCUMENT_DELETE,
Database::EVENT_PERMISSIONS_CREATE,
Database::EVENT_PERMISSIONS_READ,
Database::EVENT_PERMISSIONS_DELETE,
Database::EVENT_ATTRIBUTE_CREATE,
Database::EVENT_ATTRIBUTES_CREATE,
Database::EVENT_ATTRIBUTE_UPDATE,
Database::EVENT_ATTRIBUTE_DELETE,
Database::EVENT_COLLECTION_DELETE,
Database::EVENT_DATABASE_DELETE,
Database::EVENT_INDEX_RENAME,
Database::EVENT_INDEX_CREATE,
Database::EVENT_INDEX_DELETE,
Database::EVENT_CACHE_PURGE_FAILURE,
Database::EVENT_CACHE_READ_FAILURE,

$database->on(
Database::EVENT_ALL,
Expand Down Expand Up @@ -881,6 +894,28 @@ $database->purgeCachedDocument(

Utopia Framework requires PHP 8.0 or later. We recommend using the latest PHP version whenever possible.

## Testing

### Setup

`docker-compose up --detach`

### E2E

`docker compose exec tests vendor/bin/phpunit /usr/src/code/tests/e2e`

### Resources

`docker compose exec tests vendor/bin/phpunit /usr/src/code/tests/resources`

### Unit

`docker compose exec tests vendor/bin/phpunit /usr/src/code/tests/unit`

### Teardown

`docker-compose down`

## Contributing

Thank you for considering contributing to the Utopia Framework!
Expand Down
4 changes: 2 additions & 2 deletions bin/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

$cli = new CLI();

include 'tasks/load.php';
include 'tasks/index.php';
include 'tasks/load.php';
include 'tasks/operators.php';
include 'tasks/query.php';
include 'tasks/relationships.php';
include 'tasks/operators.php';

$cli
->error()
Expand Down
9 changes: 4 additions & 5 deletions dev/xdebug.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
zend_extension = xdebug.so

[xdebug]
xdebug.mode = develop,debug,profile
xdebug.start_with_request = yes
xdebug.use_compression=false
xdebug.client_host=host.docker.internal
xdebug.client_port = 9003
xdebug.log = /tmp/xdebug.log

xdebug.var_display_max_depth = 10
xdebug.mode = develop,debug,profile
xdebug.start_with_request = yes
xdebug.use_compression=false
xdebug.var_display_max_children = 256
xdebug.var_display_max_data = 4096
xdebug.var_display_max_depth = 10
Loading
Loading