Drupal ♥ CouchDB

For most web sites and software there are three pillars, code, configuration, and content. Code is always the easy one, stick it in git, then deploy it anywhere with full revisions and accountability. Historically Drupal has struggled with the other two aspects, until Drupal 8, which was launched in late 2015. This added configuration management, stored in yaml files the configuration could now be version controlled alongside the code. Now all that’s left to be solved is content.

Previously in Drupal there have been two main options. Add content in production, or use the Deploy module, which implemented a custom REST API to copy content to another Drupal site. Since it was a custom REST API it wasn’t very well documented, issues were often found and it was difficult to integrate with. The most common suggestion was to just add content in production, this worked for many, however if there were many legal or editorial steps then this was not an option.

During the development of Drupal 8, Dick Olsson, the maintainer of the Deploy module, started to look for a better solution. After a lot of research it seemed all of the content storage and replication problems had already been solved, in CouchDB. Along with Andrei Jechiu and Tim Millwood, Dick developed a suite of contributed modules for Drupal that follow the CouchDB Replication protocol.

Data storage
Drupal doesn’t store revisions for all content, and for the content that is revisionable this is not enforced. Therefore the first step was altering the schema for all content to allow us to store revisions for all content. There were also a bunch of other things we needed to store to be compatible with CouchDB, such as, a revision hash, a sequence ID, and a revision tree. Another issue we had is Drupal has many types of content, and modules can define new types of content, so without looping through all content types, then all content, we had no way of knowing which UUID related to which content. To solve this we created a UUID index in a simple key value store. Many of these features were developed into the Multiversion module.

API endpoints
Drupal 8 core ships with a REST module, which provides a bunch of API end points, we expanded on these to provide all endpoints compatible with the CouchDB protocol. This provided all the needed headers and document attributes required by the protocol. The Drupal content was then normalized (and denormalized) to provide valid JSON-LD documents. The Replication and RELAXed Web Services modules provide all the functionality to expose the CouchDB compatible API endpoints.

Replication
Initially the native CouchDB replicator was used to replicate from Drupal to CouchDB, CouchDB to Drupal, and Drupal to Drupal. Tests were then setup to work with PouchDB allowing Drupal to be used as a backend for decoupled web apps.

As part of Google Summer of Code 2015 a student worked on a PHP version of the CouchDB replicator, this was worked into the Drupal modules to allow for replication between CouchDB compatible endpoints via the Drupal UI without using CouchDB.

Conclusion
Drupal now has an awesome content staging solution allowing users to stage content on one site then replicate all content to a live site. It also allows for backing up, or storing content, within a CouchDB database. Then users can also decouple their front-end by replicating content to PouchDB.

Further reading
Drupal Deploy – The team behind this work.
Multiversion – Used for Drupal storage updates.
RELAXed Web Services – Provides the API endpoints.
Deploy – The UI for replicating between sites.
PHP CouchDB Replicator – Replicate using PHP.
Improving Drupal’s content workflow

CouchDB Weekly News, March 24, 2016

Cloudant ❤ Apache CouchDB™ 2.0: Sandbox Cluster Now Available

Last week IBM announced that the most awaited release of Cloudant is almost here — a release that realigns Cloudant with the CouchDB 2.0 code base. Read about it on the IBM dev blog here.

The CouchDB 2.0 Release Testing Plan

Interested in helping out with testing the upcoming Apache CouchDB 2.0 release and making sure it is as bug-free as possible? We’re still looking for reviewers for The CouchDB 2.0 Testing Release Plan.

Releases

Major Discussions

Calculating Revision IDs outside erlang… (see thread)

In this discussion Michael Fair recommends changing the term_to_binary computation to use the {minor_version, 1} option in the rev_id calculation, to assist with replicating the md5 for the revision id of documents with floats – which currently is causing a headache.

Candidates for built-in filter functions? (see thread)

Robert Newsome is gathering suggestions for part of a new effort to improve replicator performance, as he is planning to add new built-in filter functions, which will run in the Erlang vm.

Multiple database backup strategy (see thread

Don’t miss this discussion, based on using /_db_updates to detect active source databases of a replication job and using /_db_updates to hear about new/updated/deleted _replicator documents, with some unexpected twists.

Releases in the CouchDB Universe

PouchDB

Opinions and other News in the CouchDB Universe

… and in the PouchDB Universe

CouchDB Use Cases, Questions and Answers

Use Case:

Stack Overflow:

no public answer yet:

PouchDB Use Cases, Questions and Answers

Use Case:

Stack Overflow:

no public answer yet:

For more new questions and answers about CouchDB, see these search results and about PouchDB, see these.

Get involved!

If you want to get into working on CouchDB:

  • We have an infinite number of open contributor positions on CouchDB. Submit a pull request and join the project!
  • Do you want to help us with the work on the new CouchDB website? Get in touch on our new website mailing list and join the website team! – www@couchdb.apache.org
  • The CouchDB advocate marketing programme is just getting started. Join us in CouchDB’s Advocate Hub!
  • CouchDB has a new wiki. Help us move content from the old to the new one!
  • Can you help with Web Design, Development or UX for our Admin Console? No Erlang skills required! – Get in touch with us.
  • Do you want to help moving the CouchDB docs translation forward? We’d love to have you in our L10n team! See our current status and languages we’d like to provide CouchDB docs in on this page. If you’d like to help, don’t hesitate to contact the L10n mailing list on l10n@couchdb.apache.org or ping Andy Wenk (awenkhh on IRC).

We’d be happy to welcome you on board!

Events

Job opportunities for people with CouchDB skills

Time to relax!

  • “All day, you eagerly anticipate finding just 30 minutes to chill out, catch up with your significant other, and relax into sleep. But the problem is…though your body is ready to plop down on the sofa and decompress, your brain is still going a mile a minute.” – 3 Simple Ways to Relax Your Brain After a Funky Day
  • “Who would’ve thought that this slim plastic box can become such an attractive resting place for a cat.” – Flexible Cat Finds an Odd Spot to Relax
  • “We pushed an update to our single-signon system for Basecamp, which had me working until 1:30 AM. That wouldn’t have been so bad if it wasn’t because I got woken up at 5 AM to help deal with an issue that arose. But the costs the following day were typical, numerable, and high…” Sleep deprivation is not a badge of honor
  • “Psychologists have long noticed what’s sometimes been called the “labor illusion:” when it comes to judging other people’s work, we might say we’re focused only on whether they did the job quickly and well—but really we want to feel they wore themselves out for us.” – Nobody Cares How Hard You Work
  • “Don’t tell your friends about your strange calming habits. They will tease you. Definitely don’t write a Medium post about it. They’ll see it.” – My Arsenal of Calm

… and also in the news