source: Dev/trunk/src/server/config/couchdb-design-docs.js @ 480

Last change on this file since 480 was 480, checked in by hendrikvanantwerpen, 11 years ago

Introduced schema version.

File size: 4.0 KB
Line 
1module.exports = {
2
3    "_users/qed_admin": {
4        __configAction: "ignore",
5        _id: "org.couchdb.user:qed_admin",
6        name: "qed_admin",
7        password: "Welkom01",
8        roles: [ "qed_admin" ],
9        type: "user"
10    },
11
12    "qed/schemaInfo": {
13        version: "1"
14    },
15
16    "qed/_security": {
17        __configAction: "ignore",
18        admins: {
19            names: [],
20            roles: ["qed_admin"]
21        },
22        readers: {
23            names: [],
24            roles: ["qed_user"]
25        }
26    },
27
28    "qed/_design/default": {
29        __configAction: "replace",
30        _id: "_design/default",
31        language: "javascript",
32        validate_doc_update: function(newDoc, oldDoc, userCtx, secObj) {
33            if ( oldDoc && oldDoc.publicationDate ) { throw({forbidden:'Published documents cannot be modified.'}); }
34        },
35        views: {
36            by_type: {
37                map: function(doc){
38                    emit(doc.type, doc);
39                }
40            },
41            typeless: {
42                map: function(doc){
43                    if ( !doc.type ) {
44                        emit(doc._id, doc);
45                    }
46                }
47            }
48        }
49    },
50
51    "qed/_design/questions": {
52        __configAction: "replace",
53        _id: "_design/questions",
54        language: "javascript",
55        views: {
56            all: {
57                map: function(doc){
58                    if ( doc.type !== 'Question' ) { return; }
59                    if ( doc.categories && doc.categories.length > 0 ) {
60                        for ( var i = 0; i < doc.categories.length; i++ ) {
61                            emit([doc.categories[i],doc.topic||null],1);
62                        }
63                    } else {
64                        emit([null,null],1);
65                    }
66                },
67                reduce: function(keys,values){ return sum(values); }
68            },
69            published: {
70                map: function(doc){
71                    if ( doc.type!=='Question' || !doc.publicationDate ) { return; }
72                    if ( doc.categories && doc.categories.length > 0 ) {
73                        for ( var i = 0; i < doc.categories.length; i++ ) {
74                            emit([doc.categories[i],doc.topic||null],1);
75                        }
76                    } else {
77                        emit([null,null],1);
78                    }
79                },
80                reduce: function(keys,values){ return sum(values); }
81            },
82            all_topics: {
83                map: function(doc){
84                    if( doc.type !== 'Question' ){ return; }
85                    emit(doc.topic);
86                },
87                reduce: function(key, values, rereduce) { return null; }
88            },
89            published_topics: {
90                map: function(doc){
91                    if ( doc.type !== 'Question' || !doc.publicationDate ) { return; }
92                    emit(doc.topic);
93                },
94                reduce: function(key, values, rereduce) { return null; }
95            }
96        }
97    },
98
99    "qed/_design/surveys": {
100        __configAction: "replace",
101        _id: "_design/surveys",
102        language: "javascript",
103        views: {
104            drafts: {
105                map: function(doc){
106                    if ( doc.type !== 'Survey' || doc.publicationDate ) { return; }
107                    emit(doc._id,doc);
108                }
109            },
110            published: {
111                map: function(doc){
112                    if ( doc.type !== 'Survey' || !doc.publicationDate ) { return; }
113                    emit(doc._id,doc);
114                }
115            }
116        }
117    },
118
119    "qed/_design/responses": {
120        __configAction: "replace",
121        _id: "_design/responses",
122        language: "javascript",
123        views: {
124            by_surveyrun: {
125                map: function(doc){
126                    if ( doc.type !== 'Response' ) { return; }
127                    emit(doc.surveyRunId, doc);
128                }
129            }
130        }
131    }
132
133};
Note: See TracBrowser for help on using the repository browser.