@palmares/databases
Version:
Add support for working with databases with palmares framework
78 lines (74 loc) • 2.93 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/migrations/makemigrations/asker.ts
var asker_exports = {};
__export(asker_exports, {
asker: () => asker
});
module.exports = __toCommonJS(asker_exports);
var import_core = require("@palmares/core");
var Asker = class Asker2 {
static {
__name(this, "Asker");
}
async theNewAttributeCantHaveNullDoYouWishToContinue(modelName, fieldName) {
const question = `\x1B[0mIf the model \x1B[33m${modelName}\x1B[0m already have data, it can cause issues when migrating the new \x1B[36m${fieldName}\x1B[0m column because you didn't set a \x1B[33mdefaultValue\x1B[0m or \x1B[33mallowNull \x1B[0mis set to \x1B[33mfalse\x1B[0m.
You can safely ignore this message if you didn't add any data to the table.
Press any key to continue or 'CTRL+C' to stop and define the attributes yourself.
`;
const answer = await import_core.std.asker.ask(question);
if (answer.toLowerCase() === "n") return false;
else return true;
}
async didUserRename(modelOrFieldThatWasRenamed, renamedTo) {
const question = `
Did you rename '${modelOrFieldThatWasRenamed}' to '${renamedTo}'? [y/n]
`;
const answer = await import_core.std.asker.ask(question);
if ([
"y",
"n"
].includes(answer)) return answer === "y";
else return false;
}
async didUserRenameToOneOption(valueThatWasRenamed, renamedToOptions) {
const toOptions = renamedToOptions.map((renamedTo, index) => `${index + 1}. ${renamedTo}`);
const explanation = "\nPlease type the corresponding number or leave blank if you have not renamed";
const question = `
Did you rename '${valueThatWasRenamed}' to one of the following options?
${toOptions.join("\n")}
${explanation}
`;
const answer = await import_core.std.asker.ask(question);
if (answer === "") return null;
else {
try {
return renamedToOptions[parseInt(answer) - 1];
} catch {
return null;
}
}
}
};
var asker = new Asker();
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
asker
});