1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 18:29:17 +02:00

Wait for indexes to be ready before we let migrate finish. Should fix

This commit is contained in:
Simo Kinnunen 2015-10-22 00:10:26 +09:00
parent 8e8f2d17b7
commit 66fbadbd5d

View file

@ -26,6 +26,42 @@ module.exports = function(conn) {
}) })
} }
function createIndex(table, index, options) {
var args = [index]
, rTable = r.table(table)
if (options) {
if (options.indexFunction) {
args.push(options.indexFunction)
}
if (options.options) {
args.push(options.options)
}
}
return rTable.indexCreate.apply(rTable, args).run(conn)
.then(function() {
log.info('Index "%s"."%s" created', table, index)
})
.catch(alreadyExistsError, function() {
log.info('Index "%s"."%s" already exists', table, index)
return Promise.resolve()
})
.then(function() {
log.info('Waiting for index "%s"."%s"', table, index)
return r.table(table).indexWait(index).run(conn)
})
.then(function() {
log.info('Index "%s"."%s" is ready', table, index)
return Promise.resolve()
})
.catch(noMasterAvailableError, function() {
return Promise.delay(1000).then(function() {
return createIndex(table, index, options)
})
})
}
function createTable(table, options) { function createTable(table, options) {
var tableOptions = { var tableOptions = {
primaryKey: options.primaryKey primaryKey: options.primaryKey
@ -52,34 +88,6 @@ module.exports = function(conn) {
}) })
} }
function createIndex(table, index, options) {
var args = [index]
, rTable = r.table(table)
if (options) {
if (options.indexFunction) {
args.push(options.indexFunction)
}
if (options.options) {
args.push(options.options)
}
}
return rTable.indexCreate.apply(rTable, args).run(conn)
.then(function() {
log.info('Index "%s"."%s" created', table, index)
})
.catch(alreadyExistsError, function() {
log.info('Index "%s"."%s" already exists', table, index)
return Promise.resolve()
})
.catch(noMasterAvailableError, function() {
return Promise.delay(1000).then(function() {
return createIndex(table, index, options)
})
})
}
return createDatabase() return createDatabase()
.then(function() { .then(function() {
return Promise.all(Object.keys(tables).map(function(table) { return Promise.all(Object.keys(tables).map(function(table) {