diff --git a/CHANGELOG.md b/CHANGELOG.md index ad355682..8a1ea0f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## 10.2.3 + +* Fix `init tables` command not working +* Improve tablesDB resource syncing during `push tables` command + ## 10.2.2 * Fix `logout` command showing duplicate sessions diff --git a/README.md b/README.md index afbc11c5..b63c4990 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using ```sh $ appwrite -v -10.2.2 +10.2.3 ``` ### Install using prebuilt binaries @@ -60,7 +60,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc Once the installation completes, you can verify your install using ``` $ appwrite -v -10.2.2 +10.2.3 ``` ## Getting Started diff --git a/install.ps1 b/install.ps1 index d4876043..e1208ac0 100644 --- a/install.ps1 +++ b/install.ps1 @@ -13,8 +13,8 @@ # You can use "View source" of this page to see the full script. # REPO -$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/10.2.2/appwrite-cli-win-x64.exe" -$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/10.2.2/appwrite-cli-win-arm64.exe" +$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/10.2.3/appwrite-cli-win-x64.exe" +$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/10.2.3/appwrite-cli-win-arm64.exe" $APPWRITE_BINARY_NAME = "appwrite.exe" diff --git a/install.sh b/install.sh index 9f379df7..c018533e 100644 --- a/install.sh +++ b/install.sh @@ -97,7 +97,7 @@ printSuccess() { downloadBinary() { echo "[2/4] Downloading executable for $OS ($ARCH) ..." - GITHUB_LATEST_VERSION="10.2.2" + GITHUB_LATEST_VERSION="10.2.3" GITHUB_FILE="appwrite-cli-${OS}-${ARCH}" GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE" diff --git a/lib/client.js b/lib/client.js index bb565c50..6697bdda 100644 --- a/lib/client.js +++ b/lib/client.js @@ -16,8 +16,8 @@ class Client { 'x-sdk-name': 'Command Line', 'x-sdk-platform': 'console', 'x-sdk-language': 'cli', - 'x-sdk-version': '10.2.2', - 'user-agent' : `AppwriteCLI/10.2.2 (${os.type()} ${os.version()}; ${os.arch()})`, + 'x-sdk-version': '10.2.3', + 'user-agent' : `AppwriteCLI/10.2.3 (${os.type()} ${os.version()}; ${os.arch()})`, 'X-Appwrite-Response-Format' : '1.8.0', }; } diff --git a/lib/commands/init.js b/lib/commands/init.js index 7d59ba03..0f653a19 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -19,6 +19,7 @@ const { questionsCreateBucket, questionsCreateMessagingTopic, questionsCreateCollection, + questionsCreateTable, questionsInitProject, questionsInitProjectAutopull, questionsInitResources, @@ -34,10 +35,11 @@ const initResources = async () => { const actions = { function: initFunction, site: initSite, - collection: initCollection, + table: initTable, bucket: initBucket, team: initTeam, - message: initTopic + message: initTopic, + collection: initCollection } const answers = await inquirer.prompt(questionsInitResources[0]); @@ -160,6 +162,40 @@ const initTeam = async () => { log("Next you can use 'appwrite push team' to deploy the changes."); }; +const initTable = async () => { + const answers = await inquirer.prompt(questionsCreateTable) + const newDatabase = (answers.method ?? '').toLowerCase() !== 'existing'; + + if (!newDatabase) { + answers.databaseId = answers.database; + answers.databaseName = localConfig.getTablesDB(answers.database).name; + } + + const databaseId = answers.databaseId === 'unique()' ? ID.unique() : answers.databaseId; + + if (newDatabase || !localConfig.getTablesDB(answers.databaseId)) { + localConfig.addTablesDB({ + $id: databaseId, + name: answers.databaseName, + enabled: true + }); + } + + localConfig.addTable({ + $id: answers.id === 'unique()' ? ID.unique() : answers.id, + $permissions: [], + databaseId: databaseId, + name: answers.table, + enabled: true, + rowSecurity: answers.rowSecurity.toLowerCase() === 'yes', + columns: [], + indexes: [], + }); + + success("Initialing table"); + log("Next you can use 'appwrite push table' to deploy the changes."); +}; + const initCollection = async () => { const answers = await inquirer.prompt(questionsCreateCollection) const newDatabase = (answers.method ?? '').toLowerCase() !== 'existing'; @@ -557,6 +593,12 @@ init .description("Init a new Appwrite collection") .action(actionRunner(initCollection)); +init + .command("table") + .alias("tables") + .description("Init a new Appwrite table") + .action(actionRunner(initTable)); + init .command("topic") .alias("topics") diff --git a/lib/commands/push.js b/lib/commands/push.js index e18dd26d..ee8c1deb 100644 --- a/lib/commands/push.js +++ b/lib/commands/push.js @@ -837,14 +837,16 @@ const attributesToCreate = async (remoteAttributes, localAttributes, collection, if (!cliConfig.force) { if (deleting.length > 0 && !isIndex) { - console.log(`${chalk.red('-------------------------------------------------------')}`); + console.log(`${chalk.red('------------------------------------------------------')}`); console.log(`${chalk.red('| WARNING: Attribute deletion may cause loss of data |')}`); - console.log(`${chalk.red('-------------------------------------------------------')}`); + console.log(`${chalk.red('------------------------------------------------------')}`); + console.log(); } if (conflicts.length > 0 && !isIndex) { - console.log(`${chalk.red('---------------------------------------------------------')}`); + console.log(`${chalk.red('--------------------------------------------------------')}`); console.log(`${chalk.red('| WARNING: Attribute recreation may cause loss of data |')}`); - console.log(`${chalk.red('---------------------------------------------------------')}`); + console.log(`${chalk.red('--------------------------------------------------------')}`); + console.log(); } if ((await getConfirmation()) !== true) { @@ -1725,9 +1727,10 @@ const checkAndApplyTablesDBChanges = async () => { toDelete.push(remoteDB); changes.push({ id: remoteDB.$id, + action: chalk.red('deleting'), key: 'Database', - remote: chalk.red(`${remoteDB.name} (${remoteDB.$id})`), - local: chalk.green('(deleted locally)') + remote: remoteDB.name, + local: '(deleted locally)' }); } } @@ -1740,9 +1743,10 @@ const checkAndApplyTablesDBChanges = async () => { toCreate.push(localDB); changes.push({ id: localDB.$id, + action: chalk.green('creating'), key: 'Database', - remote: chalk.red('(does not exist)'), - local: chalk.green(`${localDB.name} (${localDB.$id})`) + remote: '(does not exist)', + local: localDB.name }); } else { let hasChanges = false; @@ -1751,9 +1755,10 @@ const checkAndApplyTablesDBChanges = async () => { hasChanges = true; changes.push({ id: localDB.$id, + action: chalk.yellow('updating'), key: 'Name', - remote: chalk.red(remoteDB.name), - local: chalk.green(localDB.name) + remote: remoteDB.name, + local: localDB.name }); } @@ -1761,9 +1766,10 @@ const checkAndApplyTablesDBChanges = async () => { hasChanges = true; changes.push({ id: localDB.$id, - key: 'Enabled?', - remote: chalk.red(remoteDB.enabled), - local: chalk.green(localDB.enabled) + action: chalk.yellow('updating'), + key: 'Enabled', + remote: remoteDB.enabled, + local: localDB.enabled }); } @@ -1774,16 +1780,19 @@ const checkAndApplyTablesDBChanges = async () => { } if (changes.length === 0) { + console.log('No changes found in tablesDB resource'); + console.log(); return { applied: false, resyncNeeded: false }; } - log('Found changes in tablesDB resources:'); + log('Found changes in tablesDB resource:'); drawTable(changes); if (toDelete.length > 0) { - console.log(`${chalk.red('-------------------------------------------------------------------')}`); + console.log(`${chalk.red('------------------------------------------------------------------')}`); console.log(`${chalk.red('| WARNING: Database deletion will also delete all related tables |')}`); - console.log(`${chalk.red('-------------------------------------------------------------------')}`); + console.log(`${chalk.red('------------------------------------------------------------------')}`); + console.log(); } if ((await getConfirmation()) !== true) { @@ -1841,6 +1850,10 @@ const checkAndApplyTablesDBChanges = async () => { } } + if (toDelete.length === 0){ + console.log(); + } + return { applied: true, resyncNeeded: needsResync }; }; @@ -1868,6 +1881,7 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) = localConfig.set('tablesDB', validTablesDBs); success('Configuration resynced successfully.'); + console.log(); } if (cliConfig.all) { diff --git a/lib/parser.js b/lib/parser.js index 6f25b719..0ec2db87 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -122,7 +122,7 @@ const parseError = (err) => { } catch { } - const version = '10.2.2'; + const version = '10.2.3'; const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``; const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud()}`; diff --git a/lib/questions.js b/lib/questions.js index 7bfb84ed..33e68d5a 100644 --- a/lib/questions.js +++ b/lib/questions.js @@ -496,7 +496,73 @@ const questionsCreateCollection = [ { type: "list", name: "documentSecurity", - message: "Enable Document-Security for configuring permissions for individual documents", + message: "Enable document security for configuring permissions for individual documents", + choices: ["No", "Yes"] + } +]; + +const questionsCreateTable = [ + { + type: "list", + name: "method", + message: "What database would you like to use for your table?", + choices: ["New", "Existing"], + when: async () => { + return localConfig.getTablesDBs().length !== 0; + } + }, + { + type: "search-list", + name: "database", + message: "Choose the table database", + choices: async () => { + const databases = localConfig.getTablesDBs(); + + let choices = databases.map((database, idx) => { + return { + name: `${database.name} (${database.$id})`, + value: database.$id + } + }) + + if (choices.length === 0) { + throw new Error("No databases found. Please create one in project console.") + } + + return choices; + }, + when: (answers) => (answers.method ?? '').toLowerCase() === 'existing' + }, + { + type: "input", + name: "databaseName", + message: "What would you like to name your database?", + default: "My Awesome Database", + when: (answers) => (answers.method ?? '').toLowerCase() !== 'existing' + }, + { + type: "input", + name: "databaseId", + message: "What ID would you like to have for your database?", + default: "unique()", + when: (answers) => (answers.method ?? '').toLowerCase() !== 'existing' + }, + { + type: "input", + name: "table", + message: "What would you like to name your table?", + default: "My Awesome Table" + }, + { + type: "input", + name: "id", + message: "What ID would you like to have for your table?", + default: "unique()" + }, + { + type: "list", + name: "rowSecurity", + message: "Enable row security for configuring permissions for individual rows", choices: ["No", "Yes"] } ]; @@ -1001,6 +1067,7 @@ module.exports = { questionsCreateFunctionSelectTemplate, questionsCreateBucket, questionsCreateCollection, + questionsCreateTable, questionsCreateMessagingTopic, questionsPullFunctions, questionsPullFunctionsCode, diff --git a/package.json b/package.json index 6a4b9b50..dd9576b0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "appwrite-cli", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "10.2.2", + "version": "10.2.3", "license": "BSD-3-Clause", "main": "index.js", "bin": { diff --git a/scoop/appwrite.config.json b/scoop/appwrite.config.json index 9472896f..09b14c58 100644 --- a/scoop/appwrite.config.json +++ b/scoop/appwrite.config.json @@ -1,12 +1,12 @@ { "$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json", - "version": "10.2.2", + "version": "10.2.3", "description": "The Appwrite CLI is a command-line application that allows you to interact with Appwrite and perform server-side tasks using your terminal.", "homepage": "https://github.com/appwrite/sdk-for-cli", "license": "BSD-3-Clause", "architecture": { "64bit": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/10.2.2/appwrite-cli-win-x64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/10.2.3/appwrite-cli-win-x64.exe", "bin": [ [ "appwrite-cli-win-x64.exe", @@ -15,7 +15,7 @@ ] }, "arm64": { - "url": "https://github.com/appwrite/sdk-for-cli/releases/download/10.2.2/appwrite-cli-win-arm64.exe", + "url": "https://github.com/appwrite/sdk-for-cli/releases/download/10.2.3/appwrite-cli-win-arm64.exe", "bin": [ [ "appwrite-cli-win-arm64.exe",