This course is archived!
03.
Creating Unique Files
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This course is archived!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
8 Comments
What about all the built-up cruft you'd end generating over time in that files directory, i.e., the "kindle" of kitten photos?
Or is this of no concern because such a directory would be ignored by your VCS, and you can easily just overwrite as you go? The alternative would be the need to periodically go through the directory with a burlap sack and cinder block, which would be as horrid as the image I've just used.
BEST COMMENT EVER :).
Yea, it's ignored by VCS, so I wasn't too worried about it. But an alternative to letting the directory fill up with time would be to automate the proverbial burlap sack, and delete the directory automatically before loading your fixtures (the Filesystem class can remove the directory, then you can re-create it). You could do that in getFixtures() or override load(), do this, then call parent::load() if that feels a bit better.
Cheers!
Is there an easy thing to only have it load fixtures for certain environments?
I.E. My app has fixtures that it needs to add in order to function. When I load it on prod (or even stage) I'll need to add those fixtures, but I'd also like to be able to load a bunch of fixtures for testing in the dev/test environment.
Thanks!
Hey Matt,
Loading fixtures in production is not a good practice, well, because you probably have a real data in the DB, so overwriting it would be fatal :) That's why fixtures bundle usually load for dev/test environments only in kernel.
Anyway, not sure it's possible with Alice bundle, but it's possible with DoctrineFixturesBundle, where you can easily access container from the fixtures: https://symfony.com/doc/mas... - which means you can get current environment like: $env = $this->container->getParameter("kernel.environment"); . So with simple if and return statements in the beginning of the fixtures file you can skip some fixtures for some environment.
Cheers!
Haha Yeah I know. Maybe what I'm referring to isn't fixtures? It's data that has to be there for the app to function...
Hey Matt,
Yeah, it sounds like fixtures... but this data already should be on production. What I mean is that you probably do not want to reload those data on production because you'll lose real data. The only valid case I see is when you want to do the first deploy to production. But on the second, 3rd, etc. deploy those data already *should* be there. But if you need to inject more data with further deploys - you probably talking about some kind of migrations.
Cheers!
> The only valid case I see is when you want to do the first deploy to production.
Yeah,t hat's the case I'm thinking about. Migrations is an interesting idea...
Hey Matt,
So yes, most of the time it's easier to manually load those data, probably you can just export / import the data. It'd not be 100% automated, but I think it's OK to start with it. Or, you can even create a one-time migration command, that you'll execute on the production after the first deploy and then remove it on the next deploy, but once again I do not think it's worth it. I'd prefer to manually import initial data after the first deploy.
Cheers!
"Houston: no signs of life"
Start the conversation!