start on building test db from scratch
This commit is contained in:
		
							parent
							
								
									c949c3c3fc
								
							
						
					
					
						commit
						253e14dc9c
					
				
					 2 changed files with 231 additions and 3 deletions
				
			
		
							
								
								
									
										226
									
								
								bin/restore-mastodon-data.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										226
									
								
								bin/restore-mastodon-data.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,226 @@
 | 
				
			||||||
 | 
					const times = require('lodash/times')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const actions = times(30, i => ({
 | 
				
			||||||
 | 
					  post: {
 | 
				
			||||||
 | 
					    text: (i + 1)
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  user: 'admin'
 | 
				
			||||||
 | 
					})).concat([
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'foobar',
 | 
				
			||||||
 | 
					    post: {
 | 
				
			||||||
 | 
					      text: 'hello world'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'foobar',
 | 
				
			||||||
 | 
					    post: {
 | 
				
			||||||
 | 
					      text: "here's a kitten",
 | 
				
			||||||
 | 
					      media: ['kitten1.jpg']
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'foobar',
 | 
				
			||||||
 | 
					    post: {
 | 
				
			||||||
 | 
					      text: "here's a secret kitten",
 | 
				
			||||||
 | 
					      media: ['kitten2.jpg'],
 | 
				
			||||||
 | 
					      sensitive: true
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'foobar',
 | 
				
			||||||
 | 
					    post: {
 | 
				
			||||||
 | 
					      text: "here's 2 kitten photos",
 | 
				
			||||||
 | 
					      media: ['kitten3.jpg', 'kitten4.jpg']
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'foobar',
 | 
				
			||||||
 | 
					    post: {
 | 
				
			||||||
 | 
					      text: "here's an animated kitten gif",
 | 
				
			||||||
 | 
					      media: ['kitten1.gif']
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'foobar',
 | 
				
			||||||
 | 
					    post: {
 | 
				
			||||||
 | 
					      text: "here's a secret animated kitten gif",
 | 
				
			||||||
 | 
					      media: ['kitten2.gif'],
 | 
				
			||||||
 | 
					      sensitive: true
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'foobar',
 | 
				
			||||||
 | 
					    post: {
 | 
				
			||||||
 | 
					      text: "content warning",
 | 
				
			||||||
 | 
					      spoiler: 'CW'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'foobar',
 | 
				
			||||||
 | 
					    post: {
 | 
				
			||||||
 | 
					      text: "here's a video",
 | 
				
			||||||
 | 
					      media: ['kitten1.mp4']
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'foobar',
 | 
				
			||||||
 | 
					    post: {
 | 
				
			||||||
 | 
					      text: "here's a secret video",
 | 
				
			||||||
 | 
					      media: ['kitten2.mp4']
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'foobar',
 | 
				
			||||||
 | 
					    post: {
 | 
				
			||||||
 | 
					      text: "here's a kitten with a CW",
 | 
				
			||||||
 | 
					      media: ['kitten5.jpg'],
 | 
				
			||||||
 | 
					      sensitive: true,
 | 
				
			||||||
 | 
					      spoiler: 'kitten CW'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  // notifications for foobar
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'admin',
 | 
				
			||||||
 | 
					    follow: 'foobar'
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'admin',
 | 
				
			||||||
 | 
					    post: {
 | 
				
			||||||
 | 
					      text: '@foobar hello foobar',
 | 
				
			||||||
 | 
					      privacy: 'unlisted'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'quux',
 | 
				
			||||||
 | 
					    follow: 'foobar'
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'admin',
 | 
				
			||||||
 | 
					    post: {
 | 
				
			||||||
 | 
					      internalId: 3,
 | 
				
			||||||
 | 
					      text: '@foobar notification of direct message',
 | 
				
			||||||
 | 
					      privacy: 'direct'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'admin',
 | 
				
			||||||
 | 
					    favorite: 3
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'admin',
 | 
				
			||||||
 | 
					    post: {
 | 
				
			||||||
 | 
					      internalId: 4,
 | 
				
			||||||
 | 
					      text: '@foobar notification of followers-only message',
 | 
				
			||||||
 | 
					      privacy: 'private'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'admin',
 | 
				
			||||||
 | 
					    favorite: 4
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'admin',
 | 
				
			||||||
 | 
					    post: {
 | 
				
			||||||
 | 
					      internalId: 1,
 | 
				
			||||||
 | 
					      text: '@foobar notification of unlisted message',
 | 
				
			||||||
 | 
					      privacy: 'unlisted'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'admin',
 | 
				
			||||||
 | 
					    boost: 1
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'foobar',
 | 
				
			||||||
 | 
					    post: {
 | 
				
			||||||
 | 
					      internalId: 2,
 | 
				
			||||||
 | 
					      text: 'this is unlisted',
 | 
				
			||||||
 | 
					      privacy: 'private'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'admin',
 | 
				
			||||||
 | 
					    boost: 2
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'admin',
 | 
				
			||||||
 | 
					    favorite: 2
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'quux',
 | 
				
			||||||
 | 
					    post: {
 | 
				
			||||||
 | 
					      internalId: 5,
 | 
				
			||||||
 | 
					      text: 'pinned toot 1',
 | 
				
			||||||
 | 
					      privacy: 'private'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'quux',
 | 
				
			||||||
 | 
					    post: {
 | 
				
			||||||
 | 
					      internalId: 6,
 | 
				
			||||||
 | 
					      text: 'pinned toot 2',
 | 
				
			||||||
 | 
					      privacy: 'private'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					]).concat(times(25, i => ({
 | 
				
			||||||
 | 
					  user: 'quux',
 | 
				
			||||||
 | 
					  post: {
 | 
				
			||||||
 | 
					    internalId: 100 + i,
 | 
				
			||||||
 | 
					    text: 'unlisted thread ' + (i + 1),
 | 
				
			||||||
 | 
					    privacy: 'private',
 | 
				
			||||||
 | 
					    inReplyTo: i > 0 && (100 + i)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}))).concat([
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'quux',
 | 
				
			||||||
 | 
					    pin: 5
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'quux',
 | 
				
			||||||
 | 
					    pin: 6
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'admin',
 | 
				
			||||||
 | 
					    boost: 5
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'admin',
 | 
				
			||||||
 | 
					    favorite: 5
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'foobar',
 | 
				
			||||||
 | 
					    favorite: 5
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'admin',
 | 
				
			||||||
 | 
					    favorite: 6
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'ExternalLinks',
 | 
				
			||||||
 | 
					    post: {
 | 
				
			||||||
 | 
					      text: 'here are some hashtags: #kitten #kitties',
 | 
				
			||||||
 | 
					      privacy: 'private'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'ExternalLinks',
 | 
				
			||||||
 | 
					    post: {
 | 
				
			||||||
 | 
					      text: 'here are some external links: https://joinmastodon.org https://github.com/tootsuite/mastodon',
 | 
				
			||||||
 | 
					      privacy: 'private'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    user: 'ExternalLinks',
 | 
				
			||||||
 | 
					    post: {
 | 
				
			||||||
 | 
					      text: 'here are some users: @admin @quux',
 | 
				
			||||||
 | 
					      privacy: 'private'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					async function restoreMastodonData () {
 | 
				
			||||||
 | 
					  console.log('Restoring mastodon data...')
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module.exports = restoreMastodonData
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,4 @@
 | 
				
			||||||
 | 
					const restoreMastodonData = require ('./restore-mastodon-data')
 | 
				
			||||||
const pify = require('pify')
 | 
					const pify = require('pify')
 | 
				
			||||||
const exec = require('child-process-promise').exec
 | 
					const exec = require('child-process-promise').exec
 | 
				
			||||||
const spawn = require('child-process-promise').spawn
 | 
					const spawn = require('child-process-promise').spawn
 | 
				
			||||||
| 
						 | 
					@ -30,8 +31,8 @@ async function cloneMastodon () {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function restoreMastodonData () {
 | 
					async function setupMastodonDatabase() {
 | 
				
			||||||
  console.log('Restoring mastodon data...')
 | 
					  console.log('Setting up mastodon database...')
 | 
				
			||||||
  try {
 | 
					  try {
 | 
				
			||||||
    await exec('dropdb mastodon_development', {cwd: mastodonDir})
 | 
					    await exec('dropdb mastodon_development', {cwd: mastodonDir})
 | 
				
			||||||
  } catch (e) { /* ignore */ }
 | 
					  } catch (e) { /* ignore */ }
 | 
				
			||||||
| 
						 | 
					@ -70,8 +71,9 @@ async function runMastodon () {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function main () {
 | 
					async function main () {
 | 
				
			||||||
  await cloneMastodon()
 | 
					  await cloneMastodon()
 | 
				
			||||||
  await restoreMastodonData()
 | 
					  await setupMastodonDatabase()
 | 
				
			||||||
  await runMastodon()
 | 
					  await runMastodon()
 | 
				
			||||||
 | 
					  //await restoreMastodonData()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
process.on('SIGINT', function () {
 | 
					process.on('SIGINT', function () {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue