knex-migrator 4.1.2 → 4.2.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 +1 -1
- package/README.md +2 -2
- package/lib/database.js +11 -5
- package/lib/index.js +6 -1
- package/package.json +5 -5
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ Please add a file named `MigratorConfig.js`. Knex-migrator will load the config
|
|
|
52
52
|
```
|
|
53
53
|
module.exports = {
|
|
54
54
|
database: {
|
|
55
|
-
client: String (Required) ['mysql', 'sqlite3']
|
|
55
|
+
client: String (Required) ['mysql', 'mysql2', 'sqlite3']
|
|
56
56
|
connection: {
|
|
57
57
|
host: String, (Required) [e.g. '127.0.0.1']
|
|
58
58
|
user: String, (Required)
|
|
@@ -338,7 +338,7 @@ knexMigrator.isDatabaseOK()
|
|
|
338
338
|
|
|
339
339
|
# Copyright & License
|
|
340
340
|
|
|
341
|
-
Copyright (c) 2013-
|
|
341
|
+
Copyright (c) 2013-2022 Ghost Foundation - Released under the [MIT license](LICENSE).
|
|
342
342
|
|
|
343
343
|
|
|
344
344
|
|
package/lib/database.js
CHANGED
|
@@ -12,16 +12,22 @@ const knex = require('knex'),
|
|
|
12
12
|
*/
|
|
13
13
|
exports.connect = function connect(options) {
|
|
14
14
|
options = options || {};
|
|
15
|
+
|
|
16
|
+
// Alias `mysql` to `mysql2` so we can maintain backwards compatibility
|
|
17
|
+
if (options.client === 'mysql') {
|
|
18
|
+
options.client = 'mysql2';
|
|
19
|
+
}
|
|
20
|
+
|
|
15
21
|
const client = options.client;
|
|
16
22
|
|
|
17
23
|
if (client === 'sqlite3') {
|
|
18
24
|
options.useNullAsDefault = options.useNullAsDefault || false;
|
|
19
25
|
}
|
|
20
26
|
|
|
21
|
-
if (client === '
|
|
22
|
-
options.connection.timezone = options.connection.timezone || '
|
|
27
|
+
if (client === 'mysql2') {
|
|
28
|
+
options.connection.timezone = options.connection.timezone || 'Z';
|
|
23
29
|
options.connection.charset = options.connection.charset || 'utf8mb4';
|
|
24
|
-
options.connection.
|
|
30
|
+
options.connection.decimalNumbers = true;
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
return knex(options);
|
|
@@ -102,7 +108,7 @@ exports.createDatabaseIfNotExist = function createDatabaseIfNotExist(dbConfig) {
|
|
|
102
108
|
// @NOTE: Skip, because sqlite3 is a file based database.
|
|
103
109
|
if (dbConfig.client === 'sqlite3') {
|
|
104
110
|
return Promise.resolve();
|
|
105
|
-
} else if (dbConfig.client
|
|
111
|
+
} else if (!['mysql', 'mysql2'].includes(dbConfig.client)) {
|
|
106
112
|
return Promise.reject(new errors.KnexMigrateError({
|
|
107
113
|
message: 'Database is not supported.'
|
|
108
114
|
}));
|
|
@@ -157,7 +163,7 @@ exports.drop = function drop(options) {
|
|
|
157
163
|
const connection = options.connection,
|
|
158
164
|
dbConfig = options.dbConfig;
|
|
159
165
|
|
|
160
|
-
if (dbConfig.client
|
|
166
|
+
if (['mysql', 'mysql2'].includes(dbConfig.client)) {
|
|
161
167
|
debug('Drop database: ' + dbConfig.connection.database);
|
|
162
168
|
|
|
163
169
|
return connection.raw('DROP DATABASE `' + dbConfig.connection.database + '`;')
|
package/lib/index.js
CHANGED
|
@@ -158,6 +158,7 @@ KnexMigrator.prototype.init = function init(options) {
|
|
|
158
158
|
return database.createTransaction(self.connection, async function (transacting) {
|
|
159
159
|
const existingMigrations = await transacting('migrations').select('name');
|
|
160
160
|
const existingMigrationsNames = existingMigrations.map(m => m.name);
|
|
161
|
+
const migrationsToAdd = [];
|
|
161
162
|
|
|
162
163
|
// CASE: Run over all migration scripts and add the file name to the database.
|
|
163
164
|
for (const versionToMigrateTo of versionsToMigrateTo) {
|
|
@@ -170,13 +171,17 @@ KnexMigrator.prototype.init = function init(options) {
|
|
|
170
171
|
continue;
|
|
171
172
|
}
|
|
172
173
|
|
|
173
|
-
|
|
174
|
+
migrationsToAdd.push({
|
|
174
175
|
name,
|
|
175
176
|
version: versionToMigrateTo,
|
|
176
177
|
currentVersion: self.currentVersion
|
|
177
178
|
});
|
|
178
179
|
}
|
|
179
180
|
}
|
|
181
|
+
|
|
182
|
+
await self.connection
|
|
183
|
+
.batchInsert('migrations', migrationsToAdd)
|
|
184
|
+
.transacting(transacting);
|
|
180
185
|
});
|
|
181
186
|
})
|
|
182
187
|
.then(function () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knex-migrator",
|
|
3
|
-
"version": "4.1
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "Database migrations with knex.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ghost",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"posttest": "yarn lint",
|
|
34
34
|
"coverage": "nyc --reporter=lcov _mocha --require test/utils.js -- test/*_spec.js",
|
|
35
35
|
"preship": "yarn test",
|
|
36
|
-
"ship": "STATUS=$(git status --porcelain); echo $STATUS; if [ -z \"$STATUS\" ]; then yarn publish && git push ${GHOST_UPSTREAM:-upstream}
|
|
36
|
+
"ship": "STATUS=$(git status --porcelain); echo $STATUS; if [ -z \"$STATUS\" ]; then yarn publish && git push ${GHOST_UPSTREAM:-upstream} main --follow-tags; fi"
|
|
37
37
|
},
|
|
38
38
|
"bin": {
|
|
39
39
|
"knex-migrator": "./bin/knex-migrator",
|
|
@@ -50,13 +50,13 @@
|
|
|
50
50
|
"bluebird": "3.7.2",
|
|
51
51
|
"commander": "5.1.0",
|
|
52
52
|
"compare-ver": "2.0.2",
|
|
53
|
-
"debug": "4.3.
|
|
53
|
+
"debug": "4.3.3",
|
|
54
54
|
"ghost-ignition": "4.6.3",
|
|
55
55
|
"knex": "0.21.19",
|
|
56
56
|
"lodash": "4.17.21",
|
|
57
57
|
"moment": "2.24.0",
|
|
58
58
|
"nconf": "0.11.3",
|
|
59
|
-
"resolve": "1.
|
|
59
|
+
"resolve": "1.22.0"
|
|
60
60
|
},
|
|
61
61
|
"files": [
|
|
62
62
|
"bin",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"sinon": "9.2.4"
|
|
75
75
|
},
|
|
76
76
|
"optionalDependencies": {
|
|
77
|
-
"
|
|
77
|
+
"mysql2": "2.3.3",
|
|
78
78
|
"sqlite3": "5.0.2"
|
|
79
79
|
}
|
|
80
80
|
}
|