@axiosleo/orm-mysql 0.9.0 → 0.9.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/bin/orm-mysql.js +1 -1
- package/commands/migrate.js +2 -1
- package/package.json +1 -1
- package/src/builder.js +8 -1
- package/src/core.js +4 -0
- package/src/migration.js +3 -1
package/bin/orm-mysql.js
CHANGED
package/commands/migrate.js
CHANGED
|
@@ -15,9 +15,9 @@ class MigrateCommand extends Command {
|
|
|
15
15
|
|
|
16
16
|
this.addOption('debug', 'd', '[false] debug mode', 'optional', false);
|
|
17
17
|
this.addOption('host', null, '[localhost] mysql host', 'optional', 'localhost');
|
|
18
|
+
this.addOption('port', null, '[3306] port number to connect to the database', 'optional', 3306);
|
|
18
19
|
this.addOption('user', null, '[root] username for connect to the database', 'optional', 'root');
|
|
19
20
|
this.addOption('pass', null, 'password to connect to the database', 'optional', '');
|
|
20
|
-
this.addOption('port', null, '[3306] port number to connect to the database', 'optional', 3306);
|
|
21
21
|
this.addOption('db', null, 'database name', 'optional', '');
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -29,6 +29,7 @@ class MigrateCommand extends Command {
|
|
|
29
29
|
const workflow = new Workflow(migration);
|
|
30
30
|
try {
|
|
31
31
|
await workflow.start({
|
|
32
|
+
task_key: 'migrate_logs',
|
|
32
33
|
action: args.action,
|
|
33
34
|
config: {
|
|
34
35
|
dir: args.dir
|
package/package.json
CHANGED
package/src/builder.js
CHANGED
|
@@ -273,6 +273,9 @@ class Builder {
|
|
|
273
273
|
if (key === null) {
|
|
274
274
|
return '';
|
|
275
275
|
}
|
|
276
|
+
if (typeof key === 'undefined') {
|
|
277
|
+
throw new Error('Field key is required');
|
|
278
|
+
}
|
|
276
279
|
if (key.indexOf('(') !== -1 && key.indexOf(')') !== -1) {
|
|
277
280
|
let field = key.substring(key.indexOf('(') + 1, key.indexOf(')'));
|
|
278
281
|
key = key.substring(0, key.indexOf('(')) + '(' + this._buildFieldWithTableName(field) + ')' + key.substring(key.indexOf(')') + 1);
|
|
@@ -501,9 +504,13 @@ class ManageSQLBuilder extends Builder {
|
|
|
501
504
|
}
|
|
502
505
|
if (options.default === null) {
|
|
503
506
|
str += ' DEFAULT NULL';
|
|
504
|
-
} else if (options.default === 'timestamp') {
|
|
507
|
+
} else if (options.default === 'timestamp' || options.default === 'TIMESTAMP') {
|
|
505
508
|
str += ' DEFAULT CURRENT_TIMESTAMP';
|
|
509
|
+
} else if (options.default === 'CURRENT_TIMESTAMP') {
|
|
510
|
+
str += ` DEFAULT ${options.default}`;
|
|
506
511
|
} else if (is.string(options.default)) {
|
|
512
|
+
str += ` DEFAULT '${options.default}'`;
|
|
513
|
+
} else {
|
|
507
514
|
str += ` DEFAULT ${options.default}`;
|
|
508
515
|
}
|
|
509
516
|
}
|
package/src/core.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const { Builder } = require('./builder');
|
|
4
|
+
const is = require('@axiosleo/cli-tool/src/helper/is');
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
*
|
|
@@ -10,6 +11,9 @@ const { Builder } = require('./builder');
|
|
|
10
11
|
* @returns
|
|
11
12
|
*/
|
|
12
13
|
const _query = (conn, options, opt = null) => {
|
|
14
|
+
if (is.empty(options)) {
|
|
15
|
+
options = { driver: 'mysql' };
|
|
16
|
+
}
|
|
13
17
|
switch (options.driver) {
|
|
14
18
|
case 'mysql': {
|
|
15
19
|
if (opt === null) {
|
package/src/migration.js
CHANGED
|
@@ -58,7 +58,9 @@ async function init(context) {
|
|
|
58
58
|
const connect = require(connectPath);
|
|
59
59
|
_assign(context.connection, connect);
|
|
60
60
|
}
|
|
61
|
-
context.task_key
|
|
61
|
+
if (!context.task_key) {
|
|
62
|
+
context.task_key = 'migrate_' + context.connection.database;
|
|
63
|
+
}
|
|
62
64
|
let globalConn = createClient({
|
|
63
65
|
...context.connection,
|
|
64
66
|
database: 'mysql'
|