This commit is contained in:
syuilo 2018-04-01 19:53:35 +09:00
parent 0cb6fbea8c
commit 109199e445
11 changed files with 0 additions and 497 deletions

View File

@ -1,12 +0,0 @@
#!/bin/sh
certbot certonly --standalone\
-d $1\
-d api.$1\
-d auth.$1\
-d docs.$1\
-d ch.$1\
-d stats.$1\
-d status.$1\
-d dev.$1\
-d file.$2\

View File

@ -1,71 +0,0 @@
// for Node.js interpret
const { default: db } = require('../../built/db/mongodb')
const { default: DriveFile, getGridFSBucket } = require('../../built/api/models/drive-file')
const { Duplex } = require('stream')
const { default: zip } = require('@prezzemolo/zip')
const writeToGridFS = (bucket, buffer, ...rest) => new Promise((resolve, reject) => {
const writeStream = bucket.openUploadStreamWithId(...rest)
const dataStream = new Duplex()
dataStream.push(buffer)
dataStream.push(null)
writeStream.once('finish', resolve)
writeStream.on('error', reject)
dataStream.pipe(writeStream)
})
const migrateToGridFS = async (doc) => {
const id = doc._id
const buffer = doc.data ? doc.data.buffer : Buffer.from([0x00]) // アップロードのバグなのか知らないけどなぜか data が存在しない drive_file ドキュメントがまれにあることがわかったので
const created_at = doc.created_at
const name = doc.name
const type = doc.type
delete doc._id
delete doc.created_at
delete doc.datasize
delete doc.hash
delete doc.data
delete doc.name
delete doc.type
const bucket = await getGridFSBucket()
const added = await writeToGridFS(bucket, buffer, id, name, { contentType: type, metadata: doc })
const result = await DriveFile.update(id, {
$set: {
uploadDate: created_at
}
})
return added && result.ok === 1
}
async function main() {
const count = await db.get('drive_files').count({});
console.log(`there are ${count} files.`)
const dop = Number.parseInt(process.argv[2]) || 5
const idop = ((count - (count % dop)) / dop) + 1
return zip(
1,
async (time) => {
console.log(`${time} / ${idop}`)
const doc = await db.get('drive_files').find({}, { limit: dop, skip: time * dop })
return Promise.all(doc.map(migrateToGridFS))
},
idop
).then(a => {
const rv = []
a.forEach(e => rv.push(...e))
return rv
})
}
main().then(console.dir).catch(console.error)

View File

@ -1,50 +0,0 @@
// for Node.js interpret
/**
* change usage of GridFS filename
* see commit fb422b4d603c53a70712caba55b35a48a8c2e619
*/
const { default: DriveFile } = require('../../built/api/models/drive-file')
async function applyNewChange (doc) {
const result = await DriveFile.update(doc._id, {
$set: {
filename: doc.metadata.name
},
$unset: {
'metadata.name': ''
}
})
return result.ok === 1
}
async function main () {
const query = {
'metadata.name': {
$exists: true
}
}
const count = await DriveFile.count(query)
const dop = Number.parseInt(process.argv[2]) || 5
const idop = ((count - (count % dop)) / dop) + 1
return zip(
1,
async (time) => {
console.log(`${time} / ${idop}`)
const doc = await DriveFile.find(query, {
limit: dop, skip: time * dop
})
return Promise.all(doc.map(applyNewChange))
},
idop
).then(a => {
const rv = []
a.forEach(e => rv.push(...e))
return rv
})
}
main().then(console.dir).catch(console.error)

View File

@ -1,47 +0,0 @@
// for Node.js interpret
const { default: DriveFile } = require('../../built/api/models/drive-file')
const { default: zip } = require('@prezzemolo/zip')
const migrate = async (doc) => {
const result = await DriveFile.update(doc._id, {
$set: {
contentType: doc.metadata.type
},
$unset: {
'metadata.type': ''
}
})
return result.ok === 1
}
async function main() {
const query = {
'metadata.type': {
$exists: true
}
}
const count = await DriveFile.count(query);
const dop = Number.parseInt(process.argv[2]) || 5
const idop = ((count - (count % dop)) / dop) + 1
return zip(
1,
async (time) => {
console.log(`${time} / ${idop}`)
const doc = await DriveFile.find(query, {
limit: dop, skip: time * dop
})
return Promise.all(doc.map(migrate))
},
idop
).then(a => {
const rv = []
a.forEach(e => rv.push(...e))
return rv
})
}
main().then(console.dir).catch(console.error)

View File

@ -1,88 +0,0 @@
const uuid = require('uuid');
const { default: User } = require('../../built/api/models/user')
const { default: zip } = require('@prezzemolo/zip')
const home = {
left: [
'profile',
'calendar',
'activity',
'rss-reader',
'trends',
'photo-stream',
'version'
],
right: [
'broadcast',
'notifications',
'user-recommendation',
'recommended-polls',
'server',
'donation',
'nav',
'tips'
]
};
const migrate = async (doc) => {
//#region Construct home data
const homeData = [];
home.left.forEach(widget => {
homeData.push({
name: widget,
id: uuid(),
place: 'left',
data: {}
});
});
home.right.forEach(widget => {
homeData.push({
name: widget,
id: uuid(),
place: 'right',
data: {}
});
});
//#endregion
const result = await User.update(doc._id, {
$unset: {
data: ''
},
$set: {
'settings': {},
'client_settings.home': homeData,
'client_settings.show_donation': false
}
})
return result.ok === 1
}
async function main() {
const count = await User.count();
console.log(`there are ${count} users.`)
const dop = Number.parseInt(process.argv[2]) || 5
const idop = ((count - (count % dop)) / dop) + 1
return zip(
1,
async (time) => {
console.log(`${time} / ${idop}`)
const docs = await User.find({}, { limit: dop, skip: time * dop })
return Promise.all(docs.map(migrate))
},
idop
).then(a => {
const rv = []
a.forEach(e => rv.push(...e))
return rv
})
}
main().then(console.dir).catch(console.error)

