rake-db 2.3.22 → 2.3.24

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 CHANGED
@@ -1,2 +1,2 @@
1
- DATABASE_URL=postgres://postgres:@localhost:5432/porm
2
- #DATABASE_URL_TEST=postgres://postgres:@localhost:5432/porm_test
1
+ #DATABASE_URL=postgres://postgres:@localhost:5432/porm
2
+ DATABASE_URL=postgres://romeerez:e2Y6ovIJruas@ep-autumn-tooth-279704.eu-central-1.aws.neon.tech/neondb?ssl=true
@@ -1,22 +1,22 @@
1
1
 
2
- > rake-db@2.3.17 test /home/romeo/dev/my/orchid-orm/packages/rake-db
2
+ > rake-db@2.3.22 test /home/romeo/dev/my/orchid-orm/packages/rake-db
3
3
  > jest "--coverage" "--coverageReporters" "json-summary"
4
4
 
5
- PASS src/commands/generate.test.ts
6
- PASS src/commands/migrateOrRollback.test.ts
5
+ PASS src/migration/migration.test.ts
7
6
  PASS src/commands/createOrDrop.test.ts
8
- PASS src/migration/createTable.test.ts
7
+ PASS src/commands/migrateOrRollback.test.ts
9
8
  PASS src/migration/changeTable.test.ts
10
9
  PASS src/common.test.ts
11
- PASS src/migration/migration.test.ts
10
+ PASS src/pull/dbStructure.test.ts
12
11
  PASS src/rakeDb.test.ts
12
+ PASS src/pull/structureToAst.test.ts
13
+ PASS src/commands/generate.test.ts
13
14
  PASS src/pull/astToMigration.test.ts
15
+ PASS src/migration/createTable.test.ts
14
16
  PASS src/pull/pull.test.ts
15
- PASS src/pull/dbStructure.test.ts
16
- PASS src/pull/structureToAst.test.ts
17
17
 
18
18
  Test Suites: 12 passed, 12 total
19
19
  Tests: 182 passed, 182 total
20
20
  Snapshots: 0 total
21
- Time: 8.267 s, estimated 10 s
21
+ Time: 3.951 s
22
22
  Ran all test suites.
@@ -0,0 +1,22 @@
1
+
2
+ > rake-db@2.3.24 test:ci /home/romeo/dev/my/orchid-orm/packages/rake-db
3
+ > jest --coverage --coverageReporters json-summary
4
+
5
+ PASS src/migration/changeTable.test.ts
6
+ PASS src/migration/createTable.test.ts
7
+ PASS src/commands/createOrDrop.test.ts
8
+ PASS src/pull/structureToAst.test.ts
9
+ PASS src/common.test.ts
10
+ PASS src/migration/migration.test.ts
11
+ PASS src/commands/migrateOrRollback.test.ts
12
+ PASS src/commands/generate.test.ts
13
+ PASS src/rakeDb.test.ts
14
+ PASS src/pull/pull.test.ts
15
+ PASS src/pull/dbStructure.test.ts
16
+ PASS src/pull/astToMigration.test.ts
17
+
18
+ Test Suites: 12 passed, 12 total
19
+ Tests: 184 passed, 184 total
20
+ Snapshots: 0 total
21
+ Time: 4.744 s
22
+ Ran all test suites.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # rake-db
2
2
 
3
+ ## 2.3.24
4
+
5
+ ### Patch Changes
6
+
7
+ - Handle ssl required case in db create; Confirm db creation before asking for creds
8
+
9
+ ## 2.3.23
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+ - pqb@0.9.13
15
+
3
16
  ## 2.3.22
4
17
 
5
18
  ### Patch Changes
package/dist/index.js CHANGED
@@ -3,9 +3,9 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var pqb = require('pqb');
6
- var Enquirer = require('enquirer');
7
6
  var path = require('path');
8
7
  var promises = require('fs/promises');
8
+ var prompts = require('prompts');
9
9
  var url = require('url');
10
10
 
11
11
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -28,8 +28,8 @@ function _interopNamespace(e) {
28
28
  return Object.freeze(n);
29
29
  }
30
30
 
31
- var Enquirer__default = /*#__PURE__*/_interopDefaultLegacy(Enquirer);
32
31
  var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
32
+ var prompts__default = /*#__PURE__*/_interopDefaultLegacy(prompts);
33
33
 
34
34
  var __defProp$6 = Object.defineProperty;
35
35
  var __defProps$5 = Object.defineProperties;
