Is there any way to ensure nids will not change when deploying across servers???
To summarize, the problem is that when a node is deployed, there is no guarantee that the node will have the same ID on the destination server.
I've had a lot of trouble with this and really need some help. I understand that this may be a "won't fix" right from the start, but if anyone could help, that would be great. It applies to multi stage environments where any node-related content must go "backwards" from production to beta/staging/dev or where two nodes that reference each other by nid are deployed.
If more detail in required, read this example:
Server1 = dev, Server2 = production. Comments are made on Server2 and should be ported down to Server1 (comments are just an example, this can happen with anything that references nodes). Let's assume that Server1 and Server2 are practically identical in form and data.
On Server1, an editor creates two new articles, getting the autoincrement nids 5 and 6 (these, of course, are arbitrary). The editor then realizes 5 isn't ready for production, but 6 is, so the editor deploys 6 from Server1 to Server2 where 6 will get the nid 5 (because Server2's autoincrement value was never incremented when 5 was created in Server1), then when 5 is deployed, it will get the nid 6, effectively switching their nids. When users comment on each of the articles, the comments reference the new nid assigned on Server2. Then when comments are ported down from Server2 (where they were created) to Server1, 6's comments will reference nid 5, and 5's comments will reference nid 6. As you can see, this is a very simple example and can easily turn into an unrecoverable situation with many articles and comments.
Is there any way to ensure nids will not change across servers???
The deploy module could send the original nid from Server1 to Server2, where Server2 would force the new article to be created with that nid. However, that solution seems like it could cause some mySQL autoincrement problems (and would require hacking node_deploy.module and maybe core). I am utterly lost and would hate to deprive my editors of content deployments, forcing them to only update content when we do a full code & db deployment. We have considered third-party comment systems, but they rely on ids as well, so the problem persists even if you don't have to port comments "backward". Is there a UUID solution?
Any ideas, suggestions, questions, clarifications would be greatly appreciated.
Thanks in advance!
Comments
Comment #1
gddDeploy implements UUIDs for exactly this purpose. You may be interested in reading some of the background posts about this at
http://heyrocker.com/drupal
and
http://palantir.net/blog/bringing-deployment-capability-drupal
You are right about porting the comments down from live, however Deploy works both ways. It can not only map content dev->live but live->dev so you can manage comments that way.
I know you've been in my issue queues so I thought you would realize this. If you are talking about actually replacing the nid with a uuid, no that does not exist. Deploy lays them alongside then nid and uses them as needed. I am hoping to get a real UUID solution into Drupal 8.
The sad fact is that 98% of Drupal sites out there today just do all their content work right on the live site, or they do everything on the back end and do dumps forward (a decent solution for sites with no user-submitted content.)
Comment #3
teastburn85 commentedThank you so much for your prompt reply heyrocker! I have read most of the articles on your site already, thanks :)
Haha yes, I realize that's what UUID is for and it is awesome, but unfortunately hardly anyone uses it so I don't get to benefit from it too often. Tired and frustrated I wrote a module that replaced nids with your UUIDs, but too many modules (including, somewhat ironically, the UUID module) rely heavily on the exact current schema definition of nids, thus when they cast the UUIDs to integers, everything crumbles. UUIDs would indeed be an acceptable solution with a third-party comment system such as Disqus.
If only the rest of the world would use your UUID solution!!! The current nid system has only caused us pain.
Your solution of using deploy both directions is intriguing. It had crossed my mind but I shot it down because deploy is a GUI program and, AFAIK, cannot be scripted. With over a thousand articles and (hopefully) multiple comments per article, that would be a lot of manual GUI repetition! Is there a way to script it, even if it's a hack? Some kind of drush integration would be awesome, but sounds quite difficult.
Do you know if forcing the nid to be the same on the destination server is out of the question? It looks like hacking core would have to take place, but I'm relatively new to Drupal so am not positive about that.
Again, I really appreciate your help and work!
Comment #4
gddYes straight up replacing NIDs with UUIDs simply will not work as Drupal exists currently, for better or worse. Drush integration was committed last week. It needs a little work to work completely without human interaction (it still requires manual entry of username and password) but that would not be hard to add. Here is the issue.
http://drupal.org/node/795408
Forcing the NID to be the same is just not going to work. All the database tables use autoincrements, and there's just no way to control them to that levels.
Comment #5
teastburn85 commentedAwesome! Drush integration is crucial!
So the idea is I can deploy only comments from live -> dev/beta/staging and not the whole article? Or the article gets deployed and the comments go with it? That would seem to wipe out any changes to the article on dev.
Thanks again!
Comment #6
gddYes, you can do that. It will require some integration code in a custom module, but perhaps I can write up a handbook page on that since it is bound to be a common request. It will only deploy the comments, not the whole article. I have this system in place for a client right now actually and it works really well.
I also made a patch to allow Drush integration to run unattended. See
#893828: Expand Drush actions to allow unattended deployments
Comment #7
teastburn85 commentedI updated deploy, downloaded the drush patch, wrote a script to grab the latest comments and deploy them and it worked great! However, my coworkers decided on using the Disqus module for commenting, which nullifies the deploy comments stuff. In order to use it, though, I had to use the node UUID for the comment thread identifiers. Let me know if you'd like me to share either of these approaches.
Thanks again to you and UUID!
Comment #8
dixon_Looks like things got sorted out here :)
Comment #9
john.money commentedI'm going to reopen this to get some thoughts on how it might better work. Here is a (my real-live) scenario:
I don't see how I am going to ever reconcile this situation unless I force node IDs on node_save. Thoughts?
*edit: came across a d7 sandbox module node renumber which needs further investigation as an approach to forcing a node ID.
Comment #10
john.money commentedAs mentioned in my above comment, Deploy is a non-starter if you cannot QA nodes on staging and ensure that any content node ID links will remain valid when pushed to production. I am posting this as proof-of-concept since I needed a solution immediately.
Caveats:
Conceptual solution:
And the code:
In sites/all/modules/mymodule/mymodule.module, add:
(ignore closing php bracket)
In includes/common.inc, modify function drupal_write_record:
(ignore closing php bracket)