diff --git a/config/services.yaml b/config/services.yaml index d900dfe6..70c8e967 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -78,6 +78,12 @@ services: - { name: doctrine.event_listener, event: prePersist, lazy: true } - { name: doctrine.event_listener, event: preUpdate, lazy: true } + # make sure, that sqlite supports foreign keys and cascade deletes + App\Doctrine\SqliteSessionInitSubscriber: + class: App\Doctrine\SqliteSessionInitSubscriber + tags: + - { name: doctrine.event_listener, event: postConnect } + # ================================================================================ # FORMS # ================================================================================ diff --git a/src/Doctrine/SqliteSessionInitSubscriber.php b/src/Doctrine/SqliteSessionInitSubscriber.php new file mode 100644 index 00000000..861c4962 --- /dev/null +++ b/src/Doctrine/SqliteSessionInitSubscriber.php @@ -0,0 +1,37 @@ +getDatabasePlatform()->getName())) { + return; + } + $args->getConnection()->executeUpdate('PRAGMA foreign_keys = ON;'); + } + + /** + * {@inheritdoc} + */ + public function getSubscribedEvents() + { + return [Events::postConnect]; + } +} diff --git a/var/docs/faq.md b/var/docs/faq.md index f9ec7aa3..16656a91 100644 --- a/var/docs/faq.md +++ b/var/docs/faq.md @@ -43,13 +43,6 @@ Further readings: - [MariaDB - JSON support was added with 10.2.7](https://mariadb.com/kb/en/library/json-data-type/) - [Using JSON fields with Doctrine ORM on PostgreSQL & MySQL](https://symfony.fi/entry/using-json-fields-with-doctrine-orm-on-postgresql-mysql) -## SQLite not recommended for production usage - -SQLite is a great database engine for testing, but when it comes to production usage it fails due to several reasons: - -- It does not support ALTER TABLE commands and makes update procedures very clunky and problematic (we still try to support updates, but they are heavy on large databases) -- It does not support FOREIGN KEY constraints [out of the box](https://www.sqlite.org/foreignkeys.html#fk_enable), which can lead to critical bugs when deleting users/activities/projects/customers - ## Dotenv::populate() must be an instance of Symfony\\Component\\Dotenv\\void If you encounter an error like this: diff --git a/var/docs/installation.md b/var/docs/installation.md index 53a55ede..69174bce 100644 --- a/var/docs/installation.md +++ b/var/docs/installation.md @@ -29,13 +29,13 @@ chmod -R g+rw var/ cp .env.dist .env ``` -It's up to you which database server you want to use, Kimai v2 supports MySQL/MariaDB and SQLite, but SQLite is [not recommended](faq.md) for production usage. -Configure the database connection string in your the `.env` file: +Configure the database connection string in your the `.env` file (Kimai v2 supports MySQL/MariaDB and SQLite): ``` # adjust all settings in .env to your needs APP_ENV=prod DATABASE_URL=mysql://user:password@127.0.0.1:3306/database ``` +SQLite is not recommended for production usage, check FAQ below. Now install all dependencies for Kimai 2: ```bash @@ -209,6 +209,16 @@ npm run prod ## FAQ and common problems +## SQLite not recommended for production usage + +SQLite is a great database engine for testing, but when it comes to production usage it is imperfect due to several reasons: + +- It does not support ALTER TABLE commands and makes update procedures very clunky and problematic (we still try to support updates, but they are heavy on large databases) +- It does [not support FOREIGN KEY](https://www.sqlite.org/quirks.html#foreign_key_enforcement_is_off_by_default) constraints [out of the box](https://www.sqlite.org/foreignkeys.html#fk_enable), which can lead to critical bugs when deleting users/activities/projects/customers + +Kimai works around the Foreign Keys issue by using a [Doctrine PostConnect EventSubscriber]({{ site.kimai_v2_file }}/src/Doctrine/SqliteSessionInitSubscriber.php) since v0.8.1, +but it is not guaranteed that SQLite handles everything as expected. + ### Malformed parameter "url" If you see an error message like this, then you have a special character in your DATABASE_URL.