/
migrate.js
34 lines (32 loc) · 994 Bytes
/
migrate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#! /usr/bin/env node
'use strict';
let co = require('co');
let thunkify = require('thunkify');
let uuid = require('node-uuid');
let redis = require('redis');
let client = redis.createClient();
client.keys = thunkify(client.keys);
client.lrange = thunkify(client.lrange);
client.rpush = thunkify(client.rpush);
client.del = thunkify(client.del);
co(function *() {
let frontends = yield client.keys('frontend:*');
let apps = yield frontends.map(function (frontend) {
return client.lrange(frontend, 0, -1);
});
yield frontends.map(function (frontend, index) {
return [
client.del(frontend),
// push identifier
client.rpush(frontend, uuid.v4()),
// push backend list
apps[index].slice(1).map(function (backend) {
return client.rpush(frontend, backend);
}),
];
});
}).then(function() {
console.log(arguments);
}, function(err) {
console.log(err.stack);
});