Skip to content

Commit 31a484f

Browse files
committed
Make sure to deploy collection from the correct database
1 parent bb6c347 commit 31a484f

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -428,30 +428,27 @@ const createAttribute = async (databaseId, collectionId, attribute) => {
428428
const deployCollection = async ({ all, yes } = {}) => {
429429
let response = {};
430430

431-
let collectionIds = [];
432-
const configCollections = localConfig.getCollections();
431+
const collections = [];
433432

434433
if (all) {
435-
if (configCollections.length === 0) {
434+
if (localConfig.getCollections().length === 0) {
436435
throw new Error("No collections found in the current directory. Run `{{ language.params.executableName }} init collection` to fetch all your collections.");
437436
}
438-
collectionIds.push(...configCollections.map((c) => c.$id));
439-
}
440-
441-
if (collectionIds.length <= 0) {
442-
let answers = await inquirer.prompt(questionsDeployCollections[0])
443-
collectionIds.push(...answers.collections);
444-
}
445-
446-
let collections = [];
447-
448-
for (const collectionId of collectionIds) {
449-
const idCollections = configCollections.filter((c) => c.$id === collectionId);
450-
collections.push(...idCollections);
437+
collections.push(...localConfig.getCollections());
438+
} else {
439+
const answers = await inquirer.prompt(questionsDeployCollections[0])
440+
const configCollections = new Map();
441+
localConfig.getCollections().forEach((c) => {
442+
configCollections.set(`${c['databaseId']}|${c['$id']}`, c);
443+
});
444+
answers.collections.forEach((a) => {
445+
const collection = configCollections.get(a);
446+
collections.push(collection);
447+
})
451448
}
452449

453450
for (let collection of collections) {
454-
log(`Deploying collection ${collection.name} ( ${collection['$id']} )`)
451+
log(`Deploying collection ${collection.name} ( ${collection['databaseId']} - ${collection['$id']} )`)
455452

456453
let databaseId;
457454

templates/cli/lib/questions.js.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ const questionsDeployCollections = [
271271
}
272272
let choices = collections.map((collection, idx) => {
273273
return {
274-
name: `${collection.name} (${collection['$id']})`,
275-
value: collection.$id
274+
name: `${collection.name} (${collection['databaseId']} - ${collection['$id']})`,
275+
value: `${collection['databaseId']}|${collection['$id']}`
276276
}
277277
})
278278
return choices;

0 commit comments

Comments
 (0)