knex 0.95.13 → 1.0.1

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.
Files changed (78) hide show
  1. package/CHANGELOG.md +74 -3
  2. package/README.md +1 -1
  3. package/UPGRADING.md +7 -0
  4. package/lib/client.js +14 -1
  5. package/lib/constants.js +2 -0
  6. package/lib/dialects/better-sqlite3/index.js +72 -0
  7. package/lib/dialects/cockroachdb/crdb-querycompiler.js +87 -33
  8. package/lib/dialects/cockroachdb/crdb-tablecompiler.js +19 -0
  9. package/lib/dialects/cockroachdb/index.js +13 -0
  10. package/lib/dialects/mssql/index.js +0 -11
  11. package/lib/dialects/mssql/query/mssql-querycompiler.js +122 -64
  12. package/lib/dialects/mssql/schema/mssql-columncompiler.js +41 -6
  13. package/lib/dialects/mssql/schema/mssql-tablecompiler.js +24 -9
  14. package/lib/dialects/mssql/schema/mssql-viewcompiler.js +15 -1
  15. package/lib/dialects/mysql/index.js +3 -7
  16. package/lib/dialects/mysql/query/mysql-querycompiler.js +91 -5
  17. package/lib/dialects/mysql/schema/mysql-columncompiler.js +32 -5
  18. package/lib/dialects/mysql/schema/mysql-tablecompiler.js +28 -4
  19. package/lib/dialects/mysql2/index.js +7 -4
  20. package/lib/dialects/oracle/query/oracle-querycompiler.js +7 -6
  21. package/lib/dialects/oracle/schema/internal/trigger.js +1 -1
  22. package/lib/dialects/oracle/schema/oracle-columncompiler.js +10 -4
  23. package/lib/dialects/oracle/schema/oracle-tablecompiler.js +17 -6
  24. package/lib/dialects/oracledb/index.js +0 -4
  25. package/lib/dialects/oracledb/query/oracledb-querycompiler.js +104 -0
  26. package/lib/dialects/oracledb/schema/oracledb-columncompiler.js +23 -0
  27. package/lib/dialects/postgres/index.js +21 -6
  28. package/lib/dialects/postgres/query/pg-querybuilder.js +8 -0
  29. package/lib/dialects/postgres/query/pg-querycompiler.js +166 -5
  30. package/lib/dialects/postgres/schema/pg-columncompiler.js +24 -4
  31. package/lib/dialects/postgres/schema/pg-tablecompiler.js +55 -47
  32. package/lib/dialects/redshift/index.js +12 -0
  33. package/lib/dialects/redshift/query/redshift-querycompiler.js +62 -26
  34. package/lib/dialects/redshift/schema/redshift-columncompiler.js +2 -1
  35. package/lib/dialects/redshift/schema/redshift-tablecompiler.js +4 -1
  36. package/lib/dialects/sqlite3/index.js +18 -4
  37. package/lib/dialects/sqlite3/query/sqlite-querycompiler.js +85 -18
  38. package/lib/dialects/sqlite3/schema/ddl.js +274 -282
  39. package/lib/dialects/sqlite3/schema/internal/sqlite-ddl-operations.js +18 -8
  40. package/lib/dialects/sqlite3/schema/sqlite-columncompiler.js +20 -0
  41. package/lib/dialects/sqlite3/schema/sqlite-compiler.js +16 -12
  42. package/lib/dialects/sqlite3/schema/sqlite-tablecompiler.js +15 -5
  43. package/lib/dialects/sqlite3/schema/sqlite-viewcompiler.js +31 -2
  44. package/lib/execution/runner.js +37 -2
  45. package/lib/knex-builder/FunctionHelper.js +21 -0
  46. package/lib/migrations/common/MigrationsLoader.js +36 -0
  47. package/lib/migrations/migrate/MigrationGenerator.js +1 -1
  48. package/lib/migrations/migrate/Migrator.js +20 -23
  49. package/lib/migrations/migrate/migration-list-resolver.js +2 -5
  50. package/lib/migrations/migrate/{configuration-merger.js → migrator-configuration-merger.js} +2 -4
  51. package/lib/migrations/migrate/sources/fs-migrations.js +4 -29
  52. package/lib/migrations/migrate/stub/js.stub +8 -1
  53. package/lib/migrations/migrate/stub/knexfile-js.stub +3 -0
  54. package/lib/migrations/migrate/stub/knexfile-ts.stub +5 -2
  55. package/lib/migrations/migrate/table-creator.js +6 -5
  56. package/lib/migrations/seed/Seeder.js +25 -92
  57. package/lib/migrations/seed/seeder-configuration-merger.js +60 -0
  58. package/lib/migrations/seed/sources/fs-seeds.js +65 -0
  59. package/lib/migrations/seed/stub/js.stub +4 -1
  60. package/lib/migrations/util/import-file.js +0 -1
  61. package/lib/query/joinclause.js +24 -5
  62. package/lib/query/method-constants.js +37 -0
  63. package/lib/query/querybuilder.js +230 -5
  64. package/lib/query/querycompiler.js +269 -84
  65. package/lib/schema/columnbuilder.js +8 -0
  66. package/lib/schema/columncompiler.js +132 -5
  67. package/lib/schema/compiler.js +1 -0
  68. package/lib/schema/tablebuilder.js +41 -8
  69. package/lib/schema/tablecompiler.js +57 -0
  70. package/lib/schema/viewcompiler.js +13 -10
  71. package/package.json +35 -22
  72. package/scripts/docker-compose.yml +7 -7
  73. package/scripts/oracledb-install-driver-libs.sh +82 -0
  74. package/scripts/runkit-example.js +1 -1
  75. package/scripts/stress-test/docker-compose.yml +3 -3
  76. package/scripts/stress-test/knex-stress-test.js +1 -1
  77. package/scripts/stress-test/reconnect-test-mysql-based-drivers.js +1 -1
  78. package/types/index.d.ts +124 -20
@@ -1,13 +1,9 @@
1
- function createNewTable(sql, tablename, alteredName) {
2
- return sql.replace(tablename, alteredName);
3
- }
4
-
5
1
  function copyData(sourceTable, targetTable, columns) {
6
- return `INSERT INTO ${targetTable} SELECT ${
2
+ return `INSERT INTO "${targetTable}" SELECT ${
7
3
  columns === undefined
8
4
  ? '*'
9
5
  : columns.map((column) => `"${column}"`).join(', ')
10
- } FROM ${sourceTable};`;
6
+ } FROM "${sourceTable}";`;
11
7
  }
12
8
 
13
9
  function dropOriginal(tableName) {
@@ -19,13 +15,27 @@ function renameTable(tableName, alteredName) {
19
15
  }
20
16
 
21
17
  function getTableSql(tableName) {
22
- return `SELECT type, sql FROM sqlite_master WHERE (type="table" OR (type="index" AND sql IS NOT NULL)) AND tbl_name="${tableName}"`;
18
+ return `SELECT type, sql FROM sqlite_master WHERE (type='table' OR (type='index' AND sql IS NOT NULL)) AND tbl_name='${tableName}'`;
19
+ }
20
+
21
+ function isForeignCheckEnabled() {
22
+ return `PRAGMA foreign_keys`;
23
+ }
24
+
25
+ function setForeignCheck(enable) {
26
+ return `PRAGMA foreign_keys = ${enable ? 'ON' : 'OFF'}`;
27
+ }
28
+
29
+ function executeForeignCheck() {
30
+ return `PRAGMA foreign_key_check`;
23
31
  }
24
32
 
25
33
  module.exports = {
26
- createNewTable,
27
34
  copyData,
28
35
  dropOriginal,
29
36
  renameTable,
30
37
  getTableSql,
38
+ isForeignCheckEnabled,
39
+ setForeignCheck,
40
+ executeForeignCheck,
31
41
  };
@@ -7,6 +7,7 @@ class ColumnCompiler_SQLite3 extends ColumnCompiler {
7
7
  constructor() {
8
8
  super(...arguments);
9
9
  this.modifiers = ['nullable', 'defaultTo'];
10
+ this._addCheckModifiers();
10
11
  }
11
12
 
12
13
  // Types
@@ -17,6 +18,21 @@ class ColumnCompiler_SQLite3 extends ColumnCompiler {
17
18
  this.args[0]
18
19
  )} in ('${allowed.join("', '")}'))`;
19
20
  }
21
+
22
+ _pushAlterCheckQuery(checkPredicate, constraintName) {
23
+ throw new Error(
24
+ `Alter table with to add constraints is not permitted in SQLite`
25
+ );
26
+ }
27
+
28
+ checkRegex(regexes, constraintName) {
29
+ return this._check(
30
+ `${this.formatter.wrap(
31
+ this.getColumnName()
32
+ )} REGEXP ${this.client._escapeBinding(regexes)}`,
33
+ constraintName
34
+ );
35
+ }
20
36
  }
21
37
 
22
38
  ColumnCompiler_SQLite3.prototype.json = 'json';
@@ -26,5 +42,9 @@ ColumnCompiler_SQLite3.prototype.double =
26
42
  ColumnCompiler_SQLite3.prototype.floating =
27
43
  'float';
28
44
  ColumnCompiler_SQLite3.prototype.timestamp = 'datetime';
45
+ // autoincrement without primary key is a syntax error in SQLite, so it's necessary
46
+ ColumnCompiler_SQLite3.prototype.increments =
47
+ ColumnCompiler_SQLite3.prototype.bigincrements =
48
+ 'integer not null primary key autoincrement';
29
49
 
30
50
  module.exports = ColumnCompiler_SQLite3;
@@ -17,7 +17,7 @@ class SchemaCompiler_SQLite3 extends SchemaCompiler {
17
17
  const sql =
18
18
  `select * from sqlite_master ` +
19
19
  `where type = 'table' and name = ${this.client.parameter(
20
- tableName,
20
+ this.formatter.wrap(tableName).replace(/`/g, ''),
21
21
  this.builder,
22
22
  this.bindingsHolder
23
23
  )}`;
@@ -55,21 +55,25 @@ class SchemaCompiler_SQLite3 extends SchemaCompiler {
55
55
  this[query.method].apply(this, query.args);
56
56
  }
57
57
 
58
- const result = [];
59
58
  const commandSources = this.sequence;
60
- for (const commandSource of commandSources) {
61
- const command = commandSource.statementsProducer
62
- ? await commandSource.statementsProducer()
63
- : commandSource.sql;
64
59
 
65
- if (Array.isArray(command)) {
66
- result.push(...command);
67
- } else {
68
- result.push(command);
60
+ if (commandSources.length === 1 && commandSources[0].statementsProducer) {
61
+ return commandSources[0].statementsProducer();
62
+ } else {
63
+ const result = [];
64
+
65
+ for (const commandSource of commandSources) {
66
+ const command = commandSource.sql;
67
+
68
+ if (Array.isArray(command)) {
69
+ result.push(...command);
70
+ } else {
71
+ result.push(command);
72
+ }
69
73
  }
70
- }
71
74
 
72
- return { pre: [], sql: result, post: [] };
75
+ return { pre: [], sql: result, check: null, post: [] };
76
+ }
73
77
  }
74
78
  }
75
79
 
@@ -27,9 +27,14 @@ class TableCompiler_SQLite3 extends TableCompiler {
27
27
  sql += ' (' + columns.sql.join(', ');
28
28
  sql += this.foreignKeys() || '';
29
29
  sql += this.primaryKeys() || '';
30
+ sql += this._addChecks();
30
31
  sql += ')';
31
32
  }
32
33
  this.pushQuery(sql);
34
+
35
+ if (like) {
36
+ this.addColumns(columns, this.addColumnsPrefix);
37
+ }
33
38
  }
34
39
 
35
40
  addColumns(columns, prefix, colCompilers) {
@@ -57,9 +62,9 @@ class TableCompiler_SQLite3 extends TableCompiler {
57
62
 
58
63
  this.pushQuery({
59
64
  sql: `PRAGMA table_info(${this.tableName()})`,
60
- output(pragma) {
65
+ statementsProducer(pragma, connection) {
61
66
  return compiler.client
62
- .ddl(compiler, pragma, this.connection)
67
+ .ddl(compiler, pragma, connection)
63
68
  .alterColumn(columnsInfo);
64
69
  },
65
70
  });
@@ -257,9 +262,14 @@ class TableCompiler_SQLite3 extends TableCompiler {
257
262
  if (constraintName) {
258
263
  constraintName = ' constraint ' + this.formatter.wrap(constraintName);
259
264
  }
260
- return `,${constraintName} primary key (${this.formatter.columnize(
261
- columns
262
- )})`;
265
+ const needUniqueCols =
266
+ this.grouped.columns.filter((t) => t.builder._type === 'increments')
267
+ .length > 0;
268
+ // SQLite dont support autoincrement columns and composite primary keys (autoincrement is always primary key).
269
+ // You need to add unique index instead when you have autoincrement columns (https://stackoverflow.com/a/6154876/1535159)
270
+ return `,${constraintName} ${
271
+ needUniqueCols ? 'unique' : 'primary key'
272
+ } (${this.formatter.columnize(columns)})`;
263
273
  }
264
274
  }
265
275
 
@@ -1,11 +1,40 @@
1
1
  /* eslint max-len: 0 */
2
2
 
3
3
  const ViewCompiler = require('../../../schema/viewcompiler.js');
4
+ const {
5
+ columnize: columnize_,
6
+ } = require('../../../formatter/wrappingFormatter');
4
7
 
5
- class ViewCompiler_PG extends ViewCompiler {
8
+ class ViewCompiler_SQLite3 extends ViewCompiler {
6
9
  constructor(client, viewCompiler) {
7
10
  super(client, viewCompiler);
8
11
  }
12
+ createOrReplace() {
13
+ const columns = this.columns;
14
+ const selectQuery = this.selectQuery.toString();
15
+ const viewName = this.viewName();
16
+
17
+ const columnList = columns
18
+ ? ' (' +
19
+ columnize_(
20
+ columns,
21
+ this.viewBuilder,
22
+ this.client,
23
+ this.bindingsHolder
24
+ ) +
25
+ ')'
26
+ : '';
27
+
28
+ const dropSql = `drop view if exists ${viewName}`;
29
+ const createSql = `create view ${viewName}${columnList} as ${selectQuery}`;
30
+
31
+ this.pushQuery({
32
+ sql: dropSql,
33
+ });
34
+ this.pushQuery({
35
+ sql: createSql,
36
+ });
37
+ }
9
38
  }
10
39
 
11
- module.exports = ViewCompiler_PG;
40
+ module.exports = ViewCompiler_SQLite3;
@@ -228,12 +228,47 @@ class Runner {
228
228
  undefined,
229
229
  this.connection
230
230
  );
231
- const queryObjects = statements.map((statement) => ({
231
+
232
+ const sqlQueryObjects = statements.sql.map((statement) => ({
233
+ sql: statement,
234
+ bindings: query.bindings,
235
+ }));
236
+ const preQueryObjects = statements.pre.map((statement) => ({
232
237
  sql: statement,
233
238
  bindings: query.bindings,
234
239
  }));
240
+ const postQueryObjects = statements.post.map((statement) => ({
241
+ sql: statement,
242
+ bindings: query.bindings,
243
+ }));
244
+
245
+ let results = [];
246
+
247
+ await this.queryArray(preQueryObjects);
248
+
249
+ try {
250
+ await this.client.transaction(
251
+ async (trx) => {
252
+ const transactionRunner = new Runner(trx.client, this.builder);
253
+ transactionRunner.connection = this.connection;
254
+
255
+ results = await transactionRunner.queryArray(sqlQueryObjects);
256
+
257
+ if (statements.check) {
258
+ const foreignViolations = await trx.raw(statements.check);
259
+
260
+ if (foreignViolations.length > 0) {
261
+ throw new Error('FOREIGN KEY constraint failed');
262
+ }
263
+ }
264
+ },
265
+ { connection: this.connection }
266
+ );
267
+ } finally {
268
+ await this.queryArray(postQueryObjects);
269
+ }
235
270
 
236
- return this.queryArray(queryObjects);
271
+ return results;
237
272
  }
238
273
 
239
274
  const results = [];
@@ -13,6 +13,27 @@ class FunctionHelper {
13
13
  }
14
14
  return this.client.raw('CURRENT_TIMESTAMP');
15
15
  }
16
+
17
+ uuidToBin(uuid) {
18
+ const buf = Buffer.from(uuid.replace(/-/g, ''), 'hex');
19
+ return Buffer.concat([
20
+ buf.slice(6, 8),
21
+ buf.slice(4, 6),
22
+ buf.slice(0, 4),
23
+ buf.slice(8, 16),
24
+ ]);
25
+ }
26
+
27
+ binToUuid(bin) {
28
+ const buf = new Buffer(bin, 'hex');
29
+ return [
30
+ buf.toString('hex', 4, 8),
31
+ buf.toString('hex', 2, 4),
32
+ buf.toString('hex', 0, 2),
33
+ buf.toString('hex', 8, 10),
34
+ buf.toString('hex', 10, 16),
35
+ ].join('-');
36
+ }
16
37
  }
17
38
 
18
39
  module.exports = FunctionHelper;
@@ -0,0 +1,36 @@
1
+ const path = require('path');
2
+ const DEFAULT_LOAD_EXTENSIONS = Object.freeze([
3
+ '.co',
4
+ '.coffee',
5
+ '.eg',
6
+ '.iced',
7
+ '.js',
8
+ '.cjs',
9
+ '.litcoffee',
10
+ '.ls',
11
+ '.ts',
12
+ ]);
13
+
14
+ class AbstractMigrationsLoader {
15
+ constructor(migrationDirectories, sortDirsSeparately, loadExtensions) {
16
+ this.sortDirsSeparately = sortDirsSeparately;
17
+
18
+ if (!Array.isArray(migrationDirectories)) {
19
+ migrationDirectories = [migrationDirectories];
20
+ }
21
+ this.migrationsPaths = migrationDirectories;
22
+ this.loadExtensions = loadExtensions || DEFAULT_LOAD_EXTENSIONS;
23
+ }
24
+
25
+ getFile(migrationsInfo) {
26
+ const absoluteDir = path.resolve(process.cwd(), migrationsInfo.directory);
27
+ const _path = path.join(absoluteDir, migrationsInfo.file);
28
+ const importFile = require('../util/import-file'); // late import
29
+ return importFile(_path);
30
+ }
31
+ }
32
+
33
+ module.exports = {
34
+ DEFAULT_LOAD_EXTENSIONS,
35
+ AbstractMigrationsLoader,
36
+ };
@@ -1,6 +1,6 @@
1
1
  const path = require('path');
2
2
  const { writeJsFileUsingTemplate } = require('../util/template');
3
- const { getMergedConfig } = require('./configuration-merger');
3
+ const { getMergedConfig } = require('./migrator-configuration-merger');
4
4
  const { ensureDirectoryExists } = require('../util/fs');
5
5
  const { yyyymmddhhmmss } = require('../util/timestamp');
6
6
 
@@ -4,7 +4,6 @@ const differenceWith = require('lodash/differenceWith');
4
4
  const get = require('lodash/get');
5
5
  const isEmpty = require('lodash/isEmpty');
6
6
  const max = require('lodash/max');
7
- const { inherits } = require('util');
8
7
  const {
9
8
  getLockTableName,
10
9
  getTable,
@@ -13,16 +12,16 @@ const {
13
12
  const { getSchemaBuilder } = require('./table-creator');
14
13
  const migrationListResolver = require('./migration-list-resolver');
15
14
  const MigrationGenerator = require('./MigrationGenerator');
16
- const { getMergedConfig } = require('./configuration-merger');
15
+ const { getMergedConfig } = require('./migrator-configuration-merger');
17
16
  const { isBoolean, isFunction } = require('../../util/is');
18
17
 
19
- function LockError(msg) {
20
- this.name = 'MigrationLocked';
21
- this.message = msg;
18
+ class LockError extends Error {
19
+ constructor(msg) {
20
+ super(msg);
21
+ this.name = 'MigrationLocked';
22
+ }
22
23
  }
23
24
 
24
- inherits(LockError, Error);
25
-
26
25
  // The new migration we're performing, typically called from the `knex.migrate`
27
26
  // interface on the main `knex` object. Passes the `knex` instance performing
28
27
  // the migration.
@@ -187,9 +186,11 @@ class Migrator {
187
186
  return all
188
187
  ? allMigrations
189
188
  .filter((migration) => {
190
- return completedMigrations.includes(
191
- this.config.migrationSource.getMigrationName(migration)
192
- );
189
+ return completedMigrations
190
+ .map((migration) => migration.name)
191
+ .includes(
192
+ this.config.migrationSource.getMigrationName(migration)
193
+ );
193
194
  })
194
195
  .reverse()
195
196
  : this._getLastBatch(val);
@@ -215,9 +216,9 @@ class Migrator {
215
216
  })
216
217
  .then(([all, completed]) => {
217
218
  const completedMigrations = all.filter((migration) => {
218
- return completed.includes(
219
- this.config.migrationSource.getMigrationName(migration)
220
- );
219
+ return completed
220
+ .map((migration) => migration.name)
221
+ .includes(this.config.migrationSource.getMigrationName(migration));
221
222
  });
222
223
 
223
224
  let migrationToRun;
@@ -265,7 +266,7 @@ class Migrator {
265
266
  return migrationListResolver
266
267
  .listCompleted(this.config.tableName, this.config.schemaName, this.knex)
267
268
  .then((completed) => {
268
- const val = max(completed.map((value) => value.split('_')[0]));
269
+ const val = max(completed.map((value) => value.name.split('_')[0]));
269
270
  return val === undefined ? 'none' : val;
270
271
  });
271
272
  }
@@ -327,7 +328,7 @@ class Migrator {
327
328
  .where('is_locked', '=', 0)
328
329
  .update({ is_locked: 1 })
329
330
  .then((rowCount) => {
330
- if (rowCount != 1) {
331
+ if (rowCount !== 1) {
331
332
  throw new Error('Migration table is already locked');
332
333
  }
333
334
  });
@@ -570,18 +571,14 @@ function validateMigrationList(migrationSource, migrations) {
570
571
  }
571
572
 
572
573
  function getMissingMigrations(migrationSource, completed, all) {
573
- return differenceWith(completed, all, (completedMigration, allMigration) => {
574
- return (
575
- completedMigration === migrationSource.getMigrationName(allMigration)
576
- );
574
+ return differenceWith(completed, all, (c, a) => {
575
+ return c.name === migrationSource.getMigrationName(a);
577
576
  });
578
577
  }
579
578
 
580
579
  function getNewMigrations(migrationSource, all, completed) {
581
- return differenceWith(all, completed, (allMigration, completedMigration) => {
582
- return (
583
- completedMigration === migrationSource.getMigrationName(allMigration)
584
- );
580
+ return differenceWith(all, completed, (a, c) => {
581
+ return c.name === migrationSource.getMigrationName(a);
585
582
  });
586
583
  }
587
584
 
@@ -10,14 +10,11 @@ function listAll(migrationSource, loadExtensions) {
10
10
  // array.
11
11
  async function listCompleted(tableName, schemaName, trxOrKnex) {
12
12
  await ensureTable(tableName, schemaName, trxOrKnex);
13
- const completedMigrations = await trxOrKnex
13
+
14
+ return await trxOrKnex
14
15
  .from(getTableName(tableName, schemaName))
15
16
  .orderBy('id')
16
17
  .select('name');
17
-
18
- return completedMigrations.map((migration) => {
19
- return migration.name;
20
- });
21
18
  }
22
19
 
23
20
  // Gets the migration list from the migration directory specified in config, as well as
@@ -1,8 +1,6 @@
1
- const {
2
- FsMigrations,
3
- DEFAULT_LOAD_EXTENSIONS,
4
- } = require('./sources/fs-migrations');
1
+ const { FsMigrations } = require('./sources/fs-migrations');
5
2
  const Logger = require('../../logger');
3
+ const { DEFAULT_LOAD_EXTENSIONS } = require('../common/MigrationsLoader');
6
4
  const defaultLogger = new Logger();
7
5
 
8
6
  const CONFIG_DEFAULT = Object.freeze({
@@ -2,30 +2,9 @@ const path = require('path');
2
2
  const sortBy = require('lodash/sortBy');
3
3
 
4
4
  const { readdir } = require('../../util/fs');
5
+ const { AbstractMigrationsLoader } = require('../../common/MigrationsLoader');
5
6
 
6
- const DEFAULT_LOAD_EXTENSIONS = Object.freeze([
7
- '.co',
8
- '.coffee',
9
- '.eg',
10
- '.iced',
11
- '.js',
12
- '.cjs',
13
- '.litcoffee',
14
- '.ls',
15
- '.ts',
16
- ]);
17
-
18
- class FsMigrations {
19
- constructor(migrationDirectories, sortDirsSeparately, loadExtensions) {
20
- this.sortDirsSeparately = sortDirsSeparately;
21
-
22
- if (!Array.isArray(migrationDirectories)) {
23
- migrationDirectories = [migrationDirectories];
24
- }
25
- this.migrationsPaths = migrationDirectories;
26
- this.loadExtensions = loadExtensions || DEFAULT_LOAD_EXTENSIONS;
27
- }
28
-
7
+ class FsMigrations extends AbstractMigrationsLoader {
29
8
  /**
30
9
  * Gets the migration names
31
10
  * @returns Promise<string[]>
@@ -77,11 +56,8 @@ class FsMigrations {
77
56
  return migration.file;
78
57
  }
79
58
 
80
- getMigration(migration) {
81
- const absoluteDir = path.resolve(process.cwd(), migration.directory);
82
- const _path = path.join(absoluteDir, migration.file);
83
- const importFile = require('../../util/import-file'); // late import
84
- return importFile(_path);
59
+ getMigration(migrationInfo) {
60
+ return this.getFile(migrationInfo);
85
61
  }
86
62
  }
87
63
 
@@ -94,6 +70,5 @@ function filterMigrations(migrationSource, migrations, loadExtensions) {
94
70
  }
95
71
 
96
72
  module.exports = {
97
- DEFAULT_LOAD_EXTENSIONS,
98
73
  FsMigrations,
99
74
  };
@@ -1,4 +1,7 @@
1
-
1
+ /**
2
+ * @param { import("knex").Knex } knex
3
+ * @returns { Promise<void> }
4
+ */
2
5
  exports.up = function(knex) {
3
6
  <% if (d.tableName) { %>
4
7
  return knex.schema.createTable("<%= d.tableName %>", function(t) {
@@ -8,6 +11,10 @@ exports.up = function(knex) {
8
11
  <% } %>
9
12
  };
10
13
 
14
+ /**
15
+ * @param { import("knex").Knex } knex
16
+ * @returns { Promise<void> }
17
+ */
11
18
  exports.down = function(knex) {
12
19
  <% if (d.tableName) { %>
13
20
  return knex.schema.dropTable("<%= d.tableName %>");
@@ -1,5 +1,8 @@
1
1
  // Update with your config settings.
2
2
 
3
+ /**
4
+ * @type { Object.<string, import("knex").Knex.Config> }
5
+ */
3
6
  module.exports = {
4
7
 
5
8
  development: {
@@ -1,7 +1,8 @@
1
- // Update with your config settings.
1
+ import type { Knex } from "knex";
2
2
 
3
- module.exports = {
3
+ // Update with your config settings.
4
4
 
5
+ const config: { [key: string]: Knex.Config } = {
5
6
  development: {
6
7
  client: "sqlite3",
7
8
  connection: {
@@ -42,3 +43,5 @@ module.exports = {
42
43
  }
43
44
 
44
45
  };
46
+
47
+ module.exports = config;
@@ -55,11 +55,12 @@ function _createMigrationLockTable(tableName, schemaName, trxOrKnex) {
55
55
  function _insertLockRowIfNeeded(tableName, schemaName, trxOrKnex) {
56
56
  const lockTableWithSchema = getLockTableNameWithSchema(tableName, schemaName);
57
57
  return trxOrKnex
58
- .from(trxOrKnex.raw('?? (??)', [lockTableWithSchema, 'is_locked']))
59
- .insert(function () {
60
- return this.select(trxOrKnex.raw('?', [0])).whereNotExists(function () {
61
- return this.select('*').from(lockTableWithSchema);
62
- });
58
+ .select('*')
59
+ .from(lockTableWithSchema)
60
+ .then((data) => {
61
+ return !data.length
62
+ ? trxOrKnex.from(lockTableWithSchema).insert({ is_locked: 0 })
63
+ : null;
63
64
  });
64
65
  }
65
66