SonataMediaBundle icon indicating copy to clipboard operation
SonataMediaBundle copied to clipboard

Migration always generated for the "providerMetadata" field with MySQL

Open JudicaelR opened this issue 1 year ago • 5 comments

Environment

Sonata packages

show

$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle              4.12.0 4.14.0 The missing Symfony Admin Generator
sonata-project/block-bundle              4.12.0 4.14.0 Symfony SonataBlockBundle
sonata-project/cache                     2.2.0  2.2.0  Cache library
Package sonata-project/cache is abandoned, you should avoid using it. No replacement was suggested.
sonata-project/doctrine-extensions       1.16.0 1.17.0 Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 4.2.8  4.3.1  Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  2.11.0 2.13.0 Lightweight Exporter library
sonata-project/form-extensions           1.16.1 1.17.1 Symfony form extensions
sonata-project/media-bundle              4.1.5  4.4.0  Symfony SonataMediaBundle
sonata-project/twig-extensions           1.9.1  1.10.0 Sonata twig extensions
sonata-project/user-bundle               5.1.0  5.3.0  Symfony SonataUserBundle

Symfony packages

show

$ composer show --latest 'symfony/*'
symfony/acl-bundle                 v2.3.0  v2.3.0  Symfony AclBundle
symfony/asset                      v5.4.7  v6.1.0  Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files
symfony/browser-kit                v5.4.3  v6.1.0  Simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms programmatically
symfony/cache                      v5.4.8  v6.1.2  Provides an extended PSR-6, PSR-16 (and tags) implementation
symfony/cache-contracts            v2.5.1  v3.1.1  Generic abstractions related to caching
symfony/config                     v5.4.8  v6.1.0  Helps you find, load, combine, autofill and validate configuration values of any kind
symfony/console                    v5.4.8  v6.1.2  Eases the creation of beautiful and testable command line interfaces
symfony/dependency-injection       v5.4.8  v6.1.2  Allows you to standardize and centralize the way objects are constructed in your application
symfony/deprecation-contracts      v3.1.0  v3.1.1  A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge            v5.4.8  v6.1.2  Provides integration for Doctrine with various Symfony components
symfony/dom-crawler                v5.4.6  v6.1.0  Eases DOM navigation for HTML and XML documents
symfony/dotenv                     v5.4.5  v6.1.0  Registers environment variables from a .env file
symfony/error-handler              v5.4.8  v6.1.0  Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher           v5.4.3  v6.1.0  Provides tools that allow your application components to communicate with each other by dispatching events and listening to them
symfony/event-dispatcher-contracts v2.5.1  v3.1.1  Generic abstractions related to dispatching event
symfony/expression-language        v5.4.8  v6.1.2  Provides an engine that can compile and evaluate expressions
symfony/filesystem                 v5.4.7  v6.1.0  Provides basic utilities for the filesystem
symfony/finder                     v5.4.8  v6.1.0  Finds files and directories via an intuitive fluent interface
symfony/flex                       v1.18.7 v2.2.2  Composer plugin for Symfony
symfony/form                       v5.4.8  v6.1.2  Allows to easily create, process and reuse HTML forms
symfony/framework-bundle           v5.4.8  v6.1.2  Provides a tight integration between Symfony components and the Symfony full-stack framework
symfony/http-client                v5.4.8  v6.1.2  Provides powerful methods to fetch HTTP resources synchronously or asynchronously
symfony/http-client-contracts      v2.5.1  v3.1.1  Generic abstractions related to HTTP clients
symfony/http-foundation            v5.4.8  v6.1.2  Defines an object-oriented layer for the HTTP specification
symfony/http-kernel                v5.4.8  v6.1.2  Provides a structured process for converting a Request into a Response
symfony/intl                       v5.4.8  v6.1.0  Provides a PHP replacement layer for the C intl extension that includes additional data from the ICU library
symfony/lock                       v5.4.7  v6.1.1  Creates and manages locks, a mechanism to provide exclusive access to a shared resource
symfony/mailer                     v5.4.8  v6.1.2  Helps sending emails
symfony/maker-bundle               v1.41.0 v1.43.0 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.
symfony/mime                       v5.4.8  v6.1.1  Allows manipulating MIME messages
symfony/monolog-bridge             v5.4.3  v6.1.2  Provides integration for Monolog with various Symfony components
symfony/monolog-bundle             v3.7.1  v3.8.0  Symfony MonologBundle
symfony/options-resolver           v5.4.3  v6.1.0  Provides an improved replacement for the array_replace PHP function
symfony/password-hasher            v5.4.8  v6.1.0  Provides password hashing utilities
symfony/phpunit-bridge             v6.0.8  v6.1.2  Provides utilities for PHPUnit, especially user deprecation notices management
symfony/polyfill-intl-grapheme     v1.25.0 v1.26.0 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-normalizer   v1.25.0 v1.26.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/process                    v5.4.8  v6.1.0  Executes commands in sub-processes
symfony/property-access            v5.4.8  v6.1.0  Provides functions to read and write from/to an object or array using a simple string notation
symfony/property-info              v5.4.7  v6.1.2  Extracts information about PHP class' properties using metadata of popular sources
symfony/proxy-manager-bridge       v5.4.6  v6.1.0  Provides integration for ProxyManager with various Symfony components
symfony/routing                    v5.4.8  v6.1.1  Maps an HTTP request to a set of configuration variables
symfony/security-acl               v3.3.1  v3.3.1  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle            v5.4.8  v6.1.0  Provides a tight integration of the Security component into the Symfony full-stack framework
symfony/security-core              v5.4.8  v6.1.2  Symfony Security Component - Core Library
symfony/security-csrf              v5.4.3  v6.1.0  Symfony Security Component - CSRF Library
symfony/security-guard             v5.4.3  v5.4.9  Symfony Security Component - Guard
symfony/security-http              v5.4.8  v6.1.2  Symfony Security Component - HTTP Integration
symfony/sendgrid-mailer            v5.4.7  v6.1.0  Symfony Sendgrid Mailer Bridge
symfony/serializer                 v5.4.8  v6.1.2  Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON.
symfony/service-contracts          v2.5.1  v3.1.1  Generic abstractions related to writing services
symfony/stopwatch                  v5.4.5  v6.1.0  Provides a way to profile code
symfony/string                     v5.4.8  v6.1.2  Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way
symfony/translation                v5.4.8  v6.1.0  Provides tools to internationalize your application
symfony/translation-contracts      v2.5.1  v3.1.1  Generic abstractions related to translation
symfony/twig-bridge                v5.4.8  v6.1.2  Provides integration for Twig with various Symfony components
symfony/twig-bundle                v5.4.8  v6.1.1  Provides a tight integration of Twig into the Symfony full-stack framework
symfony/validator                  v5.4.8  v6.1.1  Provides tools to validate values
symfony/var-dumper                 v5.4.8  v6.1.0  Provides mechanisms for walking through any arbitrary PHP variable
symfony/var-exporter               v5.4.8  v6.1.1  Allows exporting any serializable PHP data structure to plain PHP code
symfony/web-profiler-bundle        v5.4.8  v6.1.2  Provides a development tool that gives detailed information about the execution of any request
symfony/yaml                       v5.4.3  v6.1.2  Loads and dumps YAML files

Doctrine packages

show

$ composer show --latest 'doctrine/*'
doctrine/annotations                1.13.2 1.13.3 Docblock Annotations Parser
doctrine/cache                      2.1.1  2.2.0  PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.
doctrine/collections                1.6.8  1.6.8  PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.
doctrine/common                     3.3.0  3.3.0  PHP Doctrine Common project is a library that provides additional functionality that other Doctrine projects depend on such as better reflection support, proxies and much more.
doctrine/data-fixtures              1.5.3  1.5.3  Data Fixtures for all Doctrine Object Managers
doctrine/dbal                       2.13.9 3.3.7  Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.
doctrine/deprecations               v0.5.3 v1.0.0 A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.
doctrine/doctrine-bundle            2.6.3  2.7.0  Symfony DoctrineBundle
doctrine/doctrine-fixtures-bundle   3.4.2  3.4.2  Symfony DoctrineFixturesBundle
doctrine/doctrine-migrations-bundle 3.2.2  3.2.2  Symfony DoctrineMigrationsBundle
doctrine/event-manager              1.1.1  1.1.1  The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.
doctrine/inflector                  2.0.4  2.0.4  PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words.
doctrine/instantiator               1.4.1  1.4.1  A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                      1.2.3  1.2.3  PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                 3.4.2  3.5.1  PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily deploying changes to it. It is a very easy to use and a powerful tool.
doctrine/orm                        2.12.2 2.12.3 Object-Relational-Mapper for PHP
doctrine/persistence                2.5.2  3.0.2  The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doctrine object mappers share.
doctrine/sql-formatter              1.1.3  1.1.3  a PHP SQL highlighting library

PHP version

