rake-db 2.37.13 → 2.37.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ import path, { join } from "node:path";
3
3
  import { fileURLToPath, pathToFileURL } from "node:url";
4
4
  import { createDbWithAdapter } from "pqb";
5
5
  import fs, { mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
6
- const RAKE_DB_LOCK_KEY = "8582141715823621641";
6
+ const RAKE_DB_LOCK_KEY = 8582141715823621641n;
7
7
  const getFirstWordAndRest = (input) => {
8
8
  const i = input.search(/(?=[A-Z])|[-_ ]/);
9
9
  if (i !== -1) {
@@ -65,7 +65,7 @@ const transaction = (adapter, config, fn) => {
65
65
  const searchPath = config.transactionSearchPath;
66
66
  return adapter.transaction(void 0, searchPath ? { setConfig: { search_path: typeof searchPath === "function" ? searchPath() : searchPath } } : void 0, fn);
67
67
  };
68
- const queryLock = (trx) => trx.query(`SELECT pg_advisory_xact_lock('${RAKE_DB_LOCK_KEY}')`);
68
+ const queryLock = (trx, key = RAKE_DB_LOCK_KEY) => trx.query(`SELECT pg_advisory_xact_lock('${key}')`);
69
69
  const getCliParam = (args, name) => {
70
70
  if (args) {
71
71
  const key = "--" + name;
@@ -3459,7 +3459,7 @@ const migrateOrRollback = async (trx, config, set, versions, count, up, redo, fo
3459
3459
  set.migrations.reverse();
3460
3460
  }
3461
3461
  }
3462
- if (!skipLock) await queryLock(trx);
3462
+ if (!skipLock) await queryLock(trx, config.migrationLockKey);
3463
3463
  let db;
3464
3464
  const beforeMigrate = config[up ? "beforeMigrate" : "beforeRollback"];
3465
3465
  if (beforeMigrate || config.beforeChange) {
@@ -3613,7 +3613,8 @@ const CSI = `[`;
3613
3613
  const cursorShow = `${CSI}?25h`;
3614
3614
  const cursorHide = `${CSI}?25l`;
3615
3615
  const { stdin, stdout } = process;
3616
- const visibleChars = (s) => s.replace(/[\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d/#&.:=?%@~_]*)*)?\u0007)|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PRZcf-ntqry=><~]))/g, "").length;
3616
+ const stripAnsi = (s) => s.replace(/[\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d/#&.:=?%@~_]*)*)?\u0007)|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PRZcf-ntqry=><~]))/g, "");
3617
+ const visibleChars = (s) => stripAnsi(s).length;
3617
3618
  const clear = (text) => {
3618
3619
  const rows = text.split(/\r?\n/).reduce((rows, line) => rows + 1 + Math.floor(Math.max(visibleChars(line) - 1, 0) / stdout.columns), 0);
3619
3620
  let clear = "";
@@ -3623,9 +3624,10 @@ const clear = (text) => {
3623
3624
  }
3624
3625
  return clear;
3625
3626
  };
3626
- const prompt = async ({ render, onKeyPress, validate, value, cursor: showCursor }) => {
3627
+ const prompt = async ({ message, render, onKeyPress, validate, value, cursor: showCursor }) => {
3628
+ if (!stdin.isTTY) throw new RakeDbError(`Cannot prompt "${stripAnsi(message)}": stdin is not a TTY, run the command in an interactive terminal`);
3627
3629
  stdin.resume();
3628
- if (stdin.isTTY) stdin.setRawMode(true);
3630
+ stdin.setRawMode(true);
3629
3631
  stdin.setEncoding("utf-8");
3630
3632
  if (!showCursor) stdout.write(cursorHide);
3631
3633
  return new Promise((res) => {
@@ -3650,7 +3652,7 @@ const prompt = async ({ render, onKeyPress, validate, value, cursor: showCursor
3650
3652
  };
3651
3653
  const close = () => {
3652
3654
  if (!showCursor) stdout.write(cursorShow);
3653
- if (stdin.isTTY) stdin.setRawMode(false);
3655
+ stdin.setRawMode(false);
3654
3656
  stdin.off("data", keypress);
3655
3657
  stdin.pause();
3656
3658
  };
@@ -3669,6 +3671,7 @@ const prompt = async ({ render, onKeyPress, validate, value, cursor: showCursor
3669
3671
  const defaultActive = (s) => `${colors.blueBold("❯")} ${s}`;
3670
3672
  const defaultInactive = (s) => ` ${s}`;
3671
3673
  const promptSelect = ({ message, options, active = defaultActive, inactive = defaultInactive }) => prompt({
3674
+ message,
3672
3675
  value: 0,
3673
3676
  render(ctx) {
3674
3677
  let text = `${message} ${colors.pale("Use arrows or jk. Press enter to submit.")}\n`;
@@ -3681,6 +3684,7 @@ const promptSelect = ({ message, options, active = defaultActive, inactive = def
3681
3684
  }
3682
3685
  });
3683
3686
  const promptConfirm = ({ message }) => prompt({
3687
+ message,
3684
3688
  value: true,
3685
3689
  render(ctx) {
3686
3690
  return `${colors.bright(message)}\n${ctx.submitted ? `> ${ctx.value ? colors.greenBold("Yes") : colors.yellowBold("No")}` : colors.pale(`> (Y/n)`)}\n`;
@@ -3697,6 +3701,7 @@ const promptText = ({ message, default: def = "", password, min }) => {
3697
3701
  let x = 0;
3698
3702
  const renderValue = (ctx) => password ? "*".repeat(ctx.value.length) : ctx.value;
3699
3703
  return prompt({
3704
+ message,
3700
3705
  value: def,
3701
3706
  cursor: true,
3702
3707
  validate: (ctx) => !min || ctx.value.length >= min,