Skip to content

Add mariadb example to DATABASE_URL #1186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 28, 2023

Conversation

alexander-schranz
Copy link
Contributor

@alexander-schranz alexander-schranz commented Mar 20, 2023

Q A
License MIT
Doc issue/PR symfony/symfony-docs#...

I did see in the past a lot of misconfigured versions strings for users which did use @sulu with mariadb and run into an SQL error because they did not configure the mariadb version string instead used mysql version. Think it would make sense to have also mariadb as an example beside mysql and sqlite.

Related PRs: doctrine/dbal#5971

@symfony-recipes-bot symfony-recipes-bot enabled auto-merge (squash) March 20, 2023 13:00
@github-actions
Copy link

github-actions bot commented Mar 20, 2023

Thanks for the PR 😍

How to test these changes in your application

  1. Define the SYMFONY_ENDPOINT environment variable:

    # On Unix-like (BSD, Linux and macOS)
    export SYMFONY_ENDPOINT=https://raw.githubusercontent.com/symfony/recipes/flex/pull-1186/index.json
    # On Windows
    SET SYMFONY_ENDPOINT=https://raw.githubusercontent.com/symfony/recipes/flex/pull-1186/index.json
  2. Install the package(s) related to this recipe:

    composer req 'symfony/flex:^1.16'
    composer req 'doctrine/doctrine-bundle:^2.8'
  3. Don't forget to unset the SYMFONY_ENDPOINT environment variable when done:

    # On Unix-like (BSD, Linux and macOS)
    unset SYMFONY_ENDPOINT
    # On Windows
    SET SYMFONY_ENDPOINT=

Diff between recipe versions

In order to help with the review stage, I'm in charge of computing the diff between the various versions of patched recipes.
I'm going keep this comment up to date with any updates of the attached patch.

doctrine/doctrine-bundle

1.6 vs 1.12
diff --git a/doctrine/doctrine-bundle/1.6/config/packages/doctrine.yaml b/doctrine/doctrine-bundle/1.12/config/packages/doctrine.yaml
index a8e2ebc..802b218 100644
--- a/doctrine/doctrine-bundle/1.6/config/packages/doctrine.yaml
+++ b/doctrine/doctrine-bundle/1.12/config/packages/doctrine.yaml
@@ -10,9 +10,12 @@ doctrine:
         charset: utf8mb4
         default_table_options:
             collate: utf8mb4_unicode_ci
+
+        # backtrace queries in profiler (increases memory usage per request)
+        #profiling_collect_backtrace: '%kernel.debug%'
     orm:
         auto_generate_proxy_classes: true
-        naming_strategy: doctrine.orm.naming_strategy.underscore
+        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
         auto_mapping: true
         mappings:
             App:
diff --git a/doctrine/doctrine-bundle/1.6/config/packages/prod/doctrine.yaml b/doctrine/doctrine-bundle/1.12/config/packages/prod/doctrine.yaml
index 0a7c53b..084f59a 100644
--- a/doctrine/doctrine-bundle/1.6/config/packages/prod/doctrine.yaml
+++ b/doctrine/doctrine-bundle/1.12/config/packages/prod/doctrine.yaml
@@ -2,26 +2,14 @@ doctrine:
     orm:
         auto_generate_proxy_classes: false
         metadata_cache_driver:
-            type: service
-            id: doctrine.system_cache_provider
+            type: pool
+            pool: doctrine.system_cache_pool
         query_cache_driver:
-            type: service
-            id: doctrine.system_cache_provider
+            type: pool
+            pool: doctrine.system_cache_pool
         result_cache_driver:
-            type: service
-            id: doctrine.result_cache_provider
-
-services:
-    doctrine.result_cache_provider:
-        class: Symfony\Component\Cache\DoctrineProvider
-        public: false
-        arguments:
-            - '@doctrine.result_cache_pool'
-    doctrine.system_cache_provider:
-        class: Symfony\Component\Cache\DoctrineProvider
-        public: false
-        arguments:
-            - '@doctrine.system_cache_pool'
+            type: pool
+            pool: doctrine.result_cache_pool
 
 framework:
     cache:
