Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try {
// TODO: DRY with "up" command
const knex = db.connect(db.thisUrl(name));
const [batch, filenames] = await knex.migrate.latest();
if (filenames.length > 0) {
console.log(`Migration batch #${batch} applied!`);
filenames.forEach(filename =>
console.log(`↑ ${c.yellowBright(filename)}`));
console.log();
}
} catch (err) {
console.error(c.redBright('Knex migration failed:'), err);
if (opts.switch) {
console.log(
`Switching back to ${c.yellowBright(current)}`
+ ' and dropping the new database...',
);
db.switchTo(current);
}
await knexFallback.raw(`drop database "${name}"`);
console.log('Done.');
throw new Error('Migration failed; database dropped.');
}
await printLatest();
}
return name;
};
};
exports.handler = async (yargs) => {
const db = require('../db')();
const { verbose: explictlyVerbose } = yargs;
const showMigrations = explictlyVerbose !== undefined ? explictlyVerbose : !!db.config.migrations;
try {
// TODO: refactor to use printLatestMigration (maybe that func can not print them?)
const name = db.thisDb();
let migration = [];
if (showMigrations) {
const knex = db.connectAsSuper(db.thisUrl(name));
migration = await migrationOutput(knex, true);
}
console.log(`* ${c.yellowBright(name)} ${migration.join(' ')}`);
process.exit(0);
} catch (err) {
const { message } = err;
console.error(`postgres: ${c.redBright(message)}`);
process.exit(1);
}
};
return async () => {
const knex = db.connect(name ? db.thisUrl(name) : db.thisUrl());
const latest = await knex(`${schema}.${table}`)
.orderBy('id', 'desc')
.first('name', 'migration_time');
console.log(
`* ${c.yellowBright(name || db.thisDb())}`
+ ` ${c.underline(c.greenBright(latest.name))}`
+ ` ${c.blueBright(timestamp(latest.migration_time))}`,
);
return new Promise(resolve =>
knex.destroy(() => {
resolve();
}));
};
};
return exports.quit(true).catch(err => {
if (err && typeof err === "string") {
logger.error(TITLE, warnIcon, 'quit failed !',
'\n\t' + colors.yellowBright('微信开发者工具需开启[服务端口] :'),
'\n' + colors.yellowBright(err)
);
}
})
}
const config = require('../pgshrc/read');
const envMap = {};
Object.values(config.vars).forEach((envKey) => {
envMap[envKey] = '';
});
console.log(c.yellowBright(
`${c.underline('.pgshrc')} exists, but ${c.underline('.env')} does not!`,
));
console.log('Try creating one, e.g.\n');
console.log(stringifyEnv(envMap));
return endProgram(1);
}
console.log(
`${c.yellowBright('pgsh')} manages your database`,
`connection via variables in ${c.underline('.env')}.`,
);
try {
console.log(
`In ${c.cyan('url')} mode, one variable holds the entire`,
'connection string.',
);
console.log(
`In ${c.cyan('split')} mode, you have separate variables for`,
'user, host, password, etc.\n',
);
const { mode } = await prompt(
{
name: 'mode',
filenames.forEach(filename =>
console.log(`↑ ${c.yellowBright(filename)}`));
console.log();
async (db) => {
const { pickTemplate } = await prompt({
type: 'toggle',
name: 'pickTemplate',
message:
`${c.bold('Do you need to change the template database?')}`
+ ` (default ${c.yellowBright(config.template)})`,
});
const template = pickTemplate
? await pick(db, 'Which template do you want to use?', true)
: config.template;
const { name } = await prompt({
type: 'input',
name: 'name',
message: 'What should the new database be called?',
});
console.log();
console.log(`Going to create ${c.yellowBright(name)}...`);
await create(db)(name, { template, switch: false });
console.log('Done!');
function getTime(level) {
const time = new Date().toLocaleTimeString('en-US', { hour12: false });
if (noColor) {
return '[' + time + ']';
} else {
switch (level) {
case 1:
return colors.yellowBright('[') + colors.gray(time) + colors.yellowBright(']');
case 2:
return colors.red('[') + colors.gray(time) + colors.red(']');
case -1:
return colors.gray('[') + colors.gray(time) + colors.gray(']');
default:
return '[' + colors.gray(time) + ']';
}
}
}
function warnNotInstelled() {
logger.warn(
colors.bgRed('\t\t 微信开发者工具未安装 '),
colors.yellowBright('\n\t\t\t 请手动下载安装工具 :'),
colors.yellowBright('\n\tdownload link https://developers.weixin.qq.com/miniprogram/en/dev/devtools/download.html'),
colors.yellowBright('\n\t下载和安装链接 https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html')
, '\n');
}