rake-db 2.3.16 → 2.3.18

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.
@@ -0,0 +1,22 @@
1
+
2
+ > rake-db@2.3.17 test /home/romeo/dev/my/orchid-orm/packages/rake-db
3
+ > jest "--coverage" "--coverageReporters" "json-summary"
4
+
5
+ PASS src/commands/generate.test.ts
6
+ PASS src/commands/migrateOrRollback.test.ts
7
+ PASS src/commands/createOrDrop.test.ts
8
+ PASS src/migration/createTable.test.ts
9
+ PASS src/migration/changeTable.test.ts
10
+ PASS src/common.test.ts
11
+ PASS src/migration/migration.test.ts
12
+ PASS src/rakeDb.test.ts
13
+ PASS src/pull/astToMigration.test.ts
14
+ PASS src/pull/pull.test.ts
15
+ PASS src/pull/dbStructure.test.ts
16
+ PASS src/pull/structureToAst.test.ts
17
+
18
+ Test Suites: 12 passed, 12 total
19
+ Tests: 182 passed, 182 total
20
+ Snapshots: 0 total
21
+ Time: 8.267 s, estimated 10 s
22
+ Ran all test suites.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # rake-db
2
2
 
3
+ ## 2.3.18
4
+
5
+ ### Patch Changes
6
+
7
+ - Relative path in rakeDb config
8
+
9
+ ## 2.3.17
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+ - pqb@0.9.12
15
+
3
16
  ## 2.3.16
4
17
 
5
18
  ### Patch Changes
@@ -1,8 +1,8 @@
1
1
  import { config } from 'dotenv';
2
2
  import path from 'path';
3
- import { rakeDb } from './src/rakeDb';
3
+ import { rakeDb } from '../src/rakeDb';
4
4
  import { AdapterOptions } from 'pqb';
5
- import { appCodeUpdater } from '../orm/src';
5
+ import { appCodeUpdater } from '../../orm/src';
6
6
 
7
7
  config({ path: path.resolve('.env.local') });
8
8
  config();