diff --git a/doctrine/doctrine-bundle/1.6/manifest.json b/doctrine/doctrine-bundle/1.12/manifest.json
index dca9096..754bce8 100644
--- a/doctrine/doctrine-bundle/1.6/manifest.json
+++ b/doctrine/doctrine-bundle/1.12/manifest.json
@@ -11,8 +11,8 @@
         "#2": "IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml",
         "#3": "",
         "#4": "DATABASE_URL=\"sqlite:///%kernel.project_dir%/var/data.db\"",
-        "#5": "DATABASE_URL=\"mysql://app:[email protected]:3306/app?serverVersion=8\"",
-        "DATABASE_URL": "postgresql://app:[email protected]:5432/app?serverVersion=15&charset=utf8"
+        "#5": "DATABASE_URL=\"mysql://app:[email protected]:3306/db_name?serverVersion=8\"",
+        "DATABASE_URL": "postgresql://app:[email protected]:5432/db_name?serverVersion=15&charset=utf8"
     },
     "dockerfile": [
         "RUN apk add --no-cache --virtual .pgsql-deps postgresql-dev && \\",
1.12 vs 2.0
diff --git a/doctrine/doctrine-bundle/1.12/config/packages/doctrine.yaml b/doctrine/doctrine-bundle/2.0/config/packages/doctrine.yaml
index 802b218..8e337f7 100644
--- a/doctrine/doctrine-bundle/1.12/config/packages/doctrine.yaml
+++ b/doctrine/doctrine-bundle/2.0/config/packages/doctrine.yaml
@@ -5,14 +5,6 @@ doctrine:
         # IMPORTANT: You MUST configure your server version,
         # either here or in the DATABASE_URL env var (see .env file)
         #server_version: '15'
-
-        # only needed for MySQL
-        charset: utf8mb4
-        default_table_options:
-            collate: utf8mb4_unicode_ci
-
-        # backtrace queries in profiler (increases memory usage per request)
-        #profiling_collect_backtrace: '%kernel.debug%'
     orm:
         auto_generate_proxy_classes: true
         naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
diff --git a/doctrine/doctrine-bundle/1.12/manifest.json b/doctrine/doctrine-bundle/2.0/manifest.json
index 754bce8..dca9096 100644
--- a/doctrine/doctrine-bundle/1.12/manifest.json
+++ b/doctrine/doctrine-bundle/2.0/manifest.json
@@ -11,8 +11,8 @@
         "#2": "IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml",
         "#3": "",
         "#4": "DATABASE_URL=\"sqlite:///%kernel.project_dir%/var/data.db\"",
-        "#5": "DATABASE_URL=\"mysql://app:[email protected]:3306/db_name?serverVersion=8\"",
-        "DATABASE_URL": "postgresql://app:[email protected]:5432/db_name?serverVersion=15&charset=utf8"
+        "#5": "DATABASE_URL=\"mysql://app:[email protected]:3306/app?serverVersion=8\"",
+        "DATABASE_URL": "postgresql://app:[email protected]:5432/app?serverVersion=15&charset=utf8"
     },
     "dockerfile": [
         "RUN apk add --no-cache --virtual .pgsql-deps postgresql-dev && \\",
2.0 vs 2.3
diff --git a/doctrine/doctrine-bundle/2.0/config/packages/prod/doctrine.yaml b/doctrine/doctrine-bundle/2.3/config/packages/prod/doctrine.yaml
index 084f59a..17299e2 100644
--- a/doctrine/doctrine-bundle/2.0/config/packages/prod/doctrine.yaml
+++ b/doctrine/doctrine-bundle/2.3/config/packages/prod/doctrine.yaml
@@ -1,9 +1,6 @@
 doctrine:
     orm:
         auto_generate_proxy_classes: false
-        metadata_cache_driver:
-            type: pool
-            pool: doctrine.system_cache_pool
         query_cache_driver:
             type: pool
             pool: doctrine.system_cache_pool
diff --git a/doctrine/doctrine-bundle/2.3/config/packages/test/doctrine.yaml b/doctrine/doctrine-bundle/2.3/config/packages/test/doctrine.yaml
new file mode 100644
index 0000000..2ace640
--- /dev/null
+++ b/doctrine/doctrine-bundle/2.3/config/packages/test/doctrine.yaml
@@ -0,0 +1,4 @@
+doctrine:
+    dbal:
+        # "TEST_TOKEN" is typically set by ParaTest
+        dbname: 'main_test%env(default::TEST_TOKEN)%'
diff --git a/doctrine/doctrine-bundle/2.0/manifest.json b/doctrine/doctrine-bundle/2.3/manifest.json
index dca9096..f673cbc 100644
--- a/doctrine/doctrine-bundle/2.0/manifest.json
+++ b/doctrine/doctrine-bundle/2.3/manifest.json
@@ -11,13 +11,13 @@
         "#2": "IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml",
         "#3": "",
         "#4": "DATABASE_URL=\"sqlite:///%kernel.project_dir%/var/data.db\"",
-        "#5": "DATABASE_URL=\"mysql://app:[email protected]:3306/app?serverVersion=8\"",
+        "#5": "DATABASE_URL=\"mysql://app:[email protected]:3306/app?serverVersion=8&charset=utf8mb4\"",
         "DATABASE_URL": "postgresql://app:[email protected]:5432/app?serverVersion=15&charset=utf8"
     },
     "dockerfile": [
-        "RUN apk add --no-cache --virtual .pgsql-deps postgresql-dev && \\",
-        "\tdocker-php-ext-install -j$(nproc) pdo_pgsql && \\",
-        "\tapk add --no-cache --virtual .pgsql-rundeps so:libpq.so.5 && \\",
+        "RUN apk add --no-cache --virtual .pgsql-deps postgresql-dev; \\",
+        "\tdocker-php-ext-install -j$(nproc) pdo_pgsql; \\",
+        "\tapk add --no-cache --virtual .pgsql-rundeps so:libpq.so.5; \\",
         "\tapk del .pgsql-deps"
     ],
     "docker-compose": {
2.3 vs 2.4
diff --git a/doctrine/doctrine-bundle/2.3/config/packages/doctrine.yaml b/doctrine/doctrine-bundle/2.4/config/packages/doctrine.yaml
index 8e337f7..1bb885e 100644
--- a/doctrine/doctrine-bundle/2.3/config/packages/doctrine.yaml
+++ b/doctrine/doctrine-bundle/2.4/config/packages/doctrine.yaml
@@ -12,7 +12,32 @@ doctrine:
         mappings:
             App:
                 is_bundle: false
-                type: annotation
                 dir: '%kernel.project_dir%/src/Entity'
                 prefix: 'App\Entity'
                 alias: App
+
+when@test:
+    doctrine:
+        dbal:
+            # "TEST_TOKEN" is typically set by ParaTest
+            dbname_suffix: '_test%env(default::TEST_TOKEN)%'
+
+when@prod:
+    doctrine:
+        orm:
+            auto_generate_proxy_classes: false
+            proxy_dir: '%kernel.build_dir%/doctrine/orm/Proxies'
+            query_cache_driver:
+                type: pool
+                pool: doctrine.system_cache_pool
+            result_cache_driver:
+                type: pool
+                pool: doctrine.result_cache_pool
+
+    framework:
+        cache:
+            pools:
+                doctrine.result_cache_pool:
+                    adapter: cache.app
+                doctrine.system_cache_pool:
+                    adapter: cache.system
diff --git a/doctrine/doctrine-bundle/2.3/config/packages/prod/doctrine.yaml b/doctrine/doctrine-bundle/2.3/config/packages/prod/doctrine.yaml
deleted file mode 100644
index 17299e2..0000000
--- a/doctrine/doctrine-bundle/2.3/config/packages/prod/doctrine.yaml
+++ /dev/null
@@ -1,17 +0,0 @@
-doctrine:
-    orm:
-        auto_generate_proxy_classes: false
-        query_cache_driver:
-            type: pool
-            pool: doctrine.system_cache_pool
-        result_cache_driver:
-            type: pool
-            pool: doctrine.result_cache_pool
-
-framework:
-    cache:
-        pools:
-            doctrine.result_cache_pool:
-                adapter: cache.app
-            doctrine.system_cache_pool:
-                adapter: cache.system
diff --git a/doctrine/doctrine-bundle/2.3/config/packages/test/doctrine.yaml b/doctrine/doctrine-bundle/2.3/config/packages/test/doctrine.yaml
deleted file mode 100644
index 2ace640..0000000
--- a/doctrine/doctrine-bundle/2.3/config/packages/test/doctrine.yaml
+++ /dev/null
@@ -1,4 +0,0 @@
-doctrine:
-    dbal:
-        # "TEST_TOKEN" is typically set by ParaTest
-        dbname: 'main_test%env(default::TEST_TOKEN)%'
diff --git a/doctrine/doctrine-bundle/2.3/manifest.json b/doctrine/doctrine-bundle/2.4/manifest.json
index f673cbc..472f48f 100644
--- a/doctrine/doctrine-bundle/2.3/manifest.json
+++ b/doctrine/doctrine-bundle/2.4/manifest.json
@@ -44,5 +44,8 @@
                 "    - \"5432\""
             ]
         }
