Skip to content

Commit d801949

Browse files
committed
fix(cli): Check collection basic settings + bug fix
1 parent 15db874 commit d801949

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

templates/cli/lib/commands/push.js.twig

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ const chalk = require('chalk');
22
const inquirer = require("inquirer");
33
const JSONbig = require("json-bigint")({ storeAsString: false });
44
const { Command } = require("commander");
5-
const { localConfig, globalConfig, KeysAttributes, KeysFunction, whitelistKeys, KeysTopics, KeysStorage, KeysTeams, } = require("../config");
5+
const { localConfig, globalConfig, KeysAttributes, KeysFunction, whitelistKeys, KeysTopics, KeysStorage, KeysTeams, KeysCollection } = require("../config");
66
const { Spinner, SPINNER_ARC, SPINNER_DOTS } = require('../spinner');
77
const { paginate } = require('../paginate');
8-
const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionPushChanges, questionPushChangesConfirmation, questionsPushMessagingTopics, questionsPushResources } = require("../questions");
8+
const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionPushChanges, questionPushChangesFix, questionsPushMessagingTopics, questionsPushResources } = require("../questions");
99
const { cliConfig, actionRunner, success, warn, log, hint, error, commandDescriptions, drawTable } = require("../parser");
1010
const { proxyListRules } = require('./proxy');
1111
const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsGetDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions');
@@ -341,42 +341,50 @@ const awaitPools = {
341341
}
342342

343343
const getConfirmation = async () => {
344-
if (!cliConfig.force) {
345-
async function fixConfirmation() {
346-
const answers = await inquirer.prompt(questionPushChangesConfirmation);
347-
if (answers.changes !== 'YES' && answers.changes !== 'NO') {
348-
return await fixConfirmation();
349-
}
350-
351-
return answers.changes;
352-
}
344+
if (cliConfig.force) {
345+
return true;
346+
}
353347

354-
let answers = await inquirer.prompt(questionPushChanges);
348+
async function fixConfirmation() {
349+
const answers = await inquirer.prompt(questionPushChangesFix);
355350
if (answers.changes !== 'YES' && answers.changes !== 'NO') {
356-
answers.changes = await fixConfirmation();
351+
return await fixConfirmation();
357352
}
358353

359-
if (answers.changes === 'YES') {
360-
return true;
361-
}
354+
return answers.changes;
355+
}
356+
357+
let answers = await inquirer.prompt(questionPushChanges);
358+
359+
if (answers.changes !== 'YES' && answers.changes !== 'NO') {
360+
answers.changes = await fixConfirmation();
361+
}
362362

363-
warn('Skipping push action. Changes were not applied.');
364-
return false;
363+
if (answers.changes === 'YES') {
364+
return true;
365365
}
366366

367-
return true;
367+
warn('Skipping push action. Changes were not applied.');
368+
return false;
369+
368370
};
369371

370-
const approveChanges = async (resource, resourceGetFunction, keys, resourceName, resourcePlural, skipKeys = []) => {
372+
const approveChanges = async (resource, resourceGetFunction, keys, resourceName, resourcePlural, skipKeys = [], secondId = '', secondResourceName = '') => {
371373
log('Checking for changes ...');
372374
const changes = [];
373375

374376
await Promise.all(resource.map(async (localResource) => {
375377
try {
376-
const remoteResource = await resourceGetFunction({
378+
const options = {
377379
[resourceName]: localResource['$id'],
378380
parseOutput: false,
379-
});
381+
};
382+
383+
if (secondId !== '' && secondResourceName !== '') {
384+
options[secondResourceName] = localResource[secondId]
385+
}
386+
387+
const remoteResource = await resourceGetFunction(options);
380388

381389
for (let [key, value] of Object.entries(whitelistKeys(remoteResource, keys))) {
382390
if (skipKeys.includes(key)) {
@@ -1310,8 +1318,6 @@ const pushCollection = async ({ returnOnZero, attempts } = { returnOnZero: false
13101318

13111319
const databases = Array.from(new Set(collections.map(collection => collection['databaseId'])));
13121320

1313-
log('Checking for changes ...');
1314-
13151321
// Parallel db actions
13161322
await Promise.all(databases.map(async (databaseId) => {
13171323
const localDatabase = localConfig.getDatabase(databaseId);
@@ -1342,6 +1348,10 @@ const pushCollection = async ({ returnOnZero, attempts } = { returnOnZero: false
13421348
}
13431349
}));
13441350

1351+
1352+
if (!(await approveChanges(collections, databasesGetCollection, KeysCollection, 'collectionId', 'collections', ['attributes', 'indexes'], 'databaseId', 'databaseId',))) {
1353+
return;
1354+
}
13451355
// Parallel collection actions
13461356
await Promise.all(collections.map(async (collection) => {
13471357
try {

templates/cli/lib/config.js.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,5 +618,6 @@ module.exports = {
618618
KeysTopics,
619619
KeysStorage,
620620
KeysTeams,
621+
KeysCollection,
621622
whitelistKeys
622623
};

0 commit comments

Comments
 (0)