Skip to content

Commit 1ea90ef

Browse files
authored
Merge pull request #211 from appwrite/dev
feat: Command Line SDK update for version 10.2.3
2 parents 07e94c7 + 66ab7d3 commit 1ea90ef

File tree

11 files changed

+159
-31
lines changed

11 files changed

+159
-31
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## 10.2.3
4+
5+
* Fix `init tables` command not working
6+
* Improve tablesDB resource syncing during `push tables` command
7+
38
## 10.2.2
49

510
* Fix `logout` command showing duplicate sessions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using
2929

3030
```sh
3131
$ appwrite -v
32-
10.2.2
32+
10.2.3
3333
```
3434

3535
### Install using prebuilt binaries
@@ -60,7 +60,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc
6060
Once the installation completes, you can verify your install using
6161
```
6262
$ appwrite -v
63-
10.2.2
63+
10.2.3
6464
```
6565

6666
## Getting Started

install.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# You can use "View source" of this page to see the full script.
1414

1515
# REPO
16-
$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/10.2.2/appwrite-cli-win-x64.exe"
17-
$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/10.2.2/appwrite-cli-win-arm64.exe"
16+
$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/10.2.3/appwrite-cli-win-x64.exe"
17+
$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/10.2.3/appwrite-cli-win-arm64.exe"
1818