+    },
+    "conflict": {
+        "symfony/framework-bundle": "<5.3"
     }
 }
2.4 vs 2.8
diff --git a/doctrine/doctrine-bundle/2.4/config/packages/doctrine.yaml b/doctrine/doctrine-bundle/2.8/config/packages/doctrine.yaml
index 1bb885e..bdff96f 100644
--- a/doctrine/doctrine-bundle/2.4/config/packages/doctrine.yaml
+++ b/doctrine/doctrine-bundle/2.8/config/packages/doctrine.yaml
@@ -7,6 +7,7 @@ doctrine:
         #server_version: '15'
     orm:
         auto_generate_proxy_classes: true
+        enable_lazy_ghost_objects: true
         naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
         auto_mapping: true
         mappings:
diff --git a/doctrine/doctrine-bundle/2.4/manifest.json b/doctrine/doctrine-bundle/2.8/manifest.json
index 472f48f..fc8c043 100644
--- a/doctrine/doctrine-bundle/2.4/manifest.json
+++ b/doctrine/doctrine-bundle/2.8/manifest.json
@@ -11,12 +11,13 @@
         "#2": "IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml",
         "#3": "",
         "#4": "DATABASE_URL=\"sqlite:///%kernel.project_dir%/var/data.db\"",
-        "#5": "DATABASE_URL=\"mysql://app:[email protected]:3306/app?serverVersion=8&charset=utf8mb4\"",
+        "#5": "DATABASE_URL=\"mysql://app:[email protected]:3306/app?serverVersion=8.0.32&charset=utf8mb4\"",
+        "#6": "DATABASE_URL=\"mysql://app:[email protected]:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4\"",
         "DATABASE_URL": "postgresql://app:[email protected]:5432/app?serverVersion=15&charset=utf8"
     },
     "dockerfile": [
         "RUN apk add --no-cache --virtual .pgsql-deps postgresql-dev; \\",
-        "\tdocker-php-ext-install -j$(nproc) pdo_pgsql; \\",
+        "\tdocker-php-ext-install -j\"$(nproc)\" pdo_pgsql; \\",
         "\tapk add --no-cache --virtual .pgsql-rundeps so:libpq.so.5; \\",
         "\tapk del .pgsql-deps"
     ],
