127.0.0.1:8000 watch-together / master tools / populate_user_prefs.js
master

Tree @master (Download .tar.gz)

populate_user_prefs.js @masterraw · history · blame

require('dotenv').config();

const utils = require('../server/utils');

utils.query("SELECT user_id, email FROM users").then(function(users) {
    return Promise.all(users.map(function(user) {
        return utils.query(
            "SELECT * FROM user_prefs WHERE user_id=?",
            [user.user_id]
        ).then(function([prefs]) {
            if (!prefs) {
                return utils.query(
                    "INSERT INTO user_prefs SET user_id=?",
                    [user.user_id]
                ).then(function() {
                    console.log("Prefs initialized for", user.email);
                });
            }
        });
    }))
}).then(function() {
    process.exit(0);
}).catch(function(error) {
    console.error(error);
    process.exit(1);
});