rake-db 2.4.41 → 2.4.43

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ColumnsShape, Db as Db$1, ColumnType, EnumColumn, ColumnTypes, Adapter, DbResult, DefaultColumnTypes, TransactionAdapter, QueryLogObject, IndexColumnOptions, IndexOptions, ForeignKeyOptions, TextColumn, NoPrimaryKeyOption, TableData, SingleColumnIndexOptions, AdapterOptions, QueryLogOptions } from 'pqb';
2
2
  import { EmptyObject, RawExpression, ColumnTypesBase, raw, MaybeArray } from 'orchid-core';
3
3
 
4
- declare type CreateTableResult<Table extends string, Shape extends ColumnsShape> = {
4
+ type CreateTableResult<Table extends string, Shape extends ColumnsShape> = {
5
5
  table: Db$1<Table, Shape>;
6
6
  };
7
7
 
@@ -12,12 +12,12 @@ declare function add(this: ColumnTypesBase, emptyObject: EmptyObject): EmptyObje
12
12
  declare function add(this: ColumnTypesBase, items: Record<string, ColumnType>, options?: {
13
13
  dropMode?: DropMode;
14
14
  }): Record<string, RakeDbAst.ChangeTableItem.Column>;
15
- declare type Change = RakeDbAst.ChangeTableItem.Change & ChangeOptions;
16
- declare type ChangeOptions = {
15
+ type Change = RakeDbAst.ChangeTableItem.Change & ChangeOptions;
16
+ type ChangeOptions = {
17
17
  usingUp?: RawExpression;
18
18
  usingDown?: RawExpression;
19
19
  };
20
- declare type TableChangeMethods = typeof tableChangeMethods;
20
+ type TableChangeMethods = typeof tableChangeMethods;
21
21
  declare const tableChangeMethods: {
22
22
  add: typeof add;
23
23
  drop: typeof add;
@@ -29,43 +29,43 @@ declare const tableChangeMethods: {
29
29
  rename(name: string): RakeDbAst.ChangeTableItem.Rename;
30
30
  enum(this: ColumnTypesBase, name: string): EnumColumn<string, [string, ...string[]]>;
31
31
  };
32
- declare type TableChanger = MigrationColumnTypes & TableChangeMethods;
33
- declare type TableChangeData = Record<string, RakeDbAst.ChangeTableItem.Column | RakeDbAst.ChangeTableItem.Rename | Change | EmptyObject>;
32
+ type TableChanger = MigrationColumnTypes & TableChangeMethods;
33
+ type TableChangeData = Record<string, RakeDbAst.ChangeTableItem.Column | RakeDbAst.ChangeTableItem.Rename | Change | EmptyObject>;
34
34
 
35
- declare type DropMode = 'CASCADE' | 'RESTRICT';
36
- declare type TableOptions = {
35
+ type DropMode = 'CASCADE' | 'RESTRICT';
36
+ type TableOptions = {
37
37
  dropMode?: DropMode;
38
38
  comment?: string;
39
39
  noPrimaryKey?: boolean;
40
40
  snakeCase?: boolean;
41
41
  };
42
- declare type TextColumnCreator = () => TextColumn;
43
- declare type MigrationColumnTypes = Omit<ColumnTypes, 'text' | 'string' | 'enum'> & {
42
+ type TextColumnCreator = () => TextColumn;
43
+ type MigrationColumnTypes = Omit<ColumnTypes, 'text' | 'string' | 'enum'> & {
44
44
  text: TextColumnCreator;
45
45
  string: TextColumnCreator;
46
46
  citext: TextColumnCreator;
47
47
  enum: (name: string) => EnumColumn;
48
48
  };
49
- declare type ColumnsShapeCallback<Shape extends ColumnsShape = ColumnsShape> = (t: MigrationColumnTypes & {
49
+ type ColumnsShapeCallback<Shape extends ColumnsShape = ColumnsShape> = (t: MigrationColumnTypes & {
50
50
  raw: typeof raw;
51
51
  }) => Shape;
52
- declare type ChangeTableOptions = {
52
+ type ChangeTableOptions = {
53
53
  snakeCase?: boolean;
54
54
  comment?: string | [string, string] | null;
55
55
  };
56
- declare type ChangeTableCallback = (t: TableChanger) => TableChangeData;
57
- declare type ColumnComment = {
56
+ type ChangeTableCallback = (t: TableChanger) => TableChangeData;
57
+ type ColumnComment = {
58
58
  column: string;
59
59
  comment: string | null;
60
60
  };
61
- declare type SilentQueries = {
61
+ type SilentQueries = {
62
62
  silentQuery: Adapter['query'];
63
63
  silentArrays: Adapter['arrays'];
64
64
  };
65
- declare type Migration = DbResult<DefaultColumnTypes> & MigrationBase & {
65
+ type Migration = DbResult<DefaultColumnTypes> & MigrationBase & {
66
66
  adapter: SilentQueries;
67
67
  };
68
- declare type ConstraintArg = {
68
+ type ConstraintArg = {
69
69
  name?: string;
70
70
  references?: [
71
71
  columns: [string, ...string[]],
@@ -124,7 +124,7 @@ declare class MigrationBase {
124
124
  constraintExists(constraintName: string): Promise<boolean>;
125
125
  }
126
126
 
127
- declare type RakeDbAst = RakeDbAst.Table | RakeDbAst.ChangeTable | RakeDbAst.RenameTable | RakeDbAst.Schema | RakeDbAst.Extension | RakeDbAst.Enum | RakeDbAst.Domain | RakeDbAst.Constraint | RakeDbAst.View;
127
+ type RakeDbAst = RakeDbAst.Table | RakeDbAst.ChangeTable | RakeDbAst.RenameTable | RakeDbAst.Schema | RakeDbAst.Extension | RakeDbAst.Enum | RakeDbAst.Domain | RakeDbAst.Constraint | RakeDbAst.View;
128
128
  declare namespace RakeDbAst {
129
129
  type Table = {
130
130
  type: 'table';
@@ -258,8 +258,8 @@ declare namespace RakeDbAst {
258
258
  };
259
259
  }
260
260
 
261
- declare type Db = DbResult<DefaultColumnTypes>;
262
- declare type RakeDbConfig = {
261
+ type Db = DbResult<DefaultColumnTypes>;
262
+ type RakeDbConfig = {
263
263
  basePath: string;
264
264
  migrationsPath: string;
265
265
  migrationsTable: string;
@@ -274,7 +274,7 @@ declare type RakeDbConfig = {
274
274
  beforeRollback?(db: Db): Promise<void>;
275
275
  afterRollback?(db: Db): Promise<void>;
276
276
  } & QueryLogOptions;
277
- declare type AppCodeUpdater = (params: {
277
+ type AppCodeUpdater = (params: {
278
278
  ast: RakeDbAst;
279
279
  options: AdapterOptions;
280
280
  basePath: string;
@@ -290,7 +290,7 @@ declare const writeMigrationFile: (config: RakeDbConfig, version: string, name:
290
290
  declare const generate: (config: RakeDbConfig, args: string[]) => Promise<void>;
291
291
  declare const makeFileTimeStamp: () => string;
292
292
 
293
- declare type ChangeCallback = (db: Migration, up: boolean) => Promise<void>;
293
+ type ChangeCallback = (db: Migration, up: boolean) => Promise<void>;
294
294
  declare const change: (fn: ChangeCallback) => void;
295
295
 
296
296
  declare const migrateOrRollback: (options: MaybeArray<AdapterOptions>, config: RakeDbConfig, args: string[], up: boolean) => Promise<void>;
package/dist/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var pqb = require('pqb');
6
4
  var orchidCore = require('orchid-core');
7
5
  var path = require('path');
@@ -9,10 +7,7 @@ var promises = require('fs/promises');
9
7
  var prompts = require('prompts');
10
8
  var url = require('url');
11
9
 
12
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
-
14
- function _interopNamespace(e) {
15
- if (e && e.__esModule) return e;
10
+ function _interopNamespaceDefault(e) {
16
11
  var n = Object.create(null);
17
12
  if (e) {
18
13
  Object.keys(e).forEach(function (k) {
@@ -25,13 +20,11 @@ function _interopNamespace(e) {
25
20
  }
26
21
  });
27
22
  }
28
- n["default"] = e;
23
+ n.default = e;
29
24
  return Object.freeze(n);
30
25
  }
31
26
 
32
- var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
33
- var prompts__default = /*#__PURE__*/_interopDefaultLegacy(prompts);
34
- var url__namespace = /*#__PURE__*/_interopNamespace(url);
27
+ var url__namespace = /*#__PURE__*/_interopNamespaceDefault(url);
35
28
 
36
29
  var __defProp$6 = Object.defineProperty;
37
30
  var __defProps$5 = Object.defineProperties;
@@ -53,11 +46,11 @@ var __spreadValues$6 = (a, b) => {
53
46
  };
54
47
  var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
55
48
  const migrationConfigDefaults = {
56
- migrationsPath: path__default["default"].join("src", "db", "migrations"),
49
+ migrationsPath: path.join("src", "db", "migrations"),
57
50
  migrationsTable: "schemaMigrations",
58
51
  snakeCase: false,
59
52
  commands: {},
60
- import: (path2) => (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(path2),
53
+ import: (path2) => import(path2),
61
54
  log: true,
62
55
  logger: console,
63
56
  useCodeUpdater: true
@@ -76,10 +69,10 @@ const processRakeDbConfig = (config) => {
76
69
  Error.prepareStackTrace = original;
77
70
  if (stack) {
78
71
  const thisFile = (_a = stack[0]) == null ? void 0 : _a.getFileName();
79
- const thisDir = thisFile && path__default["default"].dirname(thisFile);
72
+ const thisDir = thisFile && path.dirname(thisFile);
80
73
  for (const item of stack) {
81
74
  let file = item.getFileName();
82
- if (!file || path__default["default"].dirname(file) === thisDir || /\bnode_modules\b/.test(file)) {
75
+ if (!file || path.dirname(file) === thisDir || /\bnode_modules\b/.test(file)) {
83
76
  continue;
84
77
  }
85
78
  if (/file:\/\/\/\w+:\//.test(file)) {
@@ -90,7 +83,7 @@ const processRakeDbConfig = (config) => {
90
83
  } catch (_) {
91
84
  }
92
85
  }
93
- result.basePath = path__default["default"].dirname(file);
86
+ result.basePath = path.dirname(file);
94
87
  break;
95
88
  }
96
89
  }
@@ -100,8 +93,8 @@ const processRakeDbConfig = (config) => {
100
93
  );
101
94
  }
102
95
  }
103
- if (!path__default["default"].isAbsolute(result.migrationsPath)) {
104
- result.migrationsPath = path__default["default"].resolve(
96
+ if (!path.isAbsolute(result.migrationsPath)) {
97
+ result.migrationsPath = path.resolve(
105
98
  result.basePath,
106
99
  result.migrationsPath
107
100
  );
@@ -140,7 +133,7 @@ const setAdapterOptions = (options, set) => {
140
133
  }
141
134
  };
142
135
  const setAdminCredentialsToOptions = async (options, create) => {
143
- const confirm = await prompts__default["default"]([
136
+ const confirm = await prompts([
144
137
  {
145
138
  message: `Would you like to share admin credentials to ${create ? "create" : "drop"} a database`,
146
139
  type: "confirm",
@@ -151,7 +144,7 @@ const setAdminCredentialsToOptions = async (options, create) => {
151
144
  if (!confirm.confirm) {
152
145
  return;
153
146
  }
154
- const values = await prompts__default["default"]([
147
+ const values = await prompts([
155
148
  {
156
149
  message: "Enter admin user:",
157
150
  type: "text",
@@ -235,7 +228,7 @@ const getMigrationFiles = async (config, up) => {
235
228
  );
236
229
  }
237
230
  return {
238
- path: path__default["default"].resolve(migrationsPath, file),
231
+ path: path.resolve(migrationsPath, file),
239
232
  version: timestampMatch[1]
240
233
  };
241
234
  });
@@ -1837,7 +1830,7 @@ const resetDb = async (arg, config) => {
1837
1830
  const writeMigrationFile = async (config, version, name, content) => {
1838
1831
  var _a;
1839
1832
  await promises.mkdir(config.migrationsPath, { recursive: true });
1840
- const filePath = path__default["default"].resolve(config.migrationsPath, `${version}_${name}.ts`);
1833
+ const filePath = path.resolve(config.migrationsPath, `${version}_${name}.ts`);
1841
1834
  await promises.writeFile(filePath, content);
1842
1835
  (_a = config.logger) == null ? void 0 : _a.log(`Created ${orchidCore.pathToLog(filePath)}`);
1843
1836
  };
@@ -1854,7 +1847,7 @@ const generate = async (config, args) => {
1854
1847
  );
1855
1848
  };
1856
1849
  const makeFileTimeStamp = () => {
1857
- const now = new Date();
1850
+ const now = /* @__PURE__ */ new Date();
1858
1851
  return [
1859
1852
  now.getUTCFullYear(),
1860
1853
  now.getUTCMonth() + 1,
@@ -2368,6 +2361,7 @@ const matchMap = {
2368
2361
  };
2369
2362
  const fkeyActionMap = {
2370
2363
  a: void 0,
2364
+ // default
2371
2365
  r: "RESTRICT",
2372
2366
  c: "CASCADE",
2373
2367
  n: "SET NULL",