@13w/miri 1.1.7 → 1.1.8
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/Readme.md +53 -0
- package/dist/cli.js +7 -7
- package/package.json +1 -1
package/Readme.md
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#### Migration manager
|
|
2
|
+
### Migrations folder structure
|
|
3
|
+
|
|
4
|
+
* migrations/
|
|
5
|
+
* init/
|
|
6
|
+
* 01-create-collections.js
|
|
7
|
+
```javascript
|
|
8
|
+
db.createCollection('users');
|
|
9
|
+
db.createCollection('goods');
|
|
10
|
+
```
|
|
11
|
+
* 02-create-default-users.js
|
|
12
|
+
```javascript
|
|
13
|
+
db.users.insertOne({firstName: 'foo', lastName: 'zoo'});
|
|
14
|
+
db.users.insertOne({firstName: 'baz', lastName: 'poo'});
|
|
15
|
+
```
|
|
16
|
+
* 03-create-default-goods.js
|
|
17
|
+
```javascript
|
|
18
|
+
db.goods.insertOne({name: 'lemon'});
|
|
19
|
+
db.goods.insertOne({name: 'orange'});
|
|
20
|
+
```
|
|
21
|
+
* indexes/
|
|
22
|
+
* users.json
|
|
23
|
+
```json
|
|
24
|
+
[
|
|
25
|
+
{name: 1}
|
|
26
|
+
]
|
|
27
|
+
```
|
|
28
|
+
* goods.json
|
|
29
|
+
```json
|
|
30
|
+
[
|
|
31
|
+
[{name: 1}, { unique: true }]
|
|
32
|
+
]
|
|
33
|
+
```
|
|
34
|
+
* version-1/
|
|
35
|
+
* 01-02-2023-add-full-name.js
|
|
36
|
+
```javascript
|
|
37
|
+
export const test = () => db.users.countDocuments({ fullName: { $exists: false } });
|
|
38
|
+
export const up = () => db.users.updateMany({ fullName: { $exists: false } }, [{ $set: { fullName: { $concat: ['$firstName', ' ', '$lastName'] } } }])
|
|
39
|
+
export const down = () => db.users.updateMany({}, {$unset: { fullName: 1 }})
|
|
40
|
+
```
|
|
41
|
+
* 04-05-2023-add-user-age.js
|
|
42
|
+
```javascript
|
|
43
|
+
export const test = () => db.users.countDocuments({ age: { $exists: false } });
|
|
44
|
+
export const up => () => db.users.updateMany({ age: { $exists: false } }, {$set: { age: 135 }})
|
|
45
|
+
export const down = () => db.users.updateMany({}, {$unset: { age: 1 }})
|
|
46
|
+
```
|
|
47
|
+
* version-2/
|
|
48
|
+
* 05-08-2023-add-price-to-goods.js
|
|
49
|
+
```javascript
|
|
50
|
+
export const test = () => db.goods.countDocuments({ price: { $exists: false } });
|
|
51
|
+
export const up => () => db.goods.updateMany({ price: { $exists: false } }, { $set: {price: 12.24} })
|
|
52
|
+
export const down = () => db.goods.updateMany({}, {$unset: { price: 1 }})
|
|
53
|
+
```
|
package/dist/cli.js
CHANGED
|
@@ -58,13 +58,13 @@ initProgram.command('status')
|
|
|
58
58
|
.action(() => {
|
|
59
59
|
console.log('There should be init status....');
|
|
60
60
|
});
|
|
61
|
-
const indexesProgram = program.command('indexes')
|
|
62
|
-
|
|
61
|
+
const indexesProgram = program.command('indexes');
|
|
62
|
+
const indexStatusProgram = indexesProgram.command('status')
|
|
63
63
|
.argument('[collection]', 'MongoDB Collection name')
|
|
64
64
|
.option('-q --quiet', 'Show only changes', false)
|
|
65
65
|
.action(async () => {
|
|
66
|
-
const collection =
|
|
67
|
-
const { quiet } =
|
|
66
|
+
const collection = indexStatusProgram.args[0];
|
|
67
|
+
const { quiet } = indexStatusProgram.opts();
|
|
68
68
|
const miri = await getMiri();
|
|
69
69
|
const structure = await miri.indexesDiff(collection);
|
|
70
70
|
await miri[Symbol.asyncDispose]();
|
|
@@ -93,12 +93,12 @@ const indexesProgram = program.command('indexes')
|
|
|
93
93
|
console.groupEnd();
|
|
94
94
|
}
|
|
95
95
|
});
|
|
96
|
-
indexesProgram.command('sync')
|
|
97
|
-
|
|
96
|
+
const indexSyncProgram = indexesProgram.command('sync');
|
|
97
|
+
indexSyncProgram.option('<collection>', 'MongoDB Collection name', '')
|
|
98
98
|
.action(async () => {
|
|
99
99
|
const miri = await getMiri();
|
|
100
100
|
let group = '';
|
|
101
|
-
console.group('Starting synchronisation...',
|
|
101
|
+
console.group('Starting synchronisation...', indexSyncProgram.opts());
|
|
102
102
|
for await (const { collection, status, name, error } of miri.indexesSync()) {
|
|
103
103
|
if (group !== collection) {
|
|
104
104
|
if (group) {
|