appwrite-utils-cli 1.6.4 → 1.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -177,7 +177,12 @@ export const createOrUpdateIndex = async (dbId, db, collectionId, index) => {
177
177
  createIndex = true;
178
178
  }
179
179
  if (createIndex) {
180
- newIndex = await db.createIndex(dbId, collectionId, index.key, index.type, index.attributes, index.orders);
180
+ // Ensure orders array exists and matches attributes length
181
+ // Default to "asc" for each attribute if not specified
182
+ const orders = index.orders && index.orders.length === index.attributes.length
183
+ ? index.orders
184
+ : index.attributes.map(() => "asc");
185
+ newIndex = await db.createIndex(dbId, collectionId, index.key, index.type, index.attributes, orders);
181
186
  }
182
187
  return newIndex;
183
188
  };
@@ -68,7 +68,8 @@ export const checkForCollection = async (db, dbId, collection) => {
68
68
  const items = isLegacyDatabases(db) ? response.collections : (response.tables || response.collections);
69
69
  if (items && items.length > 0) {
70
70
  MessageFormatter.info(`Collection found: ${items[0].$id}`, { prefix: "Collections" });
71
- return { ...collection, ...items[0] };
71
+ // Return remote collection for update operations (don't merge local config over it)
72
+ return items[0];
72
73
  }
73
74
  else {
74
75
  MessageFormatter.info(`No collection found with name: ${collection.name}`, { prefix: "Collections" });
@@ -223,10 +224,8 @@ export const createOrUpdateCollections = async (database, databaseId, config, de
223
224
  attributes);
224
225
  // Add delay after creating attributes
225
226
  await delay(250);
226
- const indexesToUse = indexes && indexes.length > 0
227
- ? indexes
228
- : config.collections?.find((c) => c.$id === collectionToUse.$id)
229
- ?.indexes ?? [];
227
+ // For PUSH operations, only use indexes from local config (not remote)
228
+ const indexesToUse = indexes || [];
230
229
  MessageFormatter.progress("Creating Indexes", { prefix: "Collections" });
231
230
  await createOrUpdateIndexesWithStatusCheck(databaseId, database, collectionToUse.$id, collectionToUse, indexesToUse);
232
231
  // Mark this collection as fully processed to prevent re-processing
package/dist/main.js CHANGED
@@ -697,24 +697,19 @@ async function main() {
697
697
  operationStats.wipedBuckets = wipeStats.buckets;
698
698
  }
699
699
  }
700
- if (parsedArgv.push || parsedArgv.sync) {
700
+ if (parsedArgv.push) {
701
+ // PUSH: Use LOCAL config collections only (pass empty array to use config.collections)
701
702
  const databases = options.databases || (await fetchAllDatabases(controller.database));
702
- let collections = [];
703
- if (options.collections) {
704
- for (const db of databases) {
705
- const dbCollections = await fetchAllCollections(db.$id, controller.database);
706
- collections = collections.concat(dbCollections.filter((c) => options.collections.includes(c.$id)));
707
- }
708
- }
709
- if (parsedArgv.push) {
710
- await controller.syncDb(databases, collections);
711
- operationStats.pushedDatabases = databases.length;
712
- operationStats.pushedCollections = collections.length;
713
- }
714
- else if (parsedArgv.sync) {
715
- await controller.synchronizeConfigurations(databases);
716
- operationStats.syncedDatabases = databases.length;
717
- }
703
+ // Pass empty array - syncDb will use config.collections (local schema)
704
+ await controller.syncDb(databases, []);
705
+ operationStats.pushedDatabases = databases.length;
706
+ operationStats.pushedCollections = controller.config?.collections?.length || 0;
707
+ }
708
+ else if (parsedArgv.sync) {
709
+ // SYNC: Pull from remote
710
+ const databases = options.databases || (await fetchAllDatabases(controller.database));
711
+ await controller.synchronizeConfigurations(databases);
712
+ operationStats.syncedDatabases = databases.length;
718
713
  }
719
714
  if (options.generateSchemas) {
720
715
  await controller.generateSchemas();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "appwrite-utils-cli",
3
3
  "description": "Appwrite Utility Functions to help with database management, data conversion, data import, migrations, and much more. Meant to be used as a CLI tool, I do not recommend installing this in frontend environments.",
4
- "version": "1.6.4",
4
+ "version": "1.6.5",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -293,13 +293,19 @@ export const createOrUpdateIndex = async (
293
293
  }
294
294
 
295
295
  if (createIndex) {
296
+ // Ensure orders array exists and matches attributes length
297
+ // Default to "asc" for each attribute if not specified
298
+ const orders = index.orders && index.orders.length === index.attributes.length
299
+ ? index.orders
300
+ : index.attributes.map(() => "asc");
301
+
296
302
  newIndex = await db.createIndex(
297
303
  dbId,
298
304
  collectionId,
299
305
  index.key,
300
306
  index.type as IndexType,
301
307
  index.attributes,
302
- index.orders
308
+ orders
303
309
  );
304
310
  }
305
311
 
@@ -122,7 +122,8 @@ export const checkForCollection = async (
122
122
  const items = isLegacyDatabases(db) ? response.collections : ((response as any).tables || response.collections);
123
123
  if (items && items.length > 0) {
124
124
  MessageFormatter.info(`Collection found: ${items[0].$id}`, { prefix: "Collections" });
125
- return { ...collection, ...items[0] } as Models.Collection;
125
+ // Return remote collection for update operations (don't merge local config over it)
126
+ return items[0] as Models.Collection;
126
127
  } else {
127
128
  MessageFormatter.info(`No collection found with name: ${collection.name}`, { prefix: "Collections" });
128
129
  return null;
@@ -338,11 +339,8 @@ export const createOrUpdateCollections = async (
338
339
  // Add delay after creating attributes
339
340
  await delay(250);
340
341
 
341
- const indexesToUse =
342
- indexes && indexes.length > 0
343
- ? indexes
344
- : config.collections?.find((c) => c.$id === collectionToUse!.$id)
345
- ?.indexes ?? [];
342
+ // For PUSH operations, only use indexes from local config (not remote)
343
+ const indexesToUse = indexes || [];
346
344
 
347
345
  MessageFormatter.progress("Creating Indexes", { prefix: "Collections" });
348
346
  await createOrUpdateIndexesWithStatusCheck(
package/src/main.ts CHANGED
@@ -850,31 +850,21 @@ async function main() {
850
850
  }
851
851
  }
852
852
 
853
- if (parsedArgv.push || parsedArgv.sync) {
853
+ if (parsedArgv.push) {
854
+ // PUSH: Use LOCAL config collections only (pass empty array to use config.collections)
854
855
  const databases =
855
856
  options.databases || (await fetchAllDatabases(controller.database!));
856
- let collections: Models.Collection[] = [];
857
857
 
858
- if (options.collections) {
859
- for (const db of databases) {
860
- const dbCollections = await fetchAllCollections(
861
- db.$id,
862
- controller.database!
863
- );
864
- collections = collections.concat(
865
- dbCollections.filter((c) => options.collections!.includes(c.$id))
866
- );
867
- }
868
- }
869
-
870
- if (parsedArgv.push) {
871
- await controller.syncDb(databases, collections);
872
- operationStats.pushedDatabases = databases.length;
873
- operationStats.pushedCollections = collections.length;
874
- } else if (parsedArgv.sync) {
875
- await controller.synchronizeConfigurations(databases);
876
- operationStats.syncedDatabases = databases.length;
877
- }
858
+ // Pass empty array - syncDb will use config.collections (local schema)
859
+ await controller.syncDb(databases, []);
860
+ operationStats.pushedDatabases = databases.length;
861
+ operationStats.pushedCollections = controller.config?.collections?.length || 0;
862
+ } else if (parsedArgv.sync) {
863
+ // SYNC: Pull from remote
864
+ const databases =
865
+ options.databases || (await fetchAllDatabases(controller.database!));
866
+ await controller.synchronizeConfigurations(databases);
867
+ operationStats.syncedDatabases = databases.length;
878
868
  }
879
869
 
880
870
  if (options.generateSchemas) {