View File

@ -1,71 +0,0 @@
// for Node.js interpret
const { default: DriveFile, getGridFSBucket } = require('../../built/api/models/drive-file')
const { default: zip } = require('@prezzemolo/zip')
const _gm = require('gm');
const gm = _gm.subClass({
imageMagick: true
});
const migrate = doc => new Promise(async (res, rej) => {
const bucket = await getGridFSBucket();
const readable = bucket.openDownloadStream(doc._id);
gm(readable)
.setFormat('ppm')
.resize(1, 1)
.toBuffer(async (err, buffer) => {
if (err) {
console.error(err);
res(false);
return;
}
const r = buffer.readUInt8(buffer.length - 3);
const g = buffer.readUInt8(buffer.length - 2);
const b = buffer.readUInt8(buffer.length - 1);
const result = await DriveFile.update(doc._id, {
$set: {
'metadata.properties.average_color': [r, g, b]
}
})
res(result.ok === 1);
});
});
async function main() {
const query = {
contentType: {
$in: [
'image/png',
'image/jpeg'
]
}
}
const count = await DriveFile.count(query);
const dop = Number.parseInt(process.argv[2]) || 5
const idop = ((count - (count % dop)) / dop) + 1
return zip(
1,
async (time) => {
console.log(`${time} / ${idop}`)
const doc = await DriveFile.find(query, {
limit: dop, skip: time * dop
})
return Promise.all(doc.map(migrate))
},
idop
).then(a => {
const rv = []
a.forEach(e => rv.push(...e))
return rv
})
}
main().then(console.dir).catch(console.error)

View File

@ -1,67 +0,0 @@
// for Node.js interpret
const { default: Post } = require('../../built/api/models/post')
const { default: zip } = require('@prezzemolo/zip')
const migrate = async (post) => {
const x = {};
if (post.reply_id != null) {
const reply = await Post.findOne({
_id: post.reply_id
});
x['_reply.user_id'] = reply.user_id;
}
if (post.repost_id != null) {
const repost = await Post.findOne({
_id: post.repost_id
});
x['_repost.user_id'] = repost.user_id;
}
if (post.reply_id != null || post.repost_id != null) {
const result = await Post.update(post._id, {
$set: x,
});
return result.ok === 1;
} else {
return true;
}
}
async function main() {
const query = {
$or: [{
reply_id: {
$exists: true,
$ne: null
}
}, {
repost_id: {
$exists: true,
$ne: null
}
}]
}
const count = await Post.count(query);
const dop = Number.parseInt(process.argv[2]) || 5
const idop = ((count - (count % dop)) / dop) + 1
return zip(
1,
async (time) => {
console.log(`${time} / ${idop}`)
const doc = await Post.find(query, {
limit: dop, skip: time * dop
})
return Promise.all(doc.map(migrate))
},
idop
).then(a => {
const rv = []
a.forEach(e => rv.push(...e))
return rv
})
}
main().then(console.dir).catch(console.error)

View File

@ -1,46 +0,0 @@
// for Node.js interpret
const { default: Othello } = require('../../built/api/models/othello-game')
const { default: zip } = require('@prezzemolo/zip')
const migrate = async (doc) => {
const x = {};
doc.logs.forEach(log => {
log.color = log.color == 'black';
});
const result = await Othello.update(doc._id, {
$set: {
logs: doc.logs
}
});
return result.ok === 1;
}
async function main() {
const count = await Othello.count({});
const dop = Number.parseInt(process.argv[2]) || 5
const idop = ((count - (count % dop)) / dop) + 1
return zip(
1,
async (time) => {
console.log(`${time} / ${idop}`)
const doc = await Othello.find({}, {
limit: dop, skip: time * dop
})
return Promise.all(doc.map(migrate))
},
idop
).then(a => {
const rv = []
a.forEach(e => rv.push(...e))
return rv
})
}
main().then(console.dir).catch(console.error)

View File

@ -1,18 +0,0 @@
db.users.find({}).forEach(function(user) {
print(user._id);
db.users.update({ _id: user._id }, {
$rename: {
bio: 'description'
},
$unset: {
location: '',
birthday: ''
},
$set: {
profile: {
location: user.location || null,
birthday: user.birthday || null
}
}
}, false, false);
});

View File

@ -1,22 +0,0 @@
db.users.update({}, {
$unset: {
likes_count: 1,
liked_count: 1
}
}, false, true)
db.likes.renameCollection('post_reactions')
db.post_reactions.update({}, {
$set: {
reaction: 'like'
}
}, false, true)
db.posts.update({}, {
$rename: {
likes_count: 'reaction_counts.like'
}
}, false, true);
db.notifications.remove({})

View File

@ -1,5 +0,0 @@
db.posts.update({}, {
$rename: {
reply_to_id: 'reply_id'
}
}, false, true);