1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-03 17:59:28 +02:00

Merge pull request #1172 from denis99999/group-feature-rethinkdb-migration

Group feature rethinkdb migration
This commit is contained in:
Karol Wrótniak 2020-02-12 17:23:38 +01:00 committed by GitHub
commit 1423826fad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 79 additions and 0 deletions

Binary file not shown.

View file

@ -38,6 +38,79 @@ dbapi.unlockBookingObjects = function() {
dbapi.createBootStrap = function(env) { dbapi.createBootStrap = function(env) {
const now = Date.now() 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({ return dbapi.createGroup({
name: env.STF_ROOT_GROUP_NAME name: env.STF_ROOT_GROUP_NAME
, owner: { , owner: {
@ -65,6 +138,12 @@ dbapi.createBootStrap = function(env) {
, email: group.owner.email , email: group.owner.email
, ip: '127.0.0.1' , ip: '127.0.0.1'
}) })
.then(function() {
return updateUsersForMigration(group)
})
.then(function() {
return updateDevicesForMigration(group)
})
.then(function() { .then(function() {
return dbapi.reserveUserGroupInstance(group.owner.email) return dbapi.reserveUserGroupInstance(group.owner.email)
}) })