Skip to content

Commit 8f410f7

Browse files
authored
Merge pull request #1184 from appwrite/fix-push-attributes
fix push columns in tablesdb cli
2 parents e988d73 + 83e077d commit 8f410f7

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

example.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function getSSLPage($url) {
3939

4040
// Leave the platform you want uncommented
4141
// $platform = 'client';
42-
$platform = 'server';
42+
$platform = 'console';
4343
// $platform = 'server';
4444

4545
$version = '1.8.x';

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const { globalConfig, localConfig } = require("../config");
66
const { actionRunner, success, parseBool, commandDescriptions, error, parse, hint, log, drawTable, cliConfig } = require("../parser");
77
const ID = require("../id");
88
{% if sdk.test != "true" %}
9-
const { questionsLogin, questionsLogout, questionsListFactors, questionsMfaChallenge } = require("../questions");
10-
const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } = require("./account");
9+
const { questionsLogin, questionsLogout, questionsListFactors, questionsMFAChallenge } = require("../questions");
10+
const { accountUpdateMFAChallenge, accountCreateMFAChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } = require("./account");
1111

1212
const DEFAULT_ENDPOINT = '{{ spec.endpoint }}';
1313

@@ -72,15 +72,15 @@ const loginCommand = async ({ email, password, endpoint, mfa, code }) => {
7272
if (error.response === 'user_more_factors_required') {
7373
const { factor } = mfa ? { factor: mfa } : await inquirer.prompt(questionsListFactors);
7474

75-
const challenge = await accountCreateMfaChallenge({
75+
const challenge = await accountCreateMFAChallenge({
7676
factor,
7777
parseOutput: false,
7878
sdk: client
7979
});
8080

81-
const { otp } = code ? { otp: code } : await inquirer.prompt(questionsMfaChallenge);
81+
const { otp } = code ? { otp: code } : await inquirer.prompt(questionsMFAChallenge);
8282

83-
await accountUpdateMfaChallenge({
83+
await accountUpdateMFAChallenge({
8484
challengeId: challenge.$id,
8585
otp,
8686
parseOutput: false,

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,25 @@ const createAttributes = async (attributes, collection) => {
918918

919919
success(`Created ${attributes.length} attributes`);
920920
}
921+
const createColumns = async (columns, table) => {
922+
for (let column of columns) {
923+
if (column.side !== 'child') {
924+
await createAttribute(table['databaseId'], table['$id'], column);
925+
}
926+
}
927+
928+
const result = await awaitPools.expectAttributes(
929+
table['databaseId'],
930+
table['$id'],
931+
table.columns.filter(column => column.side !== 'child').map(column => column.key)
932+
);
933+
934+
if (!result) {
935+
throw new Error(`Column creation timed out.`);
936+
}
937+
938+
success(`Created ${columns.length} columns`);
939+
}
921940

922941
const pushResources = async () => {
923942
const actions = {
@@ -1797,13 +1816,12 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
17971816
if ((Array.isArray(columns) && columns.length <= 0) && (Array.isArray(indexes) && indexes.length <= 0)) {
17981817
continue;
17991818
}
1800-
18011819
}
18021820

18031821
log(`Pushing table ${table.name} ( ${table['databaseId']} - ${table['$id']} ) attributes`)
18041822

18051823
try {
1806-
await createAttributes(columns, table)
1824+
await createColumns(columns, table)
18071825
} catch (e) {
18081826
throw e;
18091827
}

templates/cli/lib/questions.js.twig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { projectsList } = require('./commands/projects');
55
const { organizationsList } = require('./commands/organizations');
66
const { teamsList } = require('./commands/teams');
77
const { functionsListRuntimes, functionsListSpecifications, functionsList } = require('./commands/functions');
8-
const { accountListMfaFactors } = require("./commands/account");
8+
const { accountListMFAFactors } = require("./commands/account");
99
const { sdkForConsole } = require("./sdks");
1010
const { validateRequired } = require("./validations");
1111
const { paginate } = require('./paginate');
@@ -877,7 +877,7 @@ const questionsListFactors = [
877877
message: "Your account is protected by multi-factor authentication. Please choose one for verification.",
878878
choices: async () => {
879879
let client = await sdkForConsole(false);
880-
const factors = await accountListMfaFactors({
880+
const factors = await accountListMFAFactors({
881881
sdk: client,
882882
parseOutput: false
883883
});
@@ -906,7 +906,7 @@ const questionsListFactors = [
906906
}
907907
];
908908

909-
const questionsMfaChallenge = [
909+
const questionsMFAChallenge = [
910910
{
911911
type: "input",
912912
name: "otp",
@@ -1019,7 +1019,7 @@ module.exports = {
10191019
questionsPushTeams,
10201020
questionsGetEntrypoint,
10211021
questionsListFactors,
1022-
questionsMfaChallenge,
1022+
questionsMFAChallenge,
10231023
questionsRunFunctions,
10241024
questionGetEndpoint,
10251025
questionsInitResources,

0 commit comments

Comments
 (0)