@@ -131,32 +131,35 @@ const setAdapterOptions = (options, set) => {
131
131
  return __spreadValues$6(__spreadValues$6({}, options), set);
132
132
  }
133
133
  };
134
- const askAdminCredentials = async () => {
135
- const prompt = new Enquirer__default["default"].Snippet({
136
- message: `What are postgres admin login and password?`,
137
- fields: [
138
- {
139
- name: "user",
140
- required: true
141
- },
142
- {
143
- name: "password"
144
- }
145
- ],
146
- values: {
147
- user: "postgres",
148
- password: ""
134
+ const setAdminCredentialsToOptions = async (options, create) => {
135
+ const confirm = await prompts__default["default"]([
136
+ {
137
+ message: `Would you like to share admin credentials to ${create ? "create" : "drop"} a database`,
138
+ type: "confirm",
139
+ name: "confirm",
140
+ initial: true
141
+ }
142
+ ]);
143
+ if (!confirm.confirm) {
144
+ return;
145
+ }
146
+ const values = await prompts__default["default"]([
147
+ {
148
+ message: "Enter admin user:",
149
+ type: "text",
150
+ name: "user",
151
+ initial: "postgres",
152
+ min: 1
149
153
  },
150
- template: "Admin user: {{user}}\nAdmin password: {{password}}"
151
- });
152
- const { values } = await prompt.run();
153
- if (!values.password)
154
- values.password = "";
155
- return values;
156
- };
157
- const setAdminCredentialsToOptions = async (options) => {
158
- const values = await askAdminCredentials();
159
- return setAdapterOptions(options, values);
154
+ {
155
+ message: "Enter admin password:",
156
+ type: "password",
157
+ name: "password"
158
+ }
159
+ ]);
160
+ return setAdapterOptions(options, __spreadProps$5(__spreadValues$6({}, values), {
161
+ password: values.password || void 0
162
+ }));
160
163
  };
161
164
  const createSchemaMigrations = async (db, config) => {
162
165
  try {
@@ -1299,9 +1302,12 @@ const execute = async (options, sql) => {
1299
1302
  return "ok";
1300
1303
  } catch (error) {
1301
1304
  const err = error;
1305
+ if (typeof err.message === "string" && err.message.includes("sslmode=require")) {
1306
+ return "ssl required";
1307
+ }
1302
1308
  if (err.code === "42P04" || err.code === "3D000") {
1303
1309
  return "already";
1304
- } else if (err.code === "42501") {
1310
+ } else if (err.code === "42501" || typeof err.message === "string" && err.message.includes("password authentication failed")) {
1305
1311
  return "forbidden";
1306
1312
  } else {
1307
1313
  return { error };
@@ -1320,18 +1326,30 @@ const createOrDrop = async (options, adminOptions, config, args) => {
1320
1326
  console.log(args.successMessage(params));
1321
1327
  } else if (result === "already") {
1322
1328
  console.log(args.alreadyMessage(params));
1329
+ } else if (result === "ssl required") {
1330
+ console.log("SSL is required: append ?ssl=true to the database url string");
1331
+ return;
1323
1332
  } else if (result === "forbidden") {
1324
- await createOrDrop(
1333
+ let message = `Permission denied to ${args.create ? "create" : "drop"} database.`;
1334
+ const host = adminOptions.databaseURL ? new URL(adminOptions.databaseURL).hostname : adminOptions.host;
1335
+ const isLocal = host === "localhost";
1336
+ if (!isLocal) {
1337
+ message += `
1338
+ Don't use this command for database service providers, only for a local db.`;
1339
+ }
1340
+ console.log(message);
1341
+ const updatedOptions = await setAdminCredentialsToOptions(
1325
1342
  options,
1326
- await setAdminCredentialsToOptions(options),
1327
- config,
1328
- args
1343
+ args.create
1329
1344
  );
1345
+ if (!updatedOptions)
1346
+ return;
1347
+ await createOrDrop(options, updatedOptions, config, args);
1330
1348
  return;
1331
1349
  } else {
1332
1350
  throw result.error;
1333
1351
  }
1334
- if (!args.createVersionsTable)
1352
+ if (!args.create)
1335
1353
  return;
1336
1354
  const db = new pqb.Adapter(options);
1337
1355
  await createSchemaMigrations(db, config);
@@ -1349,7 +1367,7 @@ const createDb = async (arg, config) => {
1349
1367
  alreadyMessage({ database }) {
1350
1368
  return `Database ${database} already exists`;
1351
1369
  },
1352
- createVersionsTable: true
1370
+ create: true
1353
1371
  });
1354
1372
  }
1355
1373
  };