@@ -46,6 +47,8 @@
         }
     },
     "conflict": {
+        "doctrine/orm": "<2.14",
+        "symfony/dependency-injection": "<6.2",
         "symfony/framework-bundle": "<5.3"
     }
 }

@nicolas-grekas
Copy link
Member

It'd be nice to support mariadb:// URls and do this trick under the hood...

@@ -11,7 +11,8 @@
"#2": "IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml",
"#3": "",
"#4": "DATABASE_URL=\"sqlite:///%kernel.project_dir%/var/data.db\"",
"#5": "DATABASE_URL=\"mysql://app:[email protected]:3306/app?serverVersion=8&charset=utf8mb4\"",
"#5": "DATABASE_URL=\"mysql://app:[email protected]:3306/app?serverVersion=mariadb-10.11&charset=utf8mb4\"",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should specify the version as the server would report it, otherwise later versions of DBAL will fail to parse it.

Suggested change
"#5": "DATABASE_URL=\"mysql://app:[email protected]:3306/app?serverVersion=mariadb-10.11&charset=utf8mb4\"",
"#5": "DATABASE_URL=\"mysql://app:[email protected]:3306/app?serverVersion=10.11.2-mariadb&charset=utf8mb4\"",

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the DBAL docs are outdated in that regard.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, didn't know that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -11,7 +11,8 @@
"#2": "IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml",
"#3": "",
"#4": "DATABASE_URL=\"sqlite:///%kernel.project_dir%/var/data.db\"",
"#5": "DATABASE_URL=\"mysql://app:[email protected]:3306/app?serverVersion=8&charset=utf8mb4\"",
"#5": "DATABASE_URL=\"mysql://app:[email protected]:3306/app?serverVersion=mariadb-10.11&charset=utf8mb4\"",
"#6": "DATABASE_URL=\"mysql://app:[email protected]:3306/app?serverVersion=8&charset=utf8mb4\"",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oracle is rolling out new features in MySQL 8.0.X releases nowadays, so it's a good practice to specify the full version.

