db-migrate 0.11.8 → 0.11.12
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/get.js +67 -0
- package/lib/commands/dump.js +22 -0
- package/lib/commands/generated.js +1 -0
- package/lib/commands/run.js +0 -1
- package/lib/commands/set-default-argv.js +0 -1
- package/package.json +5 -1
- package/pnpm-lock.yaml +2574 -0
- package/te.js +70 -0
package/get.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
exports.migrate = async (db, opt) => {
|
|
2
|
+
await db.get('test', {
|
|
3
|
+
columns: ['column1']
|
|
4
|
+
});
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* columns can be aliased
|
|
8
|
+
*/
|
|
9
|
+
await db.get('test', {
|
|
10
|
+
columns: {
|
|
11
|
+
column1: 'maxima'
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* We avoid tapping into complicated languages to define
|
|
17
|
+
* the where clause. Instead you just use SQL or mongo schema
|
|
18
|
+
* depending on the db you use. If you want to provide genericity we will
|
|
19
|
+
* suggest using helper libraries like sql2mongo or vice versa. This allows
|
|
20
|
+
* flexibility and avoids also the need to learn to many new things and
|
|
21
|
+
* reinventing the weel just for a translation layer in this case.
|
|
22
|
+
*/
|
|
23
|
+
await db.get('test', {
|
|
24
|
+
columns: {
|
|
25
|
+
column1: 'maxima',
|
|
26
|
+
column2: 'something'
|
|
27
|
+
},
|
|
28
|
+
search: 'maxima >= 12'
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* However, the most simple operation we will support upfront. Everything
|
|
33
|
+
* else can use tooling. We will provide a plugin hook so this can be in
|
|
34
|
+
* doubt tightly integrated into the migrations.
|
|
35
|
+
*/
|
|
36
|
+
await db.get('test', {
|
|
37
|
+
columns: {
|
|
38
|
+
column1: 'maxima',
|
|
39
|
+
column2: 'something'
|
|
40
|
+
},
|
|
41
|
+
search: {
|
|
42
|
+
maxima: 15
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* when doing more then searching, you want to access it in query mode.
|
|
48
|
+
* You will have to write the whole definition by hand. This guarantees
|
|
49
|
+
* that we still understand what is happening (type of operation), but
|
|
50
|
+
* gives ultimate flexibility.
|
|
51
|
+
*
|
|
52
|
+
* The table param is optional, when using for example SQL it will not be
|
|
53
|
+
* needed, databases like mongodb will need it however, so it might be
|
|
54
|
+
* recommended as a best practice to not omit it, depending on how ultimate
|
|
55
|
+
* the decision of the db is yet.
|
|
56
|
+
*
|
|
57
|
+
* Adding LIMITS yourself is possible, but leave this to db-migrate in doubt.
|
|
58
|
+
*/
|
|
59
|
+
await db.get('test', {
|
|
60
|
+
query: 'DISTINCT value1 FROM test' // select will be forcefully prepended so we always know this will only get data
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
exports._meta = {
|
|
65
|
+
version: 2,
|
|
66
|
+
DML: true
|
|
67
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const log = require('db-migrate-shared').log;
|
|
3
|
+
|
|
4
|
+
async function prepare (internals, config) {
|
|
5
|
+
const index = require('../../connect');
|
|
6
|
+
|
|
7
|
+
return index.driver({
|
|
8
|
+
config: config.getCurrent().settings,
|
|
9
|
+
internals: internals
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = async function (internals, config) {
|
|
14
|
+
const driver = await prepare(internals, config);
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const res = await driver.backupGet(internals.argv);
|
|
18
|
+
return internals.onComplete(driver, internals, null, res);
|
|
19
|
+
} catch (err) {
|
|
20
|
+
return internals.onComplete(driver, internals, err);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -8,6 +8,7 @@ const files = {
|
|
|
8
8
|
"create-migration": require('./create-migration.js'),
|
|
9
9
|
"db": require('./db.js'),
|
|
10
10
|
"down": require('./down.js'),
|
|
11
|
+
"dump": require('./dump.js'),
|
|
11
12
|
"fn/plugin": require('./fn/plugin.js'),
|
|
12
13
|
"generated": require('./generated.js'),
|
|
13
14
|
"helper/assert": require('./helper/assert.js'),
|
package/lib/commands/run.js
CHANGED
|
@@ -124,7 +124,6 @@ module.exports = function (internals, isModule) {
|
|
|
124
124
|
internals.argv.config = internals.argv.configFile || _config;
|
|
125
125
|
|
|
126
126
|
if (internals.argv.version) {
|
|
127
|
-
console.log(internals.argv.version);
|
|
128
127
|
console.log(internals.dbm.version);
|
|
129
128
|
process.exit(0);
|
|
130
129
|
}
|
package/package.json
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"programable",
|
|
32
32
|
"api"
|
|
33
33
|
],
|
|
34
|
-
"version": "0.11.
|
|
34
|
+
"version": "0.11.12",
|
|
35
35
|
"engines": {
|
|
36
36
|
"node": ">=8.0.0"
|
|
37
37
|
},
|
|
@@ -76,6 +76,10 @@
|
|
|
76
76
|
"rimraf": "^2.6.2",
|
|
77
77
|
"sinon": "^4.1.2"
|
|
78
78
|
},
|
|
79
|
+
"funding": {
|
|
80
|
+
"type": "opencollective",
|
|
81
|
+
"url": "https://opencollective.com/node-db-migrate"
|
|
82
|
+
},
|
|
79
83
|
"scripts": {
|
|
80
84
|
"prepublishOnly": "node generateLoader.js",
|
|
81
85
|
"pretest": "eslint *.js lib/*.js test/*.js bin/*",
|