Chapters
19 Chapters
|
1:28:34
|
This course is still being released! Check back later for more chapters.
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Aunque el código de este tutorial utiliza Symfony 8, ¡todo lo comentado funciona en Symfony 7!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.4",
"ext-ctype": "*",
"ext-iconv": "*",
"babdev/pagerfanta-bundle": "^4.6", // v4.6.0
"doctrine/dbal": "^4.4", // 4.4.3
"doctrine/doctrine-bundle": "^3.2", // 3.2.2
"doctrine/doctrine-migrations-bundle": "^3.7", // 3.7.0
"doctrine/orm": "^3.6", // 3.6.6
"knplabs/knp-time-bundle": "^2.5", // 2.5.0
"pagerfanta/doctrine-orm-adapter": "^4.8", // v4.8.0
"php-cs-fixer/shim": "^3.94", // v3.95.2
"phpdocumentor/reflection-docblock": "^5.6", // 5.6.7
"phpstan/phpdoc-parser": "^2.3", // 2.3.2
"stof/doctrine-extensions-bundle": "^1.15", // v1.15.3
"symfony/asset": "8.0.*", // v8.0.8
"symfony/asset-mapper": "8.0.*", // v8.0.11
"symfony/console": "8.0.*", // v8.0.11
"symfony/dotenv": "8.0.*", // v8.0.11
"symfony/flex": "^2.10", // v2.10.0
"symfony/form": "8.0.*", // v8.0.9
"symfony/framework-bundle": "8.0.*", // v8.0.11
"symfony/http-client": "8.0.*", // v8.0.9
"symfony/monolog-bundle": "^4.0", // v4.0.2
"symfony/property-access": "8.0.*", // v8.0.8
"symfony/property-info": "8.0.*", // v8.0.8
"symfony/rate-limiter": "8.0.*", // v8.0.14
"symfony/runtime": "8.0.*", // v8.0.12
"symfony/security-bundle": "8.0.*", // v8.0.12
"symfony/security-csrf": "8.0.*", // v8.0.8
"symfony/serializer": "8.0.*", // v8.0.10
"symfony/stimulus-bundle": "^2.34", // v2.35.0
"symfony/twig-bundle": "8.0.*", // v8.0.8
"symfony/ux-turbo": "^2.34", // v2.35.0
"symfony/validator": "8.0.*", // v8.0.10
"symfony/yaml": "8.0.*", // v8.0.12
"symfonycasts/tailwind-bundle": "^0.12.0", // v0.12.0
"twig/extra-bundle": "^3.24", // v3.24.0
"twig/twig": "^3.24" // v3.26.0
},
"require-dev": {
"symfony/debug-bundle": "8.0.*", // v8.0.8
"symfony/maker-bundle": "^1.67", // v1.67.0
"symfony/stopwatch": "8.0.*", // v8.0.8
"symfony/web-profiler-bundle": "8.0.*", // v8.0.12
"zenstruck/foundry": "^2.9" // v2.10.1
}
}
14 Comments
Not sure what I did wrong (which is typical). I ran
It worked correctly in that it did run src/Story/AppStory and did load the Users. But it dropped the "doctrine_migrations_versions" table.
Before loading the fixtures:
And now after loading the fixtures:
That doesn't seem right.
What am I doing wrong?
Some notes on my app.
[ ] Entities are not stored under src/Entity but rather src/Data/Entity - that might be the problem. However, load-fixtures does create all the entities tables.
[ ] doctrine.yaml has orm: mappings:
[ ] make:migration has not problem finding the Entities
[ ] doctrine:migrations:migrate works fine.
Also doctrine:fixtures:load does not drop the "doctrine_migrations_versions" table.
However, it does not use AppStory, so no Users were loaded.
Since I haven't found a solution yet. I just doing a work-around:
[ ] Run any migrations needed.
[ ] Export the "doctrine_migrations_versions" table.
[ ] Run the foundry:load-fixtures command
[ ] Import the "doctrine_migrations_versions" table.
Sigh...
So I tried adding the reset mode migrate to the zenstruck_foundry.yaml
But now I get a transaction error.
It will save the first User and then die with the error:
Something is closing the transaction. Not sure how the reset mode would have messed with that.
Not sure what to do next. There is someting about a migrate configuration file, but I haven't found anything clear yet.
Hey @JeffJones!
Ok, yeah, the
migratemode was the solution to your original problem. Let's see if we can figure out this new one. It is known to me but it's been a bit illusive to track down a proper cause.Here is the workaround we've found. In each of your migrations, add:
To always have this added, you can configure it:
Let me know if that works. I am not 100% sure why this is needed. It isn't required for all DB platforms (sqlite for instance).
By the way, in Foundry, we don't default to
migratemode because it can get quite expensive to reset your database when you have dozens or hundreds of migrations. As long as your migrations don't do anything fancy that the drop/create schema operations can't do,schemamode is the faster choice.Of course, you still need to know your migrations are current/correct. I've done this in a CI job:
doctrine:schema:validatewill fail if there are differences between the database and your defined schema.Anyway, let me know how you make out!
Kevin
I was kind of hoping that Foundry had something similar to:
Or even maybe something in the configuration to exclude tables. I believe Doctrine has a way to create your own Purger class so you can control it. Does Foundry have something like that?
All I could find, so far, are the classes in the ORM/ResetDatabase folder. I would have to replace the dropAndResetDatabase method which is final. Not sure how I'd wire in a replacement class.
Yeah, purging is something we haven't experimented with on Foundry. I think we investigated but it's complex.
BTW, it's totally valid to use normal doctrine fixtures with foundry. In your data fixtures just create factories or load stories. It was the only method to do so for many years. Foundry's load-fixtures command is relatively new. We added it because requiring doctrine fixtures brings a lot of unused code just to load foundry factories.
Wow! Thanks!
The first suggestion, having the isTransactional return false, works perfectly.
Though as you mentioned migrations can slow done things like testing. Something I will have to keep mind.
The second suggestion, adding transactional:false to doctrine_migrations in the doctrine_migrations.yaml, for some reason did not work. It gives the same error, so the configuration is not working. I could only get it to work with the "isTranasactional" method.
Again, thanks! I'm back on track!
Awesome, I'm glad that worked!
For the config, I believe all that does is make future generated migration classes add that method. So going forward, you don't have to manually add it to every migration.
Ah! Nice. Sounds good!
I've followed all the steps in this chapter, but there's a problem: the only user created isn't being loaded into the User table. When I run
symfony console dbal:run-sql 'select * from user', I get:[OK] The query yielded an empty result set.If I use the DB Browser for SQLite tool and inspect the User table, it is indeed empty.
@Brontie
The chapter’s fixture user is created by Foundry, so an empty
usertable usually means the fixtures story never ran, not that Doctrine is broken. Run the story loader explicitly soAppStoryinsertspicard@enterprise.spaceinto the database:If the table is still empty after that, make sure you already ran the migration that creates the
usertable, because Foundry can’t insert into a table that doesn’t exist yet. A common gotcha here is checking the SQLite file in one place while Symfony is using a different database path, so verify you’re looking at the samevar/data.dbyour app is actually configured to use.Sources:
Hey @giorgiocba
This may sound silly, but did you load the fixtures?
symfony console foundry:load-fixturesIf you did, could you do it again and see if there were any errors or warnings?
Another thing to check is whether you're using Docker for the database and whether you have it installed locally. It may be the case that the CLI is using the Docker instance, but the web isn't.
Cheers!
What could have happened?
"Houston: no signs of life"
Start the conversation!