knex-migrator 5.3.2 → 5.4.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.
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2025 Ghost Foundation
1
+ Copyright (c) 2013-2026 Ghost Foundation
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -336,7 +336,7 @@ knexMigrator.isDatabaseOK()
336
336
 
337
337
  # Copyright & License
338
338
 
339
- Copyright (c) 2013-2025 Ghost Foundation - Released under the [MIT license](LICENSE).
339
+ Copyright (c) 2013-2026 Ghost Foundation - Released under the [MIT license](LICENSE).
340
340
 
341
341
 
342
342
 
package/lib/database.js CHANGED
@@ -180,7 +180,16 @@ exports.drop = function drop(options) {
180
180
  } else if (DatabaseInfo.isSQLite(connection)) {
181
181
  // @NOTE: sqlite3 does not support "DROP DATABASE". We have to drop each table instead.
182
182
  // @NOTE: We cannot just remove the sqlite3 file, because any database connection will get invalid.
183
- return connection.raw('SELECT name FROM sqlite_master WHERE type="table";')
183
+ // @NOTE: better-sqlite3 enforces foreign key constraints, so dropping a parent table before
184
+ // its referencing children trips an FK error. Disable foreign keys for the duration of the
185
+ // drop and restore afterwards. SQLite uses a single connection here, so the PRAGMA persists
186
+ // across the drops. The legacy sqlite3 driver does not enforce these, so we leave it untouched.
187
+ const isBetterSqlite = connection.client.config.client === 'better-sqlite3';
188
+
189
+ return (isBetterSqlite ? connection.raw('PRAGMA foreign_keys = OFF;') : Promise.resolve())
190
+ .then(function () {
191
+ return connection.raw(`SELECT name FROM sqlite_master WHERE type='table';`);
192
+ })
184
193
  .then(function (tables) {
185
194
  return sequence(tables.map(table => () => {
186
195
  if (table.name === 'sqlite_sequence') {
@@ -201,6 +210,11 @@ exports.drop = function drop(options) {
201
210
  return Promise.reject(new errors.KnexMigrateError({
202
211
  err: err
203
212
  }));
213
+ })
214
+ .finally(function () {
215
+ if (isBetterSqlite) {
216
+ return connection.raw('PRAGMA foreign_keys = ON;');
217
+ }
204
218
  });
205
219
  } else {
206
220
  return Promise.reject(new errors.KnexMigrateError({
package/lib/index.js CHANGED
@@ -1207,7 +1207,11 @@ KnexMigrator.prototype._integrityCheck = async function _integrityCheck(options)
1207
1207
  }
1208
1208
 
1209
1209
  // CASE: migration table does not exist
1210
- if (err.errno === 1 || err.errno === 1146) {
1210
+ if (
1211
+ err.errno === 1
1212
+ || err.errno === 1146
1213
+ || (err.code === 'SQLITE_ERROR' && /no such table: migrations/.test(err.message))
1214
+ ) {
1211
1215
  throw new errors.DatabaseIsNotOkError({
1212
1216
  message: 'Please run `yarn knex-migrator init`',
1213
1217
  code: 'MIGRATION_TABLE_IS_MISSING'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knex-migrator",
3
- "version": "5.3.2",
3
+ "version": "5.4.1",
4
4
  "description": "Database migrations with knex.",
5
5
  "keywords": [
6
6
  "ghost",
@@ -47,19 +47,19 @@
47
47
  "node": "^14.18.0 || ^16.13.0 || ^18.12.1 || ^20.11.1 || ^22.13.1"
48
48
  },
49
49
  "dependencies": {
50
- "@tryghost/database-info": "0.3.22",
51
- "@tryghost/errors": "1.3.6",
52
- "@tryghost/logging": "2.4.19",
53
- "@tryghost/promise": "0.3.8",
50
+ "@tryghost/database-info": "0.3.35",
51
+ "@tryghost/errors": "1.3.13",
52
+ "@tryghost/logging": "2.5.5",
53
+ "@tryghost/promise": "0.3.20",
54
54
  "commander": "5.1.0",
55
55
  "compare-ver": "2.0.2",
56
- "debug": "4.4.1",
57
- "knex": "2.4.2",
58
- "lodash": "4.17.21",
59
- "moment": "2.24.0",
60
- "mysql2": "3.14.1",
61
- "nconf": "0.12.1",
62
- "resolve": "1.22.8"
56
+ "debug": "4.4.3",
57
+ "knex": "3.2.10",
58
+ "lodash": "4.18.1",
59
+ "moment": "2.30.1",
60
+ "mysql2": "3.22.5",
61
+ "nconf": "0.13.0",
62
+ "resolve": "1.22.12"
63
63
  },
64
64
  "files": [
65
65
  "bin",
@@ -71,12 +71,13 @@
71
71
  "eslint": "6.8.0",
72
72
  "eslint-plugin-ghost": "0.2.0",
73
73
  "mocha": "7.2.0",
74
- "nyc": "15.1.0",
74
+ "nyc": "17.1.0",
75
75
  "rimraf": "3.0.2",
76
76
  "should": "13.2.3",
77
- "sinon": "9.2.4"
77
+ "sinon": "22.0.0"
78
78
  },
79
79
  "optionalDependencies": {
80
+ "better-sqlite3": "12.11.1",
80
81
  "sqlite3": "5.1.7"
81
82
  }
82
83
  }
@@ -0,0 +1,9 @@
1
+ {
2
+ "database": {
3
+ "client": "better-sqlite3",
4
+ "connection": {
5
+ "filename": "test.db"
6
+ },
7
+ "useNullAsDefault": true
8
+ }
9
+ }