@13w/miri 1.1.11 → 1.1.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/dist/cli.js +48 -26
- package/dist/miri.js +18 -11
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -76,9 +76,13 @@ const getMiri = async () => {
|
|
|
76
76
|
localMigrations: config.migrations,
|
|
77
77
|
});
|
|
78
78
|
};
|
|
79
|
-
const status = async (remote = false, group) => {
|
|
79
|
+
const status = async (remote = false, group, all = false) => {
|
|
80
80
|
const miri = await getMiri();
|
|
81
81
|
const patches = await miri.stat(remote, group);
|
|
82
|
+
if (!group && all) {
|
|
83
|
+
const initPatches = await miri.stat(remote, 'init');
|
|
84
|
+
patches.unshift(...initPatches);
|
|
85
|
+
}
|
|
82
86
|
await miri[Symbol.asyncDispose]();
|
|
83
87
|
if (!patches.length) {
|
|
84
88
|
return;
|
|
@@ -104,15 +108,53 @@ const status = async (remote = false, group) => {
|
|
|
104
108
|
}
|
|
105
109
|
table.printTable();
|
|
106
110
|
};
|
|
111
|
+
const syncIndexes = async (miri, coll) => {
|
|
112
|
+
let group = '';
|
|
113
|
+
console.group('Starting synchronisation...');
|
|
114
|
+
for await (const { collection, status, name, error } of miri.indexesSync(coll)) {
|
|
115
|
+
if (group !== collection) {
|
|
116
|
+
if (group) {
|
|
117
|
+
console.log('Done');
|
|
118
|
+
console.groupEnd();
|
|
119
|
+
}
|
|
120
|
+
group = collection;
|
|
121
|
+
console.group(`Collection: ${collection}...`);
|
|
122
|
+
}
|
|
123
|
+
if (status === IndexStatus.Applied) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
console[error ? 'group' : 'log'](`${status === IndexStatus.New ? 'Creating' : 'Removing'} index ${name}... ${error ? 'failed' : 'done'}`);
|
|
127
|
+
if (error) {
|
|
128
|
+
console.log(colors.red(error.message));
|
|
129
|
+
console.groupEnd();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
console.groupEnd();
|
|
133
|
+
};
|
|
107
134
|
program.command('status')
|
|
135
|
+
.option('--all', 'show all applied patches')
|
|
108
136
|
.description('Displays list of applied migrations')
|
|
109
|
-
.action(() => status(true));
|
|
137
|
+
.action(({ all }) => status(true, void 0, all));
|
|
138
|
+
program.command('sync')
|
|
139
|
+
.description('Applies all available patches from migrations folder')
|
|
140
|
+
.option('--degraded', 'Re-apply patches on degraded migrations')
|
|
141
|
+
.option('--all', 'Re-apply all patches')
|
|
142
|
+
.action(async (opts) => {
|
|
143
|
+
const miri = await getMiri();
|
|
144
|
+
await miri.init({ force: opts.all });
|
|
145
|
+
await syncIndexes(miri);
|
|
146
|
+
await miri.sync(opts);
|
|
147
|
+
await miri[Symbol.asyncDispose]();
|
|
148
|
+
});
|
|
110
149
|
const initProgram = program.command('init')
|
|
111
150
|
.description('Manage initial scripts');
|
|
112
151
|
initProgram.command('apply')
|
|
113
|
-
.
|
|
152
|
+
.argument('[patch]', 'patch name')
|
|
153
|
+
.option('--no-exec', 'Don\' execute patch, just set as done')
|
|
154
|
+
.option('--force', 'Force apply patch')
|
|
155
|
+
.action(async (opts, patch) => {
|
|
114
156
|
const miri = await getMiri();
|
|
115
|
-
await miri.init();
|
|
157
|
+
await miri.init(opts, patch);
|
|
116
158
|
await miri[Symbol.asyncDispose]();
|
|
117
159
|
});
|
|
118
160
|
initProgram.command('status')
|
|
@@ -153,29 +195,9 @@ indexesProgram.command('status')
|
|
|
153
195
|
});
|
|
154
196
|
const indexSyncProgram = indexesProgram.command('sync');
|
|
155
197
|
indexSyncProgram.argument('[collection]', 'MongoDB Collection name', '')
|
|
156
|
-
.action(async (
|
|
198
|
+
.action(async (collection) => {
|
|
157
199
|
const miri = await getMiri();
|
|
158
|
-
|
|
159
|
-
console.group('Starting synchronisation...');
|
|
160
|
-
for await (const { collection, status, name, error } of miri.indexesSync(coll)) {
|
|
161
|
-
if (group !== collection) {
|
|
162
|
-
if (group) {
|
|
163
|
-
console.log('Done');
|
|
164
|
-
console.groupEnd();
|
|
165
|
-
}
|
|
166
|
-
group = collection;
|
|
167
|
-
console.group(`Collection: ${collection}...`);
|
|
168
|
-
}
|
|
169
|
-
if (status === IndexStatus.Applied) {
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
console[error ? 'group' : 'log'](`${status === IndexStatus.New ? 'Creating' : 'Removing'} index ${name}... ${error ? 'failed' : 'done'}`);
|
|
173
|
-
if (error) {
|
|
174
|
-
console.log(colors.red(error.message));
|
|
175
|
-
console.groupEnd();
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
console.groupEnd();
|
|
200
|
+
await syncIndexes(miri, collection);
|
|
179
201
|
await miri[Symbol.asyncDispose]();
|
|
180
202
|
});
|
|
181
203
|
const patchProgram = program.command('patch')
|
package/dist/miri.js
CHANGED
|
@@ -276,9 +276,9 @@ export default class Migrator {
|
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
-
async init() {
|
|
280
|
-
const localInits = await this.getLocalPatches(true, 'init');
|
|
281
|
-
const remoteInits = await this.getRemotePatches('init');
|
|
279
|
+
async init({ noExec = false, force = false } = {}, patch) {
|
|
280
|
+
const localInits = await this.getLocalPatches(true, 'init', patch);
|
|
281
|
+
const remoteInits = await this.getRemotePatches('init', patch);
|
|
282
282
|
if (!localInits.length) {
|
|
283
283
|
console.log('Nothing to apply');
|
|
284
284
|
return;
|
|
@@ -287,18 +287,25 @@ export default class Migrator {
|
|
|
287
287
|
for (const patch of localInits) {
|
|
288
288
|
console.group(`Testing ${patch.name}...`);
|
|
289
289
|
const remoteInit = remoteInits.find(({ group, name }) => patch.group === group && patch.name === name);
|
|
290
|
-
if (remoteInit) {
|
|
290
|
+
if (!force && remoteInit) {
|
|
291
291
|
console.log('skip');
|
|
292
292
|
console.groupEnd();
|
|
293
293
|
continue;
|
|
294
294
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}
|
|
295
|
+
if (force || !noExec) {
|
|
296
|
+
console.log('applying');
|
|
297
|
+
await this.applyPatchContent({ body: patch.raw, hash: '' }, `${patch.group}/${patch.name}`, false);
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
console.log('set as done');
|
|
301
|
+
}
|
|
302
|
+
if (!remoteInit) {
|
|
303
|
+
await this.#collection.insertOne({
|
|
304
|
+
group: patch.group,
|
|
305
|
+
name: patch.name,
|
|
306
|
+
content: {},
|
|
307
|
+
});
|
|
308
|
+
}
|
|
302
309
|
console.groupEnd();
|
|
303
310
|
}
|
|
304
311
|
console.groupEnd();
|