@@ -24,10 +24,10 @@ if (databaseURLTest) {
24
24
  rakeDb(options, {
25
25
  migrationsPath: 'migrations',
26
26
  appCodeUpdater: appCodeUpdater({
27
- tablePath: (tableName) => `app/tables/${tableName}.ts`,
28
- baseTablePath: 'app/lib/baseTable.ts',
27
+ tablePath: (tableName) => `tables/${tableName}.ts`,
28
+ baseTablePath: 'lib/baseTable.ts',
29
29
  baseTableName: 'BaseTable',
30
- mainFilePath: 'app/db.ts',
30
+ mainFilePath: 'db.ts',
31
31
  }),
32
32
  useCodeUpdater: false,
33
33
  });
@@ -1,4 +1,4 @@
1
- import { change } from '../src';
1
+ import { change } from '../../src';
2
2
 
3
3
  change(async (db) => {
4
4
  await db.createTable('user', (t) => ({
@@ -1,4 +1,4 @@
1
- import { change } from '../src';
1
+ import { change } from '../../src';
2
2
 
3
3
  change(async (db) => {
4
4
  await db.createTable('profile', (t) => ({
@@ -1,4 +1,4 @@
1
- import { change } from '../src';
1
+ import { change } from '../../src';
2
2
 
3
3
  change(async (db) => {
4
4
  await db.createTable('chat', (t) => ({
@@ -1,4 +1,4 @@
1
- import { change } from '../src';
1
+ import { change } from '../../src';
2
2
 
3
3
  change(async (db) => {
4
4
  await db.createTable('chatUser', (t) => ({
@@ -1,4 +1,4 @@
1
- import { change } from '../src';
1
+ import { change } from '../../src';
2
2
 
3
3
  change(async (db) => {
4
4
  await db.createTable('message', (t) => ({
@@ -1,4 +1,4 @@
1
- import { change } from '../src';
1
+ import { change } from '../../src';
2
2
 
3
3
  change(async (db) => {
4
4
  await db.createSchema('geo');
@@ -1,4 +1,4 @@
1
- import { change } from '../src';
1
+ import { change } from '../../src';
2
2
 
3
3
  change(async (db) => {
4
4
  await db.createTable('geo.country', (t) => ({
@@ -1,4 +1,4 @@
1
- import { change } from '../src';
1
+ import { change } from '../../src';
2
2
 
3
3
  change(async (db) => {
4
4
  await db.createTable('geo.city', (t) => ({
@@ -1,4 +1,4 @@
1
- import { change } from '../src';
1
+ import { change } from '../../src';
2
2
 
3
3
  change(async (db) => {
4
4
  await db.createTable('uniqueTable', (t) => ({
package/dist/index.d.ts CHANGED
@@ -495,10 +495,11 @@ declare namespace RakeDbAst {
495
495
 
496
496
  declare type Db = DbResult<DefaultColumnTypes>;
497
497
  declare type RakeDbConfig = {
498
+ basePath: string;
498
499
  migrationsPath: string;
499
500
  migrationsTable: string;
500
501
  commands: Record<string, (options: AdapterOptions[], config: RakeDbConfig, args: string[]) => Promise<void>>;
501
- requireTs(path: string): Promise<void>;
502
+ import(path: string): Promise<void>;
502
503
  noPrimaryKey?: NoPrimaryKeyOption;
503
504
  appCodeUpdater?: AppCodeUpdater;
504
505
  useCodeUpdater?: boolean;
@@ -510,6 +511,7 @@ declare type RakeDbConfig = {
510
511
  declare type AppCodeUpdater = (params: {
511
512
  ast: RakeDbAst;
512
513
  options: AdapterOptions;
514
+ basePath: string;
513
515
  cache: object;
514
516
  }) => Promise<void>;
515
517
 
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ var pqb = require('pqb');
6
6
  var Enquirer = require('enquirer');
7
7
  var path = require('path');
8
8
  var promises = require('fs/promises');
9
+ var url = require('url');
9
10
 
10
11
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
12
 
@@ -50,16 +51,45 @@ var __spreadValues$6 = (a, b) => {
50
51
  };
51
52
  var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
52
53
  const migrationConfigDefaults = {
53
- migrationsPath: path__default["default"].resolve("src", "db", "migrations"),
54
+ migrationsPath: path__default["default"].join("src", "db", "migrations"),
54
55
  migrationsTable: "schemaMigrations",
55
56
  commands: {},
56
- requireTs: (path2) => (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(path2),
57
+ import: (path2) => (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(path2),
57
58
  log: true,
58
59
  logger: console,
59
60
  useCodeUpdater: true
60
61
  };
61
- const getMigrationConfigWithDefaults = (config) => {
62
- return __spreadValues$6(__spreadValues$6({}, migrationConfigDefaults), config);
62
+ const processRakeDbConfig = (config) => {
63
+ var _a;
64
+ const result = __spreadValues$6(__spreadValues$6({}, migrationConfigDefaults), config);
65
+ if (!result.basePath) {
66
+ let stack;
67
+ Error.prepareStackTrace = (_, s) => stack = s;
68
+ new Error().stack;
69
+ if (stack) {
70
+ const thisFile = (_a = stack[0]) == null ? void 0 : _a.getFileName();
71
+ for (const item of stack) {
72
+ const file = item.getFileName();
73
+ if (!file || file === thisFile || /\bnode_modules\b/.test(file)) {
74
+ continue;
75
+ }
76
+ result.basePath = path__default["default"].dirname(file);
77
+ break;
78
+ }
79
+ }
80
+ if (!result.basePath) {
81
+ throw new Error(
82
+ "Failed to determine path to db script. Please set basePath option of rakeDb"
83
+ );
84
+ }
85
+ }
86
+ if (!path__default["default"].isAbsolute(result.migrationsPath)) {
87
+ result.migrationsPath = path__default["default"].resolve(
88
+ result.basePath,
89
+ result.migrationsPath
90
+ );
91
+ }
92
+ return result;
63
93
  };
64
94
  const getDatabaseAndUserFromOptions = (options) => {
65
95
  if (options.databaseURL) {
@@ -166,7 +196,7 @@ const getMigrationFiles = async (config, up) => {
166
196
  const { migrationsPath } = config;
167
197
  let files;
168
198
  try {
169
- files = await promises.readdir(path__default["default"].resolve(migrationsPath));
199
+ files = await promises.readdir(migrationsPath);
170
200
  } catch (_) {
171
201
  return [];
172
202
  }
@@ -1118,6 +1148,7 @@ const runCodeUpdater = (migration, ast) => {
1118
1148
  return (_b = (_a = migration.options).appCodeUpdater) == null ? void 0 : _b.call(_a, {
1119
1149
  ast,
1120
1150
  options: migration.adapterOptions,
1151
+ basePath: migration.options.basePath,
1121
1152
  cache: migration.appCodeUpdaterCache
1122
1153
  });
1123
1154
  };
@@ -1210,7 +1241,7 @@ const processMigration = async (db, up, file, config, options, appCodeUpdaterCac
1210
1241
  if (callback) {
1211
1242
  change(callback);
1212
1243
  } else {
1213
- await config.requireTs(file.path);
1244
+ await config.import(url.pathToFileURL(file.path).toString());
1214
1245
  changeCache[file.path] = getCurrentChangeCallback();
1215
1246
  }
1216
1247
  await getCurrentPromise();
@@ -1335,7 +1366,7 @@ const resetDb = async (arg, config) => {
1335
1366
  };
1336
1367
 
1337
1368
  const writeMigrationFile = async (config, name, content) => {
1338
- await promises.mkdir(path__default["default"].resolve(config.migrationsPath), { recursive: true });
1369
+ await promises.mkdir(config.migrationsPath, { recursive: true });
1339
1370
  const filePath = path__default["default"].resolve(
1340
1371
  config.migrationsPath,
1341
1372
  `${makeFileTimeStamp()}_${name}.ts`
@@ -2047,7 +2078,7 @@ const pullDbStructure = async (options, config) => {
2047
2078
 
2048
2079
  const rakeDb = async (options, partialConfig = {}, args = process.argv.slice(2)) => {
2049
2080
  var _a;
2050
- const config = getMigrationConfigWithDefaults(partialConfig);
2081
+ const config = processRakeDbConfig(partialConfig);
2051
2082
  const command = (_a = args[0]) == null ? void 0 : _a.split(":")[0];
2052
2083
  if (command === "create") {
2053
2084
  await createDb(options, config);