Suggested change
"#6": "DATABASE_URL=\"mysql://app:[email protected]:3306/app?serverVersion=8&charset=utf8mb4\"",
"#6": "DATABASE_URL=\"mysql://app:[email protected]:3306/app?serverVersion=8.0.32&charset=utf8mb4\"",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always fan of full version 👍 . Should we specifiy it also for postgresql?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we specifiy it also for postgresql?

We can do this for the sake of consistency, but since Postgres implements a much saner versioning policy, it's not really necessary.

auto-merge was automatically disabled March 20, 2023 13:58

Head branch was pushed to by a user without write access

@symfony-recipes-bot symfony-recipes-bot enabled auto-merge (squash) March 20, 2023 13:58
auto-merge was automatically disabled March 20, 2023 14:05

Head branch was pushed to by a user without write access

@symfony-recipes-bot symfony-recipes-bot enabled auto-merge (squash) March 20, 2023 14:05
derrabus
derrabus previously approved these changes Mar 20, 2023
auto-merge was automatically disabled March 20, 2023 14:27

Head branch was pushed to by a user without write access

derrabus
derrabus previously approved these changes Mar 20, 2023
"DATABASE_URL": "postgresql://app:[email protected]:5432/app?serverVersion=15&charset=utf8"
"#5": "DATABASE_URL=\"mysql://app:[email protected]:3306/app?serverVersion=8.0.32&charset=utf8mb4\"",
"#6": "DATABASE_URL=\"mysql://app:[email protected]:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4\"",
"DATABASE_URL": "postgresql://app:[email protected]:5432/app?serverVersion=15.2&charset=utf8"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using "full" version looks pretty annoying to me. It means you need to be sure you keep this in sync with your DB version. Is it really needed for all platforms?

Copy link
Contributor Author

@alexander-schranz alexander-schranz Mar 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Atleast for mysql there is a version_compare for 5.7.9:

And for mariadb a version_compare on 10.2.7:

On the doctrine dbal createDatabasePlatformForVersion method. So there make it sense to define it from my point of view.

We could remove it from postgresql currently? @derrabus what do you think, is that still future proof?

PS: Currently Symfony CLI Local Webserver overwrites the DATABASE_URL with a value without ?serverVersion which ends in unexpected errors for application require the ?serverVersion to be defined correctly: symfony-cli/symfony-cli#108

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For MySQL flavors we do need the full version. Oracle keeps shipping features and deprecating stuff in 8.0.x releases, unfortunately.

auto-merge was automatically disabled March 27, 2023 14:12

Head branch was pushed to by a user without write access

@symfony-recipes-bot symfony-recipes-bot enabled auto-merge (squash) March 27, 2023 14:12
@alexander-schranz
Copy link
Contributor Author

How should we proceed here?

@symfony-recipes-bot symfony-recipes-bot merged commit e0f64df into symfony:main Apr 28, 2023
@alexander-schranz alexander-schranz deleted the patch-3 branch April 28, 2023 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants