Skip to content

Conversation

@erseco
Copy link
Collaborator

@erseco erseco commented Oct 7, 2025

This pull request introduces a new Doctrine middleware to automatically tune SQLite connections for better concurrent performance in development environments. The middleware applies several PRAGMA settings to SQLite connections, and its behavior is covered by new integration tests. Configuration files are updated to enable the middleware and improve transaction handling.

SQLite Middleware and Configuration Improvements

  • Added SqlitePragmaMiddleware in src/Doctrine/Middleware/SqlitePragmaMiddleware.php, which applies optimized PRAGMA directives (WAL mode, busy timeout, foreign keys, etc.) to all SQLite connections for improved concurrency and reliability.
  • Registered the middleware in the Symfony service container (config/services.yaml) so it is automatically applied to all Doctrine connections.

Doctrine Configuration Enhancements

  • Enabled use_savepoints in config/packages/doctrine.yaml to improve transaction handling, especially for nested transactions in SQLite.

Testing for Middleware Behavior

  • Added SqlitePragmaMiddlewareTest in tests/Integration/Doctrine/SqlitePragmaMiddlewareTest.php to verify that the middleware applies the correct PRAGMA settings and supports concurrent writers without lock errors.

IMPORTANT! Integrity fixes detected and resolved

During integration testing with the new SQLite middleware, several integrity constraint issues were detected in entity relationships (mainly missing cascading deletes).
These have been fixed by adding onDelete="CASCADE" to the relevant associations, ensuring consistent cleanup of related entities and preventing orphaned records.

@erseco erseco requested a review from ignaciogros October 7, 2025 10:25
@erseco erseco linked an issue Oct 7, 2025 that may be closed by this pull request
@erseco erseco self-assigned this Oct 7, 2025
@erseco erseco added the enhancement New feature or request label Oct 7, 2025
@erseco
Copy link
Collaborator Author

erseco commented Oct 7, 2025

This change helped to detect some integrity constraint violations
Captura de pantalla 2025-10-07 a las 11 44 22

@eXeLearningProject eXeLearningProject merged commit 84d565d into main Oct 9, 2025
4 checks passed
@eXeLearningProject eXeLearningProject deleted the 361-improve-sqlite-performance-under-concurrent-writes branch October 9, 2025 06:40
erseco added a commit to ateeducacion/exelearning that referenced this pull request Nov 20, 2025
* Added some options to improve performance on sqlite

* Fix some cascading errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve SQLite performance under concurrent writes

5 participants