4

In the knowledge base article there are 4 steps described to automate the deployment process

  1. Pull updates for git
  2. Run composer install
  3. Run migrate/all
  4. Run project-config/apply

The problem with this is that when you have pushed a structural change (eg. adding a new field) and a content migration (adding new entry using that new field) at the same time, it fails because you cannot migrate into a non existing field of course

You cannot flip step 3 and 4 as in that scenario changes made to Craft CMS are not yet available in the database.

7

Something I wish I knew a long time ago, as it has bitten us quite a few times already in the past. Nothing as bad as having an automated deployment process that fails once in a while.

I'm sharing it here, but I believe it would be good to add it to the knowledge base too (https://craftcms.com/knowledge-base/deployment-best-practices)

The solution is to split up the structural migration and the content migration.

Pull the update for git and then run

craft update/composer-install --interactive=0
craft migrate/all --no-content --interactive=0
craft project-config/apply --force
craft migrate --track=content --interactive=0

Pretty straightforward and simple, but I was not aware of the --no-content flag until recently as it not in the command help. I hope it will help somebody in the future!

(The --interactive=0 and --force flags are there because it is an unattended deploy)

1
  • Thanks for pointing this out, Tim. Updated the Knowledge Base article to mention splitting out these steps along with your non-interactive flags. – Matt Stein Jan 8 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.