{"action":"created","issue":{"url":"https://api.github.com/repos/neumino/thinky/issues/319","labels_url":"https://api.github.com/repos/neumino/thinky/issues/319/labels{/name}","comments_url":"https://api.github.com/repos/neumino/thinky/issues/319/comments","events_url":"https://api.github.com/repos/neumino/thinky/issues/319/events","html_url":"https://github.com/neumino/thinky/issues/319","id":101070001,"number":319,"title":"Indexes are not ensured","user":{"login":"gjuchault","id":678848,"avatar_url":"https://avatars.githubusercontent.com/u/678848?v=3","gravatar_id":"","url":"https://api.github.com/users/gjuchault","html_url":"https://github.com/gjuchault","followers_url":"https://api.github.com/users/gjuchault/followers","following_url":"https://api.github.com/users/gjuchault/following{/other_user}","gists_url":"https://api.github.com/users/gjuchault/gists{/gist_id}","starred_url":"https://api.github.com/users/gjuchault/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gjuchault/subscriptions","organizations_url":"https://api.github.com/users/gjuchault/orgs","repos_url":"https://api.github.com/users/gjuchault/repos","events_url":"https://api.github.com/users/gjuchault/events{/privacy}","received_events_url":"https://api.github.com/users/gjuchault/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/neumino/thinky/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-08-14T18:13:38Z","updated_at":"2015-08-17T21:42:23Z","closed_at":null,"body":"Hi,\r\n\r\nI'm having a problem when I try to ensure indexes. I have ~50 indexes and at least the same number of relationships. That make a lot of indexes.\r\n\r\nWhen I'm creating models, I wait for them to be ready with `model.on('ready')` to be sure everything is ready to be used.\r\n\r\nFact is, I need to restart at least 6 or 7 times the server to make sure indexes are created. I don't know how to provide you a decent and simple example to replicate (but the original code is [there](https://github.com/buckutt/Eve-Server/tree/master/src/models)).\r\n\r\nI can attach a screen cast showing for example that the promise is triggered when calling `ensureIndex` and the index not be created in RethinkDB.\r\n\r\nI looked into the code and saw that (`lib/model.js` at line 343) :\r\n```js\r\n      return r.branch(\r\n        r.table(tableName).indexList().contains(name),\r\n        r.table(tableName).indexWait(name),\r\n        r.branch(\r\n          r.table(tableName).info()('primary_key').eq(name),\r\n          r.table(tableName).indexWait(name),\r\n          r.table(tableName).indexCreate(name, fn, opts).do(function() {\r\n            if (model._name === 'Article' && name === 'pointId') console.log(model._name, 'create index', name);\r\n            return r.table(tableName).indexWait(name);\r\n          })\r\n        )\r\n      )\r\n      .run()\r\n      .then(resolve)\r\n      .error(function(error) {\r\n        if (error.message.match(/^Index/)) {\r\n          // TODO: This regex seems a bit too generous since messages such\r\n          // as \"Index `id` was not found on table...\" will be accepted.\r\n          // Figure out if this is OK or not.\r\n          return resolve();\r\n        }\r\n        reject(error);\r\n      });\r\n```\r\n\r\nI made some tests here and; there is a lot of errors passing in the `resolve` from `.error`. Theses errors are something like `Index not found` (exactly what you put in comment).\r\n\r\nWhat's the solution here ? Is the regex trick the problem ?"},"comment":{"url":"https://api.github.com/repos/neumino/thinky/issues/comments/131970428","html_url":"https://github.com/neumino/thinky/issues/319#issuecomment-131970428","issue_url":"https://api.github.com/repos/neumino/thinky/issues/319","id":131970428,"user":{"login":"primitive-type","id":1878644,"avatar_url":"https://avatars.githubusercontent.com/u/1878644?v=3","gravatar_id":"","url":"https://api.github.com/users/primitive-type","html_url":"https://github.com/primitive-type","followers_url":"https://api.github.com/users/primitive-type/followers","following_url":"https://api.github.com/users/primitive-type/following{/other_user}","gists_url":"https://api.github.com/users/primitive-type/gists{/gist_id}","starred_url":"https://api.github.com/users/primitive-type/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/primitive-type/subscriptions","organizations_url":"https://api.github.com/users/primitive-type/orgs","repos_url":"https://api.github.com/users/primitive-type/repos","events_url":"https://api.github.com/users/primitive-type/events{/privacy}","received_events_url":"https://api.github.com/users/primitive-type/received_events","type":"User","site_admin":false},"created_at":"2015-08-17T21:42:23Z","updated_at":"2015-08-17T21:42:23Z","body":"I'm not 100% sure this is related, but I think it is. After upgrading to thinky 2.1.4 and RethinkDB 2.1.1 I now get the following type of error in abundance while running my tests:\r\n\r\n```\r\nPossibly unhandled ReqlOpFailedError: The server(s) hosting table `test.User_id` are currently unreachable. The secondary index was not created in:\r\nr.branch(r.table(\"Group_User_teacher\").indexList().contains(\"User_id\"), r.table(\"Group_User_teacher\").indexWait(\"User_id\"), r.table(\"Group_User_teacher\").indexCreate(\"User_id\").do(function() {  \r\n    return r.table(\"Group_User_teacher\").indexWait(\"User_id\")\r\n})).do(function() {\r\n    return r.branch(r.table(\"Group_User_teacher\").indexList().contains(\"Group_id\"), r.table(\"Group_User_teacher\").indexWait(\"Group_id\"), r.table(\"Group_User_teacher\").indexCreate(\"Group_id\").do(function() {\r\n        return r.table(\"Group_User_teacher\").indexWait(\"Group_id\")\r\n    }))\r\n})\r\n\r\n    at Connection._processResponse (/usr/src/app/node_modules/thinky/node_modules/rethinkdbdash/lib/connection.js:229:19)\r\n    at Socket.<anonymous> (/usr/src/app/node_modules/thinky/node_modules/rethinkdbdash/lib/connection.js:150:14)\r\n    at emitOne (events.js:77:13)\r\n    at Socket.emit (events.js:169:7)\r\n    at readableAddChunk (_stream_readable.js:146:16)\r\n    at Socket.Readable.push (_stream_readable.js:110:10)\r\n    at TCP.onread (net.js:521:20)\r\n```"}}