Skip to content

Commit 7f19171

Browse files
authored
Merge pull request #1178 from appwrite/prevent-autopull
chore: prevent deprecated resources from being auto pulled
2 parents 3ad8053 + 7d4ebe0 commit 7f19171

File tree

5 files changed

+76
-44
lines changed

5 files changed

+76
-44
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => {
124124
if(answers.autopull) {
125125
cliConfig.all = true;
126126
cliConfig.force = true;
127-
await pullResources();
127+
await pullResources({
128+
skipDeprecated: true
129+
});
128130
} else {
129131
log("You can run 'appwrite pull all' to synchronize all of your existing resources.");
130132
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ const { paginate } = require("../paginate");
1616
const { questionsPullCollection, questionsPullFunctions, questionsPullFunctionsCode, questionsPullSites, questionsPullSitesCode, questionsPullResources } = require("../questions");
1717
const { cliConfig, success, log, warn, actionRunner, commandDescriptions } = require("../parser");
1818

19-
const pullResources = async () => {
19+
const pullResources = async ({
20+
skipDeprecated = false
21+
} = {}) => {
2022
const actions = {
2123
settings: pullSettings,
2224
functions: pullFunctions,
@@ -28,6 +30,10 @@ const pullResources = async () => {
2830
messages: pullMessagingTopic
2931
}
3032

33+
if (skipDeprecated) {
34+
delete actions.collections;
35+
}
36+
3137
if (cliConfig.all) {
3238
for (let action of Object.values(actions)) {
3339
cliConfig.all = true;
@@ -372,7 +378,7 @@ const pullTable = async () => {
372378
total++;
373379
log(`Pulling all tables from ${chalk.bold(database['name'])} database ...`);
374380

375-
localConfig.addDatabase(database);
381+
localConfig.addTablesDB(database);
376382

377383
const { tables } = await paginate(tablesDBListTables, {
378384
databaseId,

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ const {
5151
} = require("./databases");
5252
const {
5353
tablesDBGet,
54-
tablesDBGetTable
54+
tablesDBGetTable,
55+
tablesDBUpdateTable,
56+
tablesDBCreateTable
5557
} = require("./tables-db");
5658
const {
5759
storageGetBucket, storageUpdateBucket, storageCreateBucket
@@ -892,7 +894,7 @@ const createIndexes = async (indexes, collection) => {
892894
);
893895

894896
if (!result) {
895-
throw new Error("Index creation timed out.");
897+
throw new Error('Index creation timed out.');
896898
}
897899

898900
success(`Created ${indexes.length} indexes`);
@@ -1711,7 +1713,7 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
17111713

17121714
// Parallel db actions
17131715
await Promise.all(databases.map(async (databaseId) => {
1714-
const localDatabase = localConfig.getDatabase(databaseId);
1716+
const localDatabase = localConfig.getTablesDB(databaseId);
17151717

17161718
try {
17171719
const database = await tablesDBGet({
@@ -1753,11 +1755,10 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
17531755
});
17541756

17551757
if (remoteTable.name !== table.name) {
1756-
await databasesUpdateTable({
1758+
await tablesDBUpdateTable({
17571759
databaseId: table['databaseId'],
17581760
tableId: table['$id'],
17591761
name: table.name,
1760-
name: table.name,
17611762
parseOutput: false
17621763
})
17631764

@@ -1770,7 +1771,7 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
17701771
(e) {
17711772
if (Number(e.code) === 404) {
17721773
log(`Table ${table.name} does not exist in the project. Creating ... `);
1773-
await databasesCreateTable({
1774+
await tablesDBCreateTable({
17741775
databaseId: table['databaseId'],
17751776
tableId: table['$id'],
17761777
name: table.name,
@@ -1900,7 +1901,6 @@ const pushCollection = async ({ returnOnZero, attempts } = { returnOnZero: false
19001901
databaseId: collection['databaseId'],
19011902
collectionId: collection['$id'],
19021903
name: collection.name,
1903-
name: collection.name,
19041904
parseOutput: false
19051905
})
19061906

templates/cli/lib/config.js.twig

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,47 @@ class Config {
150150
toString() {
151151
return JSONbig.stringify(this.data, null, 4);
152152
}
153+
154+
_getDBEntities(entityType) {
155+
if (!this.has(entityType)) {
156+
return [];
157+
}
158+
return this.get(entityType);
159+
}
160+
161+
_getDBEntity(entityType, $id) {
162+
if (!this.has(entityType)) {
163+
return {};
164+
}
165+
166+
let entities = this.get(entityType);
167+
for (let i = 0; i < entities.length; i++) {
168+
if (entities[i]['$id'] == $id) {
169+
return entities[i];
170+
}
171+
}
172+
173+
return {};
174+
}
175+
176+
_addDBEntity(entityType, props, keysSet, nestedKeys = {}) {
177+
props = whitelistKeys(props, keysSet, nestedKeys);
178+
179+
if (!this.has(entityType)) {
180+
this.set(entityType, []);
181+
}
182+
183+
let entities = this.get(entityType);
184+
for (let i = 0; i < entities.length; i++) {
185+
if (entities[i]['$id'] == props['$id']) {
186+
entities[i] = props;
187+
this.set(entityType, entities);
188+
return;
189+
}
190+
}
191+
entities.push(props);
192+
this.set(entityType, entities);
193+
}
153194
}
154195

155196
class Local extends Config {
@@ -464,45 +505,28 @@ class Local extends Config {
464505
this.set("topics", topics);
465506
}
466507

467-
getDatabases() {
468-
if (!this.has("databases")) {
469-
return [];
470-
}
471-
return this.get("databases");
508+
getTablesDBs() {
509+
return this._getDBEntities("tablesDB");
472510
}
473511

474-
getDatabase($id) {
475-
if (!this.has("databases")) {
476-
return {};
477-
}
512+
getTablesDB($id) {
513+
return this._getDBEntity("tablesDB", $id);
514+
}
515+
516+
addTablesDB(props) {
517+
this._addDBEntity("tablesDB", props, KeysDatabase);
518+
}
478519

479-
let databases = this.get("databases");
480-
for (let i = 0; i < databases.length; i++) {
481-
if (databases[i]['$id'] == $id) {
482-
return databases[i];
483-
}
484-
}
520+
getDatabases() {
521+
return this._getDBEntities("databases");
522+
}
485523

486-
return {};
524+
getDatabase($id) {
525+
return this._getDBEntity("databases", $id);
487526
}
488527

489528
addDatabase(props) {
490-
props = whitelistKeys(props, KeysDatabase);
491-
492-
if (!this.has("databases")) {
493-
this.set("databases", []);
494-
}
495-
496-
let databases = this.get("databases");
497-
for (let i = 0; i < databases.length; i++) {
498-
if (databases[i]['$id'] == props['$id']) {
499-
databases[i] = props;
500-
this.set("databases", databases);
501-
return;
502-
}
503-
}
504-
databases.push(props);
505-
this.set("databases", databases);
529+
this._addDBEntity("databases", props, KeysDatabase);
506530
}
507531

508532
getTeams() {

templates/cli/lib/questions.js.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ const questionsPullResources = [
259259
{ name: `Buckets ${chalk.blackBright(`(Storage)`)}`, value: 'buckets' },
260260
{ name: `Teams ${chalk.blackBright(`(Auth)`)}`, value: 'teams' },
261261
{ name: `Topics ${chalk.blackBright(`(Messaging)`)}`, value: 'messages' },
262-
{ name: `Collections ${chalk.blackBright(`(Database)`)}`, value: 'collections' }
262+
{ name: `Collections ${chalk.blackBright(`(Legacy Databases)`)}`, value: 'collections' }
263263
]
264264
}
265265
]
@@ -671,7 +671,7 @@ const questionsPushResources = [
671671
{ name: `Buckets ${chalk.blackBright(`(Storage)`)}`, value: 'buckets' },
672672
{ name: `Teams ${chalk.blackBright(`(Auth)`)}`, value: 'teams' },
673673
{ name: `Topics ${chalk.blackBright(`(Messaging)`)}`, value: 'messages' },
674-
{ name: `Collections ${chalk.blackBright(`(Database)`)}`, value: 'collections' }
674+
{ name: `Collections ${chalk.blackBright(`(Legacy Databases)`)}`, value: 'collections' }
675675
]
676676
}
677677
];

0 commit comments

Comments
 (0)