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:
parent
8e8f2d17b7
commit
66fbadbd5d
1 changed files with 36 additions and 28 deletions
|
@ -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) {
|
||||
var tableOptions = {
|
||||
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()
|
||||
.then(function() {
|
||||
return Promise.all(Object.keys(tables).map(function(table) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue