I think the implementation wouldn't be much radical from
https://github.com/etrepum/couchperuser - it listens for _users
database changes and setups databases when user registers. For you,
the same process will happens when project document appears in some
database.
--
,,,^..^,,,


On Wed, Feb 11, 2015 at 12:44 AM, Alexander Gabriel <[email protected]> wrote:
> Hi couch experts
>
> I will describe my reasons and my proposed solution for realising a
> database per "project". I have found a lot of information on "a database
> per user". But non on a database per "project".
> Please tell me if this is a sane way to go.
>
> **************
>
> The app:
>
> In my app's users will mainly work together on projects. Collecting data
> and geodata. In the field.
>
> Projects can be configured: Users, data structure, pixel-map-files for
> offline mapping (large attachments). This will happen online.
>
> Collecting data will happen in the field, so often offline.
>
> The app uses couchdb on the server. And pouchdb in the browser.
>
> **************
>
> Why a database per project:
>
> Let's assume five users work together on a project. A database per user
> would increase the data amount on the server by a factor 5. And also the
> syncing. As this is the normal scenario, it makes more sense to create
> databases for projects.
>
> **************
>
> My idea on how to implement "a database per project":
>
> On the server there is a central couchdb database. It's main job is user
> management, as all the project data will be in other databases.
>
> On the server there is also a node.js app that manages databases per
> projects:
> - it watches the change stream for new projects being created (using nano).
> Then:
> - it creates a new database for the project
>   - database-name is the _id of the project
> - it sets read (and hence write) permissions to users with role = _id of
> the project
> - it copies the projects users (whose names are contained in an array of
> the project object) from the central couch into the new database
> - it adds a new role to the projects users in the central couch
>   - this role equals the _id of the project
>
> Client side, the app listens to the changes feed. When the active user's
> _users-object is changed, it checks it's roles:
> - if a role has been deleted, the corresponding project is removed and
> syncing stopped
> - if a role has been added, the corresponding project is added and syncing
> added
>
> **************
>
> o.k.
> What do you think?

Reply via email to