Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env node
- const pgp = require('pg-promise')()
- const fs = require('fs')
- const _ = require('lodash')
- const Bluebird = require('bluebird')
- const environment = require('../lib/environment')
- const connection = pgp({
- user: environment.postgres.user,
- password: environment.postgres.password,
- database: 'jellyfish',
- port: environment.postgres.port,
- host: environment.postgres.host
- })
- const run = async (skip, limit) => {
- const results = await connection.any(`
- SELECT * FROM cards WHERE linked_at IS NULL OFFSET ${skip} LIMIT ${limit}`)
- console.log(`Limit ${limit} on Offset ${skip}, got ${results.length} results`)
- if (results.length === 0) {
- await connection.$pool.end()
- return
- }
- const ids = results.map((row) => {
- return `'${row.id}'`
- })
- console.time('updating')
- await connection.any(`
- UPDATE cards SET linked_at = '{}'::jsonb WHERE id IN (${ids.join(', ')})
- `)
- console.timeEnd('updating')
- await run(skip + limit, limit)
- }
- run(0, 100).catch((error) => {
- console.error(error)
- process.exit(1)
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement