Index: Dev/trunk/src/server/config/check-couchdb.js
===================================================================
--- Dev/trunk/src/server/config/check-couchdb.js	(revision 487)
+++ Dev/trunk/src/server/config/check-couchdb.js	(revision 492)
@@ -1,5 +1,5 @@
 var Q = require('q')
   , _ = require('underscore')
-  , tv4 = require('tv4')
+  , validator = require('../util/validator')
   , CouchDB = require('../util/couch').CouchDB
   ;
@@ -10,4 +10,15 @@
     var server = new CouchDB(couchServerURL,dbName);
     var designRe = /^_design\//;
+
+    var codes = {};
+    function codeUnique(code) {
+        if ( code in codes ) {
+            return false;
+        } else {
+            codes[code] = true;
+            return true;
+        }
+    }
+
     return server.get('/_all_docs')
     .then(function(allDocs){
@@ -20,5 +31,9 @@
                 return server.get(doc.id)
                 .then(function(doc){
-                    var valid = tv4.validateResult(doc,schema);
+                    var valid = validator(doc,schema);
+                    if ( doc.type === "Question" && !codeUnique(doc.code) ) {
+                        valid.valid = false;
+                        valid.error = "Question code "+doc.code+" is not unique.";
+                    }
                     result[doc._id] = valid;
                     return result;
Index: Dev/trunk/src/server/config/couchdb-design-docs.js
===================================================================
--- Dev/trunk/src/server/config/couchdb-design-docs.js	(revision 487)
+++ Dev/trunk/src/server/config/couchdb-design-docs.js	(revision 492)
@@ -125,4 +125,20 @@
     },
 
+    "qed/_design/surveyRuns": {
+        __configAction: "replace",
+        _id: "_design/surveys",
+        language: "javascript",
+        views: {
+            by_dates: {
+                map: function(doc){
+                    if ( doc.type !== 'SurveyRun' ) { return; }
+                    var startDate = doc.startDate || "";
+                    var endDate = doc.endDate || {};
+                    emit([startDate,endDate,doc.liveName||null],doc);
+                }
+            }
+        }
+    },
+
     "qed/_design/responses": {
         __configAction: "replace",
Index: Dev/trunk/src/server/config/couchdb-schema.json
===================================================================
--- Dev/trunk/src/server/config/couchdb-schema.json	(revision 487)
+++ Dev/trunk/src/server/config/couchdb-schema.json	(revision 492)
@@ -36,5 +36,5 @@
           "_rev": { "type": "string" },
           "categories": { "type": "array", "items": { "type": "string" } },
-          "code": { "type": "string" },
+          "code": { "type": "string", "minLength": 1 },
           "content": { "type": "array", "items": { "$ref": "#/definitions/content/any" } },
           "description": { "type": "string" },
@@ -52,4 +52,5 @@
           "_id": { "type": "string" },
           "_rev": { "type": "string" },
+          "description": { "type": "string" },
           "publicationDate": { "type": "string", "format": "datetime" },
           "questions": { "type": "array", "items": { "$ref": "#/definitions/docs/Question" } },
@@ -67,6 +68,8 @@
           "description": { "type": "string" },
           "endDate": { "type": "string", "format": "datetime" },
+          "liveName": { "type": "string" },
           "mode": { "type": "string", "enum": [ "open", "closed" ] },
-          "secret": { "type": "string", "minLength": 8 },
+          "respondentCanDeleteOwnResponse": { "type": "boolean" },
+          "secret": { "type": "string", "minLength": 1 },
           "startDate": { "type": "string", "format": "datetime" },
           "survey": { "$ref": "#/definitions/docs/Survey" },
@@ -83,6 +86,7 @@
           "_rev": { "type": "string" },
           "answers": { "type": "object" },
+          "email": { "type": "string", "format": "email" },
           "publicationDate": { "type": "string", "format": "datetime" },
-          "secret": { "type": "string", "minLength": 8 },
+          "secret": { "type": "string", "minLength": 1 },
           "surveyRunId": { "type": "string" }
         },
Index: Dev/trunk/src/server/config/upgrade-couchdb.js
===================================================================
--- Dev/trunk/src/server/config/upgrade-couchdb.js	(revision 487)
+++ Dev/trunk/src/server/config/upgrade-couchdb.js	(revision 492)
@@ -1,5 +1,4 @@
 var Q = require('q')
   , _ = require('underscore')
-  , tv4 = require('tv4')
   , CouchDB = require('../util/couch').CouchDB
   ;
