Skip to content

Commit

Permalink
Make sure to deploy collection from the correct database
Browse files Browse the repository at this point in the history
  • Loading branch information
stnguyen90 committed Apr 7, 2023
1 parent bb6c347 commit ec696eb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
31 changes: 14 additions & 17 deletions templates/cli/lib/commands/deploy.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -428,30 +428,27 @@ const createAttribute = async (databaseId, collectionId, attribute) => {
const deployCollection = async ({ all, yes } = {}) => {
let response = {};

let collectionIds = [];
const configCollections = localConfig.getCollections();
const collections = [];

if (all) {
if (configCollections.length === 0) {
if (configCollections.size === 0) {
throw new Error("No collections found in the current directory. Run `{{ language.params.executableName }} init collection` to fetch all your collections.");
}
collectionIds.push(...configCollections.map((c) => c.$id));
}

if (collectionIds.length <= 0) {
let answers = await inquirer.prompt(questionsDeployCollections[0])
collectionIds.push(...answers.collections);
}

let collections = [];

for (const collectionId of collectionIds) {
const idCollections = configCollections.filter((c) => c.$id === collectionId);
collections.push(...idCollections);
collections.push(...localConfig.getCollections());
} else {
const answers = await inquirer.prompt(questionsDeployCollections[0])
const configCollections = new Map();
localConfig.getCollections().forEach((c) => {
configCollections.set(`${c['databaseId']}|${c['$id']}`, c);
});
answers.collections.forEach((a) => {
const collection = configCollections.get(a);
collections.push(collection);
})
}

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

let databaseId;

Expand Down
4 changes: 2 additions & 2 deletions templates/cli/lib/questions.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ const questionsDeployCollections = [
}
let choices = collections.map((collection, idx) => {
return {
name: `${collection.name} (${collection['$id']})`,
value: collection.$id
name: `${collection.name} (${collection['databaseId']} - ${collection['$id']})`,
value: `${collection['databaseId']}|${collection['$id']}`
}
})
return choices;
Expand Down

0 comments on commit ec696eb

Please sign in to comment.