try modifying the test database

This commit is contained in:
Nolan Lawson 2018-03-05 06:32:05 -08:00
parent c949c3c3fc
commit cbf504993c
3 changed files with 167 additions and 0 deletions

View File

@ -8,6 +8,7 @@ const stat = pify(fs.stat.bind(fs))
const writeFile = pify(fs.writeFile.bind(fs))
const mkdirp = pify(require('mkdirp'))
const waitForMastodonToStart = require('./wait-for-mastodon-to-start')
const pgPromise = require('pg-promise')
const envFile = `
PAPERCLIP_SECRET=foo
@ -46,6 +47,45 @@ async function restoreMastodonData () {
await exec(`tar -xzf "${tgzFile}"`, {cwd: systemDir})
}
async function modifyMastodonData () {
const pgp = pgPromise()
const db = pgp({
host: '127.0.0.1',
port: 5432,
database: 'mastodon_development',
user: process.env.USER
})
let tables = [
'users', 'statuses', 'status_pins', 'conversations', 'oauth_access_grants',
'oauth_applications', 'session_activations', 'web_settings', 'oauth_access_tokens',
'mentions', 'notifications', 'favourites', 'follows', 'media_attachments',
'preview_cards', 'stream_entries'
]
for (let table of tables) {
let results = await db.any(
`SELECT id FROM ${table} ORDER BY created_at DESC`,
[])
let referenceDate = Date.now() - (24 * 60 * 60 * 1000)
let count = 0
for (let row of results) {
let updated = new Date(referenceDate - (1000 * ++count))
let created = new Date(referenceDate - (1000 * ++count))
try {
await db.none(
`UPDATE ${table} SET updated_at = $1, created_at = $2 WHERE id = $3`,
[updated, created, row.id])
} catch (e) {
await db.none(
`UPDATE ${table} SET created_at = $1 WHERE id = $2`,
[created, row.id])
}
}
}
db.$pool.end()
}
async function runMastodon () {
console.log('Running mastodon...')
let cmds = [
@ -71,6 +111,7 @@ async function runMastodon () {
async function main () {
await cloneMastodon()
await restoreMastodonData()
await modifyMastodonData()
await runMastodon()
}

125
package-lock.json generated
View File

@ -1346,6 +1346,11 @@
"isarray": "1.0.0"
}
},
"buffer-writer": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-1.0.1.tgz",
"integrity": "sha1-Iqk2kB4wKa/NdUfrRIfOtpejvwg="
},
"buffer-xor": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz",
@ -5245,6 +5250,11 @@
"resolved": "https://registry.npmjs.org/js-base64/-/js-base64-2.4.0.tgz",
"integrity": "sha512-Wehd+7Pf9tFvGb+ydPm9TjYjV8X1YHOVyG8QyELZxEMqOhemVwGRmoG8iQ/soqI3n8v4xn59zaLxiCJiaaRzKA=="
},
"js-string-escape": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/js-string-escape/-/js-string-escape-1.0.1.tgz",
"integrity": "sha1-4mJbrbwNZ8dTPp7cEGjFh65BN+8="
},
"js-tokens": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz",
@ -5623,6 +5633,11 @@
"pify": "3.0.0"
}
},
"manakin": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/manakin/-/manakin-0.5.1.tgz",
"integrity": "sha1-xKcRb2sA3z1fGjetPKUV0iBlplg="
},
"map-cache": {
"version": "0.2.2",
"resolved": "https://registry.npmjs.org/map-cache/-/map-cache-0.2.2.tgz",
@ -6551,6 +6566,11 @@
"resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz",
"integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M="
},
"packet-reader": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-0.3.1.tgz",
"integrity": "sha1-zWLmCvjX/qinBexP+ZCHHEaHHyc="
},
"pako": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.6.tgz",
@ -6704,6 +6724,83 @@
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
"integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns="
},
"pg": {
"version": "7.4.1",
"resolved": "https://registry.npmjs.org/pg/-/pg-7.4.1.tgz",
"integrity": "sha512-Pi5qYuXro5PAD9xXx8h7bFtmHgAQEG6/SCNyi7gS3rvb/ZQYDmxKchfB0zYtiSJNWq9iXTsYsHjrM+21eBcN1A==",
"requires": {
"buffer-writer": "1.0.1",
"js-string-escape": "1.0.1",
"packet-reader": "0.3.1",
"pg-connection-string": "0.1.3",
"pg-pool": "2.0.3",
"pg-types": "1.12.1",
"pgpass": "1.0.2",
"semver": "4.3.2"
},
"dependencies": {
"semver": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-4.3.2.tgz",
"integrity": "sha1-x6BxWKgL7dBSNVt3DYLWZA+AO+c="
}
}
},
"pg-connection-string": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-0.1.3.tgz",
"integrity": "sha1-2hhHsglA5C7hSSvq9l1J2RskXfc="
},
"pg-minify": {
"version": "0.5.4",
"resolved": "https://registry.npmjs.org/pg-minify/-/pg-minify-0.5.4.tgz",
"integrity": "sha512-GHB2v4OiMHDgwiHH86ZWNfvgEPVijrnfuWLQocseX6Zlf30k+x0imA65zBy4skIpEwfBBEplIEEKP4n3q9KkVA=="
},
"pg-pool": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-2.0.3.tgz",
"integrity": "sha1-wCIDLIlJ8xKk+R+2QJzgQHa+Mlc="
},
"pg-promise": {
"version": "8.1.1",
"resolved": "https://registry.npmjs.org/pg-promise/-/pg-promise-8.1.1.tgz",
"integrity": "sha512-+iyIcRXFunFB96uoUPAwqADm2KfAE0ur5iRtZjl8/pOM3g0IgOEtarXNiStf1G1ToiFoXhGoLiaUg11s3wINQg==",
"requires": {
"manakin": "0.5.1",
"pg": "7.4.1",
"pg-minify": "0.5.4",
"spex": "2.0.2"
}
},
"pg-types": {
"version": "1.12.1",
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-1.12.1.tgz",
"integrity": "sha1-1kCH45A7WP+q0nnnWVxSIIoUw9I=",
"requires": {
"postgres-array": "1.0.2",
"postgres-bytea": "1.0.0",
"postgres-date": "1.0.3",
"postgres-interval": "1.1.1"
}
},
"pgpass": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.2.tgz",
"integrity": "sha1-Knu0G2BltnkH6R2hsHwYR8h3swY=",
"requires": {
"split": "1.0.1"
},
"dependencies": {
"split": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/split/-/split-1.0.1.tgz",
"integrity": "sha512-mTyOoPbrivtXnwnIxZRFYRrPNtEFKlpB2fvjSnCQUiAA6qAZzqwna5envK4uk6OIeP17CsdF3rSBGYVBsU0Tkg==",
"requires": {
"through": "2.3.8"
}
}
}
},
"pify": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
@ -7382,6 +7479,29 @@
"uniqs": "2.0.0"
}
},
"postgres-array": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-1.0.2.tgz",
"integrity": "sha1-jgsy6wO/d6XAp4UeBEHBaaJWojg="
},
"postgres-bytea": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz",
"integrity": "sha1-AntTPAqokOJtFy1Hz5zOzFIazTU="
},
"postgres-date": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.3.tgz",
"integrity": "sha1-4tiXAu/bJY/52c7g/pG9BpdSV6g="
},
"postgres-interval": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.1.1.tgz",
"integrity": "sha512-OkuCi9t/3CZmeQreutGgx/OVNv9MKHGIT5jH8KldQ4NLYXkvmT9nDVxEuCENlNwhlGPE374oA/xMqn05G49pHA==",
"requires": {
"xtend": "4.0.1"
}
},
"prelude-ls": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz",
@ -8797,6 +8917,11 @@
"resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-1.2.2.tgz",
"integrity": "sha1-yd96NCRZSt5r0RkA1ZZpbcBrrFc="
},
"spex": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/spex/-/spex-2.0.2.tgz",
"integrity": "sha512-LU6TS3qTEpRth+FnNs/fIWEmridYN7JmaN2k1Jk31XVC4ex7+wYxiHMnKguRxS7oKjbOFl4H6seeWNDFFgkVRg=="
},
"split": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/split/-/split-0.3.3.tgz",

View File

@ -47,6 +47,7 @@
"npm-run-all": "^4.1.2",
"p-any": "^1.1.0",
"performance-now": "^2.1.0",
"pg-promise": "^8.1.1",
"pify": "^3.0.0",
"quick-lru": "^1.1.0",
"requestidlecallback": "^0.3.0",