1919
$APPWRITE_BINARY_NAME = "appwrite.exe"
2020

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ printSuccess() {
9797
downloadBinary() {
9898
echo "[2/4] Downloading executable for $OS ($ARCH) ..."
9999

100-
GITHUB_LATEST_VERSION="10.2.2"
100+
GITHUB_LATEST_VERSION="10.2.3"
101101
GITHUB_FILE="appwrite-cli-${OS}-${ARCH}"
102102
GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE"
103103

lib/client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class Client {
1616
'x-sdk-name': 'Command Line',
1717
'x-sdk-platform': 'console',
1818
'x-sdk-language': 'cli',
19-
'x-sdk-version': '10.2.2',
20-
'user-agent' : `AppwriteCLI/10.2.2 (${os.type()} ${os.version()}; ${os.arch()})`,
19+
'x-sdk-version': '10.2.3',
20+
'user-agent' : `AppwriteCLI/10.2.3 (${os.type()} ${os.version()}; ${os.arch()})`,
2121
'X-Appwrite-Response-Format' : '1.8.0',
2222
};
2323
}

lib/commands/init.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const {
1919
questionsCreateBucket,
2020
questionsCreateMessagingTopic,
2121
questionsCreateCollection,
22+
questionsCreateTable,
2223
questionsInitProject,
2324
questionsInitProjectAutopull,
2425
questionsInitResources,
@@ -34,10 +35,11 @@ const initResources = async () => {
3435
const actions = {
3536
function: initFunction,
3637
site: initSite,
37-
collection: initCollection,
38+
table: initTable,
3839
bucket: initBucket,
3940
team: initTeam,
40-
message: initTopic
41+
message: initTopic,
42+
collection: initCollection
4143
}
4244

4345
const answers = await inquirer.prompt(questionsInitResources[0]);
@@ -160,6 +162,40 @@ const initTeam = async () => {
160162
log("Next you can use 'appwrite push team' to deploy the changes.");
161163
};
162164

165+
const initTable = async () => {
166+
const answers = await inquirer.prompt(questionsCreateTable)
167+
const newDatabase = (answers.method ?? '').toLowerCase() !== 'existing';
168+
169+
if (!newDatabase) {
170+
answers.databaseId = answers.database;
171+
answers.databaseName = localConfig.getTablesDB(answers.database).name;
172+
}
173+
174+
const databaseId = answers.databaseId === 'unique()' ? ID.unique() : answers.databaseId;
175+
176+
if (newDatabase || !localConfig.getTablesDB(answers.databaseId)) {
177+
localConfig.addTablesDB({
178+
$id: databaseId,
179+
name: answers.databaseName,
180+
enabled: true
181+
});
182+
}
183+
184+
localConfig.addTable({
185+
$id: answers.id === 'unique()' ? ID.unique() : answers.id,
186+
$permissions: [],
187+
databaseId: databaseId,
188+
name: answers.table,
189+
enabled: true,
190+
rowSecurity: answers.rowSecurity.toLowerCase() === 'yes',
191+
columns: [],
192+
indexes: [],
193+
});
194+
195+
success("Initialing table");
196+
log("Next you can use 'appwrite push table' to deploy the changes.");
197+
};
198+
163199
const initCollection = async () => {
164200
const answers = await inquirer.prompt(questionsCreateCollection)
165201
const newDatabase = (answers.method ?? '').toLowerCase() !== 'existing';
@@ -557,6 +593,12 @@ init
557593
.description("Init a new Appwrite collection")
558594
.action(actionRunner(initCollection));
559595

596+
init
597+
.command("table")
598+
.alias("tables")
599+
.description("Init a new Appwrite table")
600+
.action(actionRunner(initTable));
601+
560602
init
561603
.command("topic")
562604
.alias("topics")

lib/commands/push.js

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -837,14 +837,16 @@ const attributesToCreate = async (remoteAttributes, localAttributes, collection,
837837

838838
if (!cliConfig.force) {
839839
if (deleting.length > 0 && !isIndex) {
840-
console.log(`${chalk.red('-------------------------------------------------------')}`);
840+
console.log(`${chalk.red('------------------------------------------------------')}`);
841841
console.log(`${chalk.red('| WARNING: Attribute deletion may cause loss of data |')}`);
842-
console.log(`${chalk.red('-------------------------------------------------------')}`);
842+
console.log(`${chalk.red('------------------------------------------------------')}`);
843+
console.log();
843844
}
844845
if (conflicts.length > 0 && !isIndex) {
845-
console.log(`${chalk.red('---------------------------------------------------------')}`);
846+
console.log(`${chalk.red('--------------------------------------------------------')}`);
846847
console.log(`${chalk.red('| WARNING: Attribute recreation may cause loss of data |')}`);
847-
console.log(`${chalk.red('---------------------------------------------------------')}`);
848+
console.log(`${chalk.red('--------------------------------------------------------')}`);
849+
console.log();
848850
}
849851

850852
if ((await getConfirmation()) !== true) {
@@ -1725,9 +1727,10 @@ const checkAndApplyTablesDBChanges = async () => {
17251727
toDelete.push(remoteDB);
17261728
changes.push({
17271729
id: remoteDB.$id,
1730+
action: chalk.red('deleting'),
17281731
key: 'Database',
1729-
remote: chalk.red(`${remoteDB.name} (${remoteDB.$id})`),
1730-
local: chalk.green('(deleted locally)')
1732+
remote: remoteDB.name,
1733+
local: '(deleted locally)'
17311734
});
17321735
}
17331736
}
@@ -1740,9 +1743,10 @@ const checkAndApplyTablesDBChanges = async () => {
17401743
toCreate.push(localDB);
17411744
changes.push({
17421745
id: localDB.$id,
1746+
action: chalk.green('creating'),
17431747
key: 'Database',
1744-
remote: chalk.red('(does not exist)'),
1745-
local: chalk.green(`${localDB.name} (${localDB.$id})`)
1748+
remote: '(does not exist)',
1749+
local: localDB.name
17461750
});
17471751
} else {
17481752
let hasChanges = false;
@@ -1751,19 +1755,21 @@ const checkAndApplyTablesDBChanges = async () => {
17511755
hasChanges = true;
17521756
changes.push({
17531757
id: localDB.$id,
1758+
action: chalk.yellow('updating'),
17541759
key: 'Name',
1755-
remote: chalk.red(remoteDB.name),
1756-
local: chalk.green(localDB.name)
1760+
remote: remoteDB.name,
1761+
local: localDB.name
17571762
});
17581763
}
17591764

17601765
if (remoteDB.enabled !== localDB.enabled) {
17611766
hasChanges = true;
17621767
changes.push({
17631768
id: localDB.$id,
1764-
key: 'Enabled?',
1765-
remote: chalk.red(remoteDB.enabled),
1766-
local: chalk.green(localDB.enabled)
1769+
action: chalk.yellow('updating'),
1770+
key: 'Enabled',
1771+
remote: remoteDB.enabled,
1772+
local: localDB.enabled
17671773
});
17681774
}
17691775

@@ -1774,16 +1780,19 @@ const checkAndApplyTablesDBChanges = async () => {
17741780
}
17751781

17761782
if (changes.length === 0) {
1783+
console.log('No changes found in tablesDB resource');
1784+
console.log();
17771785
return { applied: false, resyncNeeded: false };
17781786
}
17791787

1780-
log('Found changes in tablesDB resources:');
1788+
log('Found changes in tablesDB resource:');
17811789
drawTable(changes);
17821790

17831791
if (toDelete.length > 0) {
1784-
console.log(`${chalk.red('-------------------------------------------------------------------')}`);
1792+
console.log(`${chalk.red('------------------------------------------------------------------')}`);
17851793
console.log(`${chalk.red('| WARNING: Database deletion will also delete all related tables |')}`);
1786-
console.log(`${chalk.red('-------------------------------------------------------------------')}`);
1794+
console.log(`${chalk.red('------------------------------------------------------------------')}`);
1795+
console.log();
17871796
}
17881797

17891798
if ((await getConfirmation()) !== true) {
@@ -1841,6 +1850,10 @@ const checkAndApplyTablesDBChanges = async () => {
18411850
}
18421851
}
18431852

1853+
if (toDelete.length === 0){
1854+
console.log();
1855+
}
1856+
18441857
return { applied: true, resyncNeeded: needsResync };
18451858
};
18461859

@@ -1868,6 +1881,7 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
18681881
localConfig.set('tablesDB', validTablesDBs);
18691882

18701883
success('Configuration resynced successfully.');
1884+
console.log();
18711885
}
18721886

18731887
if (cliConfig.all) {

lib/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const parseError = (err) => {
122122
} catch {
123123
}
124124

125-
const version = '10.2.2';
125+
const version = '10.2.3';
126126
const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``;
127127
const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud()}`;
128128

lib/questions.js

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,73 @@ const questionsCreateCollection = [
496496
{
497497
type: "list",
498498
name: "documentSecurity",
499-
message: "Enable Document-Security for configuring permissions for individual documents",
499+
message: "Enable document security for configuring permissions for individual documents",
500+
choices: ["No", "Yes"]
501+
}
502+
];
503+
504+
const questionsCreateTable = [
505+
{
506+
type: "list",
507+
name: "method",
508+
message: "What database would you like to use for your table?",
509+
choices: ["New", "Existing"],
510+
when: async () => {
511+
return localConfig.getTablesDBs().length !== 0;
512+
}
513+
},
514+
{
515+
type: "search-list",
516+
name: "database",
517+
message: "Choose the table database",
518+
choices: async () => {
519+
const databases = localConfig.getTablesDBs();
520+
521+
let choices = databases.map((database, idx) => {
522+
return {
523+
name: `${database.name} (${database.$id})`,
524+
value: database.$id
525+
}
526+
})
527+
528+
if (choices.length === 0) {
529+
throw new Error("No databases found. Please create one in project console.")
530+
}
531+
532+
return choices;
533+
},
534+
when: (answers) => (answers.method ?? '').toLowerCase() === 'existing'
535+
},
536+
{
537+
type: "input",
538+
name: "databaseName",
539+
message: "What would you like to name your database?",
540+
default: "My Awesome Database",
541+
when: (answers) => (answers.method ?? '').toLowerCase() !== 'existing'
542+
},
543+
{
544+
type: "input",
545+
name: "databaseId",
546+
message: "What ID would you like to have for your database?",
547+
default: "unique()",
548+
when: (answers) => (answers.method ?? '').toLowerCase() !== 'existing'
549+
},
550+
{
551+
type: "input",
552+
name: "table",
553+
message: "What would you like to name your table?",
554+
default: "My Awesome Table"
555+
},
556+
{
557+
type: "input",
558+
name: "id",
559+
message: "What ID would you like to have for your table?",
560+
default: "unique()"
561+
},
562+
{
563+
type: "list",
564+
name: "rowSecurity",
565+
message: "Enable row security for configuring permissions for individual rows",
500566
choices: ["No", "Yes"]
501567
}
502568
];
@@ -1001,6 +1067,7 @@ module.exports = {
10011067
questionsCreateFunctionSelectTemplate,
10021068
questionsCreateBucket,
10031069
questionsCreateCollection,
1070+
questionsCreateTable,
10041071
questionsCreateMessagingTopic,
10051072
questionsPullFunctions,
10061073
questionsPullFunctionsCode,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "appwrite-cli",
33
"homepage": "https://appwrite.io/support",
44
"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",
5-
"version": "10.2.2",
5+
"version": "10.2.3",
66
"license": "BSD-3-Clause",
77
"main": "index.js",
88
"bin": {

0 commit comments

Comments
 (0)