Skip to content

Instantly share code, notes, and snippets.

@paulsonnentag
Created April 17, 2018 09:08
Show Gist options
  • Save paulsonnentag/fd0f187cd501bde639e96b169a2cae35 to your computer and use it in GitHub Desktop.
Save paulsonnentag/fd0f187cd501bde639e96b169a2cae35 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const path = require('path');
const {spaceName, paperNumbers} = require('./config.json');
const knex = require('knex')({
client: 'pg',
connection: process.env.DATABASE_URL,
});
const initialCode = fs.readFileSync(path.join(__dirname, 'initial-code.js'), 'utf8')
function getInitialCode (id) {
return `// Program ${id}
` + initialCode
}
(async () => {
// delete existing programs in space
await knex('programs').where({spaceName}).delete()
// create program with initial code for each paper
await Promise.all(paperNumbers.map((number, index) => {
const code = getInitialCode(index + 1)
console.log(`create paper #${number}`)
return knex('programs').insert({spaceName, number, originalCode: code, currentCode: code})
}));
console.log('done');
process.exit(1)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment