mirror of
https://github.com/openstf/stf
synced 2025-10-03 09:49:17 +02:00
Merge pull request #1172 from denis99999/group-feature-rethinkdb-migration
Group feature rethinkdb migration
This commit is contained in:
commit
1423826fad
2 changed files with 79 additions and 0 deletions
Binary file not shown.
|
@ -38,6 +38,79 @@ dbapi.unlockBookingObjects = function() {
|
|||
dbapi.createBootStrap = function(env) {
|
||||
const now = Date.now()
|
||||
|
||||
function updateUsersForMigration(group) {
|
||||
return dbapi.getUsers().then(function(users) {
|
||||
return Promise.map(users, function(user) {
|
||||
return db.run(r.table('users').get(user.email).update({
|
||||
privilege: user.email !== group.owner.email ? apiutil.USER : apiutil.ADMIN
|
||||
, groups: {
|
||||
subscribed: []
|
||||
, lock: false
|
||||
, quotas: {
|
||||
allocated: {
|
||||
number: group.envUserGroupsNumber
|
||||
, duration: group.envUserGroupsDuration
|
||||
}
|
||||
, consumed: {
|
||||
number: 0
|
||||
, duration: 0
|
||||
}
|
||||
, defaultGroupsNumber: user.email !== group.owner.email ?
|
||||
0 :
|
||||
group.envUserGroupsNumber
|
||||
, defaultGroupsDuration: user.email !== group.owner.email ?
|
||||
0 :
|
||||
group.envUserGroupsDuration
|
||||
, defaultGroupsRepetitions: user.email !== group.owner.email ?
|
||||
0 :
|
||||
group.envUserGroupsRepetitions
|
||||
, repetitions: group.envUserGroupsRepetitions
|
||||
}
|
||||
}
|
||||
}))
|
||||
.then(function(stats) {
|
||||
if (stats.replaced) {
|
||||
return dbapi.addGroupUser(group.id, user.email)
|
||||
}
|
||||
return stats
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function getDevices() {
|
||||
return db.run(r.table('devices'))
|
||||
.then(function(cursor) {
|
||||
return cursor.toArray()
|
||||
})
|
||||
}
|
||||
|
||||
function updateDevicesForMigration(group) {
|
||||
return getDevices().then(function(devices) {
|
||||
return Promise.map(devices, function(device) {
|
||||
return db.run(r.table('devices').get(device.serial).update({
|
||||
group: {
|
||||
id: group.id
|
||||
, name: group.name
|
||||
, lifeTime: group.dates[0]
|
||||
, owner: group.owner
|
||||
, origin: group.id
|
||||
, class: group.class
|
||||
, repetitions: group.repetitions
|
||||
, originName: group.name
|
||||
, lock: false
|
||||
}}
|
||||
))
|
||||
.then(function(stats) {
|
||||
if (stats.replaced) {
|
||||
return dbapi.addOriginGroupDevice(group, device.serial)
|
||||
}
|
||||
return stats
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return dbapi.createGroup({
|
||||
name: env.STF_ROOT_GROUP_NAME
|
||||
, owner: {
|
||||
|
@ -65,6 +138,12 @@ dbapi.createBootStrap = function(env) {
|
|||
, email: group.owner.email
|
||||
, ip: '127.0.0.1'
|
||||
})
|
||||
.then(function() {
|
||||
return updateUsersForMigration(group)
|
||||
})
|
||||
.then(function() {
|
||||
return updateDevicesForMigration(group)
|
||||
})
|
||||
.then(function() {
|
||||
return dbapi.reserveUserGroupInstance(group.owner.email)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue