-
-
Notifications
You must be signed in to change notification settings - Fork 388
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
doctrine:schema:validate returns DROP TABLE doctrine_migration_versions; #1406
doctrine:schema:validate returns DROP TABLE doctrine_migration_versions; #1406
Comments
+1:
|
Somebody posted a workaround for Symfony applications relying on the Doctrine bundle: doctrine:
dbal:
schema_filter: ~^(?!doctrine_)~ Can people here please test? |
|
Possible next steps:
|
The bug exists on ORM 3.1 with DBAL 3.8 as well, it is not per se a DBAL 4.0 issue. |
OK so possible next steps:
If somebody could dump their DBAL schema filter at runtime using the DBAL configuration object on ORM 2 then on ORM 3, it might help. |
Can somebody here please confirm that they get the issue with ORM 2 when using the |
No |
|
This is a real problem for our project, especially for production.
because it causes an even bigger problem:
|
Here is a shell script to trigger both a succeeding workflow with ORM 2.19 and a failing one with ORM 3.0. Script#!/usr/bin/env sh
# Set up new Symfony 7 project
composer create-project symfony/skeleton:"7.0.*" my_test_project
cd my_test_project
# Install Doctrine bundles
composer require --no-interaction "doctrine/doctrine-bundle:~2.11" "doctrine/doctrine-migrations-bundle:~3.3" "doctrine/orm:~2.19" "doctrine/dbal:~3.8"
# Use sqlite for local testing
echo "DATABASE_URL=\"sqlite:///%kernel.project_dir%/var/data.db\"" > .env.local
# Install empty migration. This creates the sqlite database with the doctrine_migration_versions table
bin/console doctrine:migrations:generate
bin/console doctrine:migrations:migrate
# Validate schema: succeeds
bin/console doctrine:schema:validate -v
# Upgrade to ORM 3.*
composer require "doctrine/orm:~3.0"
# Validate schema: fails
bin/console doctrine:schema:validate -v The difference causing the change is that within the callstack of the command, the variable Backtrace ORM 2.19
Backtrace ORM 3.0
|
Related PRs:
I think we should leverage asset filtering to do this. If it causes issues with command from |
Just remembered this solution that does exactly that (using a dynamic filter). Something better that might benefit not just Symfony users might be to do it directly from code inside |
Proposed If you run for example |
@gjuric yes, @yapro already established that in #1406 (comment) Can you try the solution in my last command? I'm currently working on integrated the solution from my previous comment in the migrations bundle. |
Here is my attempt: doctrine/DoctrineMigrationsBundle#526 |
For now, I manually add the migration table to the schema with a doctrine event listener on Here's a gist if anyone interested : https://gist.github.com/Brewal/d0fe0792a69e7e5fdf3fb06898b20d35 |
Adding a listener for |
If it relies solely on the ORM's event system and not on Symfony or the DoctrineBundle, I can see how it would be superior to the asset filtering solution, in that it could benefit to other frameworks such as Laminas or Laravel as well. @Brewal @stof are you willing to open a pull request? Otherwise I might work on it soon. If I understand properly, the ORM command works by diffing 2 schemas. @FlyingDR's relies on asset filtering at the DBAL level, while Symfony's event system, which means it works only for Symfony (I think? Can @Brewal's solution relies on the ORM event system, which will kick in only for the ORM. I hope we are not forgetting about other cases relying on schema diffing and not relying on the ORM somehow. Are there other pros or cons I'm forgetting ? |
Removing the table from the schemas won't detect changes to |
Gave it a try, and I'm starting to see some cons:
I think I'd rather we go with @FlyingDR's solution, where only |
I gave it a try as well and ended up opening three PRs where each PR requires the previous one.
I don't believe so as
Hence the choice to remove the table from the comparison schema instead of adding it to the generated (metadata) schema. This doesn't catch changes to One thing that is missing is documentation on how to use #1418 without DoctrineMigrationsBundle. I feel like we can and should add that to the docs of this repository. |
Since the latest version of |
@cosminsandu so if it's not an option for you, please help and contribute to the PR with the fix 👍 |
It works with the above workaround |
@cosminsandu it doesn't. Re-run the diff command again :) |
Actually the following commands works OK on my side: php bin/console doctrine:database:drop --force --if-exists
php bin/console doctrine:database:create --if-not-exists
php bin/console doctrine:migration:migrate
php bin/console doctrine:schema:validate -v The I am using |
Did you gave this a try : #1406 (comment) I fixed it for me with doctrine/orm 3.2.1 and dbal 4.0.4 |
@cosminsandu you will face with this issue soon #1406 (comment) @Brewal Yeah, I saw this solution, but for now, the current error doesn't bother me much. |
@berkut1 indeed this problem appears #1406 (comment) I will try this solution #1406 (comment) |
@berkut1 sorry, I replied to the wrong person 😄 I was trying to prevent "any updates ?" comments notifications that might bother people. For anyone else : as of now there are workarounds and also PRs opened to fix this issue. Understand that my solution #1406 (comment) will probably not be implemented (see this comment : #1406 (comment) and the following ones). That's why I keep notifications on this issue. |
when will the solution be merged? |
I can confirm this issue applies on my project, too. Using workaround in #1406 (comment) prevents me from re-running
Issue persists after upgrading |
Hello from the Doctrine team meetup. Workaround: as soon as you use migrations, run |
@greg0ire My CI setup involves executing migrations starting from an empty database (so |
@stof oh right! To elaborate on my previous answer, we would like to be able to remove the schema tool update feature and rely solely on migrations for this. If I understand your answer well, the missing piece would be a flag or a separate command in the migrations namespace to check that the diff is empty, is that it? In the end, the UX would be slightly better, because it could tell you whether you forgot to execute a migration or to generate it. We plan to introduce a new dummy metadata storage that will allow to use migrations without a database table, and remove the duplicate code. So the right current workaround would be That's assuming the only reason |
Given that all the infrastructure for comparing schemas is in DBAL anyway, why removing this from |
I suppose it not so much a removal as it would be a move. We'd be moving the sync test functionality to a place where it would belong more (the migrations package). Also, it seems that although there is a lot of code in common between this and Anyway, I'd be grateful if somebody here could confirm that |
As long as the issue of generating a Also, checking
The reason is that the DiffGenerator temporarily changes the configuration of DBAL to ignore that table from the introspection when generating the diff (so that it does not think it exists):
diff command that exits the process once generated)
|
Oh right, this is not a workaround for Postgres users indeed. We'll have to give this more thought. |
Also: running |
Well… the
Do you mean because your CI filesystem is readonly or what? Please elaborate. A |
Just Upgrading doctrine/migrations (3.8.1 => 3.8.2) https://github.com/doctrine/migrations/releases/tag/3.8.2
But the |
I seem to have misunderstood this part:
We have a couple of use cases for The other use case could be compared to I usually use If Also: a couple of projects are not using the migration system for security reasons. If the |
The mapping validation is not planned for any changes, no.
Yes… and more importantly, the exit code of the command being negated in my proposal would make your deployment fail right after the file is created.
Our plan would be to have a mode for the migrations package. When in changelog mode, everything would work as it works now. When in "no-changelog" mode, things would work "in memory": no migration file, and the metadata table would be ignored. So basically it would work like
Can you elaborate on the "security reasons"? |
In some environments, database schema changes need to be controlled more tightly, using a two-man rule, and all schema changes are deployed by hand. The database user which Doctrine uses, have only a limited set of grants, and do not allow for schema changes. Those projects do not have the Doctrine Migrations Bundle installed at all. |
I don't fall into this camp, but this is a good question |
I see. With the new design you would still have to install |
BC Break Report
Summary
When I updated doctrine/orm to version 3.0.0, my CI started to fail due to the doctrine:schema check:validate, which returned DROP TABLE doctrine_migration_versions;
I found that adding schema_filter can fix this problem: "
^(?!doctrine_migration_versions$)" in the dbal configuration, indeed, then the error no longer appears, but after that my migrations stopped tracking the current state and think that at the moment no migration has been performed.In version 3.0, the saveMode argument was removed in \Doctrine\ORM\Tools\SchemaTool::getUpdateSchemaSql and because of this, doctrine:schema:validate tracks deleted tables and returns sql for this action.
Previous behavior
Current behavior
How to reproduce
The text was updated successfully, but these errors were encountered: