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.d.ts +11 -0
- package/dist/index.js +12 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1777,6 +1777,11 @@ interface MigrateConfigBase extends QueryLogOptions {
|
|
|
1777
1777
|
migrationsTable?: string;
|
|
1778
1778
|
transaction?: 'single' | 'per-migration';
|
|
1779
1779
|
transactionSearchPath?: SearchPath;
|
|
1780
|
+
/**
|
|
1781
|
+
* Advisory lock key used while migrating or rolling back.
|
|
1782
|
+
* Defaults to rake-db's fixed lock key.
|
|
1783
|
+
*/
|
|
1784
|
+
migrationLockKey?: bigint;
|
|
1780
1785
|
forceDefaultExports?: boolean;
|
|
1781
1786
|
beforeChange?: ChangeCallback$1;
|
|
1782
1787
|
afterChange?: ChangeCallback$1;
|
|
@@ -1899,6 +1904,11 @@ interface RakeDbCliConfigInputBase<SchemaConfig extends ColumnSchemaConfig, CT =
|
|
|
1899
1904
|
};
|
|
1900
1905
|
noPrimaryKey?: NoPrimaryKeyOption;
|
|
1901
1906
|
transactionSearchPath?: SearchPath;
|
|
1907
|
+
/**
|
|
1908
|
+
* Advisory lock key used while migrating or rolling back.
|
|
1909
|
+
* Defaults to rake-db's fixed lock key.
|
|
1910
|
+
*/
|
|
1911
|
+
migrationLockKey?: bigint;
|
|
1902
1912
|
/**
|
|
1903
1913
|
* Throw if a migration doesn't have a default export.
|
|
1904
1914
|
* This is needed when in your setup you're importing migration files first and execute them later,
|
|
@@ -1998,6 +2008,7 @@ interface RakeDbConfig<ColumnTypes = unknown> extends QueryLogOptions {
|
|
|
1998
2008
|
afterRollback?: MigrationCallback;
|
|
1999
2009
|
migrationId: RakeDbMigrationId;
|
|
2000
2010
|
transactionSearchPath?: SearchPath;
|
|
2011
|
+
migrationLockKey?: bigint;
|
|
2001
2012
|
forceDefaultExports?: boolean;
|
|
2002
2013
|
afterChangeCommit?: ChangeCommitCallback;
|
|
2003
2014
|
basePath: string;
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ let node_url = require("node:url");
|
|
|
26
26
|
let pqb = require("pqb");
|
|
27
27
|
let node_fs_promises = require("node:fs/promises");
|
|
28
28
|
node_fs_promises = __toESM(node_fs_promises);
|
|
29
|
-
const RAKE_DB_LOCK_KEY =
|
|
29
|
+
const RAKE_DB_LOCK_KEY = 8582141715823621641n;
|
|
30
30
|
const getFirstWordAndRest = (input) => {
|
|
31
31
|
const i = input.search(/(?=[A-Z])|[-_ ]/);
|
|
32
32
|
if (i !== -1) {
|
|
@@ -88,7 +88,7 @@ const transaction = (adapter, config, fn) => {
|
|
|
88
88
|
const searchPath = config.transactionSearchPath;
|
|
89
89
|
return adapter.transaction(void 0, searchPath ? { setConfig: { search_path: typeof searchPath === "function" ? searchPath() : searchPath } } : void 0, fn);
|
|
90
90
|
};
|
|
91
|
-
const queryLock = (trx) => trx.query(`SELECT pg_advisory_xact_lock('${
|
|
91
|
+
const queryLock = (trx, key = RAKE_DB_LOCK_KEY) => trx.query(`SELECT pg_advisory_xact_lock('${key}')`);
|
|
92
92
|
const getCliParam = (args, name) => {
|
|
93
93
|
if (args) {
|
|
94
94
|
const key = "--" + name;
|
|
@@ -3482,7 +3482,7 @@ const migrateOrRollback = async (trx, config, set, versions, count, up, redo, fo
|
|
|
3482
3482
|
set.migrations.reverse();
|
|
3483
3483
|
}
|
|
3484
3484
|
}
|
|
3485
|
-
if (!skipLock) await queryLock(trx);
|
|
3485
|
+
if (!skipLock) await queryLock(trx, config.migrationLockKey);
|
|
3486
3486
|
let db;
|
|
3487
3487
|
const beforeMigrate = config[up ? "beforeMigrate" : "beforeRollback"];
|
|
3488
3488
|
if (beforeMigrate || config.beforeChange) {
|
|
@@ -3636,7 +3636,8 @@ const CSI = `[`;
|
|
|
3636
3636
|
const cursorShow = `${CSI}?25h`;
|
|
3637
3637
|
const cursorHide = `${CSI}?25l`;
|
|
3638
3638
|
const { stdin, stdout } = process;
|
|
3639
|
-
const
|
|
3639
|
+
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, "");
|
|
3640
|
+
const visibleChars = (s) => stripAnsi(s).length;
|
|
3640
3641
|
const clear = (text) => {
|
|
3641
3642
|
const rows = text.split(/\r?\n/).reduce((rows, line) => rows + 1 + Math.floor(Math.max(visibleChars(line) - 1, 0) / stdout.columns), 0);
|
|
3642
3643
|
let clear = "";
|
|
@@ -3646,9 +3647,10 @@ const clear = (text) => {
|
|
|
3646
3647
|
}
|
|
3647
3648
|
return clear;
|
|
3648
3649
|
};
|
|
3649
|
-
const prompt = async ({ render, onKeyPress, validate, value, cursor: showCursor }) => {
|
|
3650
|
+
const prompt = async ({ message, render, onKeyPress, validate, value, cursor: showCursor }) => {
|
|
3651
|
+
if (!stdin.isTTY) throw new RakeDbError(`Cannot prompt "${stripAnsi(message)}": stdin is not a TTY, run the command in an interactive terminal`);
|
|
3650
3652
|
stdin.resume();
|
|
3651
|
-
|
|
3653
|
+
stdin.setRawMode(true);
|
|
3652
3654
|
stdin.setEncoding("utf-8");
|
|
3653
3655
|
if (!showCursor) stdout.write(cursorHide);
|
|
3654
3656
|
return new Promise((res) => {
|
|
@@ -3673,7 +3675,7 @@ const prompt = async ({ render, onKeyPress, validate, value, cursor: showCursor
|
|
|
3673
3675
|
};
|
|
3674
3676
|
const close = () => {
|
|
3675
3677
|
if (!showCursor) stdout.write(cursorShow);
|
|
3676
|
-
|
|
3678
|
+
stdin.setRawMode(false);
|
|
3677
3679
|
stdin.off("data", keypress);
|
|
3678
3680
|
stdin.pause();
|
|
3679
3681
|
};
|
|
@@ -3692,6 +3694,7 @@ const prompt = async ({ render, onKeyPress, validate, value, cursor: showCursor
|
|
|
3692
3694
|
const defaultActive = (s) => `${pqb_internal.colors.blueBold("❯")} ${s}`;
|
|
3693
3695
|
const defaultInactive = (s) => ` ${s}`;
|
|
3694
3696
|
const promptSelect = ({ message, options, active = defaultActive, inactive = defaultInactive }) => prompt({
|
|
3697
|
+
message,
|
|
3695
3698
|
value: 0,
|
|
3696
3699
|
render(ctx) {
|
|
3697
3700
|
let text = `${message} ${pqb_internal.colors.pale("Use arrows or jk. Press enter to submit.")}\n`;
|
|
@@ -3704,6 +3707,7 @@ const promptSelect = ({ message, options, active = defaultActive, inactive = def
|
|
|
3704
3707
|
}
|
|
3705
3708
|
});
|
|
3706
3709
|
const promptConfirm = ({ message }) => prompt({
|
|
3710
|
+
message,
|
|
3707
3711
|
value: true,
|
|
3708
3712
|
render(ctx) {
|
|
3709
3713
|
return `${pqb_internal.colors.bright(message)}\n${ctx.submitted ? `> ${ctx.value ? pqb_internal.colors.greenBold("Yes") : pqb_internal.colors.yellowBold("No")}` : pqb_internal.colors.pale(`> (Y/n)`)}\n`;
|
|
@@ -3720,6 +3724,7 @@ const promptText = ({ message, default: def = "", password, min }) => {
|
|
|
3720
3724
|
let x = 0;
|
|
3721
3725
|
const renderValue = (ctx) => password ? "*".repeat(ctx.value.length) : ctx.value;
|
|
3722
3726
|
return prompt({
|
|
3727
|
+
message,
|
|
3723
3728
|
value: def,
|
|
3724
3729
|
cursor: true,
|
|
3725
3730
|
validate: (ctx) => !min || ctx.value.length >= min,
|