$ php -v
PHP 8.1.5 (cli) (built: May 11 2022 13:06:14) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.5, Copyright (c), by Zend Technologies
    with Xdebug v3.1.4, Copyright (c) 2002-2022, by Derick Rethans

MySQL version

$ mysql --version
mysql  Ver 8.0.23 for Linux on x86_64 (MySQL Community Server - GPL)

Subject

On a project I am currently working on, I notice something strange with this merged PR: https://github.com/sonata-project/SonataMediaBundle/pull/2267.

The same migration is always generated. Even if I run it, the command always regenerates it and always with the same request to update and downgrade the schema (The same request as the one in the ticket by the way).

I tried to remove the option added on the "providerMetadata" field and this migration is not present anymore.

Minimal repository with the bug

Steps to reproduce

  • Generate a migration :
bin/console doctrine:migrations:diff --formatted
  • Apply migration :
bin/api doctrine:migrations:migrate
  • Generate a new migration :
bin/console doctrine:migrations:diff --formatted

The new migration is strictly similar at the previous one

Expected results

This migration should be generated once only.

Actual results

Generated migration :

public function up(Schema $schema): void  
{  
    // this up() migration is auto-generated, please modify it to your needs  
    $this->addSql('ALTER TABLE media__media CHANGE provider_metadata provider_metadata JSON DEFAULT NULL');  
}  
  
public function down(Schema $schema): void  
{  
    // this down() migration is auto-generated, please modify it to your needs  
    $this->addSql('ALTER TABLE media__media CHANGE provider_metadata provider_metadata JSON DEFAULT NULL');  
}

JudicaelR avatar Jul 13 '22 13:07 JudicaelR

How can we do this then? On postgresql the option is needed. Do you know an alternative? Wdyt @VincentLanglet ?

Maybe this issue could be open on the migrations repository (or dbal, not sure which one is responsable for this behavior).

jordisala1991 avatar Jul 13 '22 13:07 jordisala1991

I understood in https://github.com/sonata-project/SonataMediaBundle/pull/2267 that it was working fine for @lukepass i'm curious to know if he always have the migration too.

But yeah, might be worth to ask directly to the doctrine/migration/dbal repository any help (cc @greg0ire)

VincentLanglet avatar Jul 13 '22 13:07 VincentLanglet

From a discussion I read about options that cause diff problem they pretty much said that they would not fix the diff to support all options. The problem is that the diff tools will see the options from the schema configuration but will not have any from the database schema so it will always have a diff. Probably the schema should be modify via an event listener if you are on a postgress database.

mpoiriert avatar Jul 13 '22 17:07 mpoiriert

Have the same issue with media-bundle 4.4 and Symfony 5.4

doctrine:migrations:diff always generates a migration same as JudicaelR's

Even though I executed this migration, migrations:diff keeps generating the migration over and over

sonofodinn1 avatar Jul 14 '22 09:07 sonofodinn1

bug still remains on media bundle 4.5.0

as for now, I use doctrine schema_filter as a workaround

sonofodinn1 avatar Aug 08 '22 07:08 sonofodinn1

I have this too with mariadb 10.7.4 and 10.7.6. ALTER TABLE media__media CHANGE provider_metadata provider_metadata LONGTEXT DEFAULT NULL COMMENT '(DC2Type:json)';

haivala avatar Sep 27 '22 21:09 haivala

I just upgraded: "doctrine/doctrine-migrations-bundle": "^2", to "doctrine/doctrine-migrations-bundle": "^3", and migration is not generated anymore.

haivala avatar Sep 28 '22 07:09 haivala

I just upgraded: "doctrine/doctrine-migrations-bundle": "^2", to "doctrine/doctrine-migrations-bundle": "^3", and migration is not generated anymore.

Kinda weird since the issue was opened with

doctrine/doctrine-migrations-bundle 3.2.2  3.2.2

It would be interesting to be sure which package/version solve the issue.

VincentLanglet avatar Sep 28 '22 08:09 VincentLanglet

These are the packages that upgraded with it

  - Upgrading doctrine/dbal (2.13.9 => 3.4.5)
  - Upgrading doctrine/doctrine-migrations-bundle (2.2.3 => 3.2.2)
  - Upgrading doctrine/migrations (2.3.5 => 3.5.2)

haivala avatar Sep 28 '22 08:09 haivala

Maybe it's dbal... Dunno.

Let's close this and wait for someone reporting it again with latest version.

VincentLanglet avatar Sep 28 '22 08:09 VincentLanglet