1

I'm new to CraftCMS and have a few basic questions about synching contents between local and remote development environments. This has been discussed in other posts by I'm looking for more specific answers.

  1. Traditionally, in the old CMS we use, we do all content changes in the remote dB. And then each team member imports the remote dB and updates their local dB (similar to what is described here). However, during the dB export, we need to update all the entries to reflect the local URLs. How does this work with Craft? do dB entries need to be updated to reflect the new URLs? And is there a widely used plugin for this step?

  2. Reviewing a Craft migration plugin, it mentions that one has to follow a migration dependency order, and that one has to break migrations into smaller steps to prevent issues, instead of one large migration. Is this the general practice for Craft? Is there no other way to have a single large migration (contents, settings, fields, etc.) happening at once?

Thank you so much.

1

Here's a blog I wrote that might be useful to you: Database & Asset Syncing Between Environments in Craft CMS

This was written before Project Config was a thing, but the technique works great with Project Config too.

3
  • Andrew, amazing. Thank you so much. I'll be studying your post.
    – mauricio
    Apr 23 at 18:20
  • Andrew, thank you so much for sharing your blog post. It's very helpful and just what I needed. In general terms we use the same process in the CMS we are migrating from. I think I'll be using your dB script. I have only 1 extra questions: 1. Does it work in a local environment setup using Nitro? 2. You mentioned that you wrote the article before Project Config was a thing. Since we are so new to CraftCMS, we don't know what that fully means yet ;), Is there anything we should be aware of when using the script? thanks a million!
    – mauricio
    Apr 23 at 21:25
  • 1
    I'm not sure how you'd use the scripts with Nitro -- but here's the Docker setup I use that includes a script that pulls the db down into a Docker container: An Annotated Docker Config for Frontend Web Development Apr 23 at 23:52
1

However, during the dB export, we need to update all the entries to reflect the local URLs. How does this work with Craft? do dB entries need to be updated to reflect the new URLs?

Sounds like you might be coming from something like WP where it hardcodes URL and links in the database? You'll be happy to know that is not the case in Craft.

Craft generally uses Reference tags when it needs to store links to assets, entries, etc. in the database. This neatly sidesteps around the problem of having to do a find/replace every time you move environments since those URLs are "built up" on-the-fly.

However, this only works for new content the you create in the CMS. On the off-chance that you're moving legacy content from another CMS to Craft, you can use Craft's built-in find/replace tool inside Utilities to do the find/replace.

Is there no other way to have a single large migration (contents, settings, fields, etc.) happening at once?

Generally you want your migration to go one-way.

You'll want to read up on Project Config but in general, you start on local then push your project config to staging or production. This prompts Craft to update the structural items in the CMS (added sections, fields, etc.)

Moving actual content from staging to production itself is more of a challenge. The Migration Assistant you linked up does lets you export content as well as structure, but usually you want to keep those sorts of changes as narrowly defined as possible.

Databases are highly structured beasts. When you start adding content on production then try to push an update from staging, that's a recipe for all sorts of breakage.

As an example, say you have an entry on staging that relates to a bunch of different categories, assets, and entries. Unless those entries, categories, and assets are already created on production, how does Craft know what to do with all of it?

On a technical level, primary and foreign keys could be different, for example. Some systems get around this with GUIDs, but in general, it's still a hard problem to solve unless the two are kept in sync somehow—which is what enterprise systems generally do.

WP for example has more tools to deal with this sort of thing but they're still more simplistic in this sense because it doesn't have all the relational capabilities of Craft.

2
  • Hi RitterKnight. Thanks a lot for your thorough answer. Yes, you are right, I'm coming from WP(!), so in mind, there's always the step of exporting, and replacing data, the dB tables. It's great to hear that Craft completely avoids this problem. I'll have to study the documentation well and do several tests to get an efficient and safe deployment method.
    – mauricio
    Apr 27 at 22:56
  • 1
    In the end, the plan is to get content from the Staging dB into our local machines; Media -images, videos, etc.- will remain in the Staging server; And we will commit and push to the remotes templates and other important files we change during dev. Thank you for all the help and we will be probably knocking at the door soon with more questions.
    – mauricio
    Apr 27 at 23:12

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.