Reputation: 11676
I have a CouchDb instance running a peruser database configuration.
Each user database generated (when a user is added to the _users
database) needs to have the same design documents with view/list logic etc.
What is the defacto way to add the design documents to the database upon database creation? Is it simply to add them after a successful user creation request? Or is there a more elegant way of doing this in CouchDb?
Upvotes: 3
Views: 603
Reputation: 334
If you plan on using the Follow npm module as @Juanjo Rodriguez suggested, please consider using the Cloudant's version. The Iriscouch's version (the one pointed by @Juanjo Rodriguez) is way out of date. For example it doesn't support CouchDB v2.x among other issues. I worked with the Cloudant's team to improve all this these last days and they just released the updated npm package yesterday here: https://www.npmjs.com/package/cloudant-follow?activeTab=versions
The 0.17.0-SNAPSHOT.47
version embarks the patches we worked on so don't use the 0.16.1
(which is officially the latest).
You can read more about the issues we fixed here:
https://github.com/cloudant-labs/cloudant-follow/issues/54
https://github.com/cloudant-labs/cloudant-follow/issues/50
https://github.com/cloudant-labs/cloudant-follow/issues/47
Upvotes: 1
Reputation: 2131
There is not a mechanism for initialize newly created user databases, you should include it in your user creation logic. If you want to decouple user creation and db initialization, I suggest you to explore the following strategy
1 - Create a template database and place on it your design documents that should be applied to every user db
2 - Listen continuously _db_updates endpoint where db level events will be notified. This library can help you.
3 - When a db that matches the user db name pattern is created, you can trigger a replication from the template database to the newly created database using the _replicate endpoint.
Upvotes: 2