rake-db 2.3.23 → 2.3.25
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/.env.local +1 -1
- package/.turbo/turbo-test:ci.log +7 -7
- package/CHANGELOG.md +13 -0
- package/dist/index.d.ts +58 -58
- package/dist/index.js +52 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -4
- package/src/commands/createOrDrop.test.ts +50 -5
- package/src/commands/createOrDrop.ts +43 -9
- package/src/commands/generate.test.ts +8 -5
- package/src/common.test.ts +10 -17
- package/src/common.ts +35 -31
- package/tsconfig.json +1 -1
- package/coverage/coverage-summary.json +0 -17
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { singleQuote, quote, isRaw, getRaw, toArray, columnTypes, raw, getColumnTypes, getTableData, resetTableData, ColumnType, emptyObject, TransactionAdapter, logParamToLogObject, createDb as createDb$1, Adapter, columnsByType, instantiateColumn, codeToString, addCode, quoteObjectKey, primaryKeyToCode, indexToCode, foreignKeyToCode, TimestampColumn, foreignKeyArgsToCode } from 'pqb';
|
|
2
|
-
import Enquirer from 'enquirer';
|
|
3
2
|
import path from 'path';
|
|
4
3
|
import { readdir, mkdir, writeFile } from 'fs/promises';
|
|
4
|
+
import prompts from 'prompts';
|
|
5
5
|
import { pathToFileURL } from 'url';
|
|
6
6
|
|
|
7
7
|
var __defProp$6 = Object.defineProperty;
|
|
@@ -104,32 +104,35 @@ const setAdapterOptions = (options, set) => {
|
|
|
104
104
|
return __spreadValues$6(__spreadValues$6({}, options), set);
|
|
105
105
|
}
|
|
106
106
|
};
|
|
107
|
-
const
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
107
|
+
const setAdminCredentialsToOptions = async (options, create) => {
|
|
108
|
+
const confirm = await prompts([
|
|
109
|
+
{
|
|
110
|
+
message: `Would you like to share admin credentials to ${create ? "create" : "drop"} a database`,
|
|
111
|
+
type: "confirm",
|
|
112
|
+
name: "confirm",
|
|
113
|
+
initial: true
|
|
114
|
+
}
|
|
115
|
+
]);
|
|
116
|
+
if (!confirm.confirm) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const values = await prompts([
|
|
120
|
+
{
|
|
121
|
+
message: "Enter admin user:",
|
|
122
|
+
type: "text",
|
|
123
|
+
name: "user",
|
|
124
|
+
initial: "postgres",
|
|
125
|
+
min: 1
|
|
122
126
|
},
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return setAdapterOptions(options, values);
|
|
127
|
+
{
|
|
128
|
+
message: "Enter admin password:",
|
|
129
|
+
type: "password",
|
|
130
|
+
name: "password"
|
|
131
|
+
}
|
|
132
|
+
]);
|
|
133
|
+
return setAdapterOptions(options, __spreadProps$5(__spreadValues$6({}, values), {
|
|
134
|
+
password: values.password || void 0
|
|
135
|
+
}));
|
|
133
136
|
};
|
|
134
137
|
const createSchemaMigrations = async (db, config) => {
|
|
135
138
|
try {
|
|
@@ -1272,9 +1275,12 @@ const execute = async (options, sql) => {
|
|
|
1272
1275
|
return "ok";
|
|
1273
1276
|
} catch (error) {
|
|
1274
1277
|
const err = error;
|
|
1278
|
+
if (typeof err.message === "string" && err.message.includes("sslmode=require")) {
|
|
1279
|
+
return "ssl required";
|
|
1280
|
+
}
|
|
1275
1281
|
if (err.code === "42P04" || err.code === "3D000") {
|
|
1276
1282
|
return "already";
|
|
1277
|
-
} else if (err.code === "42501") {
|
|
1283
|
+
} else if (err.code === "42501" || typeof err.message === "string" && err.message.includes("password authentication failed")) {
|
|
1278
1284
|
return "forbidden";
|
|
1279
1285
|
} else {
|
|
1280
1286
|
return { error };
|
|
@@ -1293,18 +1299,30 @@ const createOrDrop = async (options, adminOptions, config, args) => {
|
|
|
1293
1299
|
console.log(args.successMessage(params));
|
|
1294
1300
|
} else if (result === "already") {
|
|
1295
1301
|
console.log(args.alreadyMessage(params));
|
|
1302
|
+
} else if (result === "ssl required") {
|
|
1303
|
+
console.log("SSL is required: append ?ssl=true to the database url string");
|
|
1304
|
+
return;
|
|
1296
1305
|
} else if (result === "forbidden") {
|
|
1297
|
-
|
|
1306
|
+
let message = `Permission denied to ${args.create ? "create" : "drop"} database.`;
|
|
1307
|
+
const host = adminOptions.databaseURL ? new URL(adminOptions.databaseURL).hostname : adminOptions.host;
|
|
1308
|
+
const isLocal = host === "localhost";
|
|
1309
|
+
if (!isLocal) {
|
|
1310
|
+
message += `
|
|
1311
|
+
Don't use this command for database service providers, only for a local db.`;
|
|
1312
|
+
}
|
|
1313
|
+
console.log(message);
|
|
1314
|
+
const updatedOptions = await setAdminCredentialsToOptions(
|
|
1298
1315
|
options,
|
|
1299
|
-
|
|
1300
|
-
config,
|
|
1301
|
-
args
|
|
1316
|
+
args.create
|
|
1302
1317
|
);
|
|
1318
|
+
if (!updatedOptions)
|
|
1319
|
+
return;
|
|
1320
|
+
await createOrDrop(options, updatedOptions, config, args);
|
|
1303
1321
|
return;
|
|
1304
1322
|
} else {
|
|
1305
1323
|
throw result.error;
|
|
1306
1324
|
}
|
|
1307
|
-
if (!args.
|
|
1325
|
+
if (!args.create)
|
|
1308
1326
|
return;
|
|
1309
1327
|
const db = new Adapter(options);
|
|
1310
1328
|
await createSchemaMigrations(db, config);
|
|
@@ -1322,7 +1340,7 @@ const createDb = async (arg, config) => {
|
|
|
1322
1340
|
alreadyMessage({ database }) {
|
|
1323
1341
|
return `Database ${database} already exists`;
|
|
1324
1342
|
},
|
|
1325
|
-
|
|
1343
|
+
create: true
|
|
1326
1344
|
});
|
|
1327
1345
|
}
|
|
1328
1346
|
};
|