appwrite-utils-cli 1.1.2 → 1.1.3

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.
@@ -63,28 +63,6 @@ retryCount = 0, maxRetries = 5) => {
63
63
  }
64
64
  return false;
65
65
  };
66
- /**
67
- * Delete collection and recreate for index retry (reused from attributes.ts)
68
- */
69
- const deleteAndRecreateCollectionForIndex = async (db, dbId, collection, retryCount) => {
70
- try {
71
- console.log(chalk.yellow(`🗑️ Deleting collection '${collection.name}' for index retry ${retryCount}`));
72
- // Delete the collection
73
- await db.deleteCollection(dbId, collection.$id);
74
- console.log(chalk.yellow(`Deleted collection '${collection.name}'`));
75
- // Wait a bit before recreating
76
- await delay(2000);
77
- // Recreate the collection
78
- console.log(chalk.blue(`🔄 Recreating collection '${collection.name}'`));
79
- const newCollection = await db.createCollection(dbId, collection.$id, collection.name, collection.$permissions, collection.documentSecurity, collection.enabled);
80
- console.log(chalk.green(`✅ Recreated collection '${collection.name}'`));
81
- return newCollection;
82
- }
83
- catch (error) {
84
- console.log(chalk.red(`Failed to delete/recreate collection '${collection.name}': ${error}`));
85
- return null;
86
- }
87
- };
88
66
  /**
89
67
  * Enhanced index creation with proper status monitoring and retry logic
90
68
  */
@@ -99,17 +77,13 @@ export const createOrUpdateIndexWithStatusCheck = async (dbId, db, collectionId,
99
77
  if (success) {
100
78
  return true;
101
79
  }
102
- // If not successful and we have retries left, delete collection and try again
80
+ // If not successful and we have retries left, just retry the index creation
103
81
  if (retryCount < maxRetries) {
104
- console.log(chalk.yellow(`Index '${index.key}' failed/stuck, retrying...`));
105
- // Get fresh collection data
106
- const freshCollection = await db.getCollection(dbId, collectionId);
107
- // Delete and recreate collection
108
- const newCollection = await deleteAndRecreateCollectionForIndex(db, dbId, freshCollection, retryCount + 1);
109
- if (newCollection) {
110
- // Retry with the new collection
111
- return await createOrUpdateIndexWithStatusCheck(dbId, db, newCollection.$id, newCollection, index, retryCount + 1, maxRetries);
112
- }
82
+ console.log(chalk.yellow(`Index '${index.key}' failed/stuck, retrying (${retryCount + 1}/${maxRetries})...`));
83
+ // Wait a bit before retry
84
+ await new Promise(resolve => setTimeout(resolve, 2000 * (retryCount + 1)));
85
+ // Retry the index creation
86
+ return await createOrUpdateIndexWithStatusCheck(dbId, db, collectionId, collection, index, retryCount + 1, maxRetries);
113
87
  }
114
88
  console.log(chalk.red(`❌ Failed to create index '${index.key}' after ${maxRetries + 1} attempts`));
115
89
  return false;
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.1.2",
4
+ "version": "1.1.3",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -98,44 +98,6 @@ const waitForIndexAvailable = async (
98
98
  return false;
99
99
  };
100
100
 
101
- /**
102
- * Delete collection and recreate for index retry (reused from attributes.ts)
103
- */
104
- const deleteAndRecreateCollectionForIndex = async (
105
- db: Databases,
106
- dbId: string,
107
- collection: Models.Collection,
108
- retryCount: number
109
- ): Promise<Models.Collection | null> => {
110
- try {
111
- console.log(chalk.yellow(`🗑️ Deleting collection '${collection.name}' for index retry ${retryCount}`));
112
-
113
- // Delete the collection
114
- await db.deleteCollection(dbId, collection.$id);
115
- console.log(chalk.yellow(`Deleted collection '${collection.name}'`));
116
-
117
- // Wait a bit before recreating
118
- await delay(2000);
119
-
120
- // Recreate the collection
121
- console.log(chalk.blue(`🔄 Recreating collection '${collection.name}'`));
122
- const newCollection = await db.createCollection(
123
- dbId,
124
- collection.$id,
125
- collection.name,
126
- collection.$permissions,
127
- collection.documentSecurity,
128
- collection.enabled
129
- );
130
-
131
- console.log(chalk.green(`✅ Recreated collection '${collection.name}'`));
132
- return newCollection;
133
-
134
- } catch (error) {
135
- console.log(chalk.red(`Failed to delete/recreate collection '${collection.name}': ${error}`));
136
- return null;
137
- }
138
- };
139
101
 
140
102
  /**
141
103
  * Enhanced index creation with proper status monitoring and retry logic
@@ -170,28 +132,23 @@ export const createOrUpdateIndexWithStatusCheck = async (
170
132
  return true;
171
133
  }
172
134
 
173
- // If not successful and we have retries left, delete collection and try again
135
+ // If not successful and we have retries left, just retry the index creation
174
136
  if (retryCount < maxRetries) {
175
- console.log(chalk.yellow(`Index '${index.key}' failed/stuck, retrying...`));
137
+ console.log(chalk.yellow(`Index '${index.key}' failed/stuck, retrying (${retryCount + 1}/${maxRetries})...`));
176
138
 
177
- // Get fresh collection data
178
- const freshCollection = await db.getCollection(dbId, collectionId);
179
-
180
- // Delete and recreate collection
181
- const newCollection = await deleteAndRecreateCollectionForIndex(db, dbId, freshCollection, retryCount + 1);
139
+ // Wait a bit before retry
140
+ await new Promise(resolve => setTimeout(resolve, 2000 * (retryCount + 1)));
182
141
 
183
- if (newCollection) {
184
- // Retry with the new collection
185
- return await createOrUpdateIndexWithStatusCheck(
186
- dbId,
187
- db,
188
- newCollection.$id,
189
- newCollection,
190
- index,
191
- retryCount + 1,
192
- maxRetries
193
- );
194
- }
142
+ // Retry the index creation
143
+ return await createOrUpdateIndexWithStatusCheck(
144
+ dbId,
145
+ db,
146
+ collectionId,
147
+ collection,
148
+ index,
149
+ retryCount + 1,
150
+ maxRetries
151
+ );
195
152
  }
196
153
 
197
154
  console.log(chalk.red(`❌ Failed to create index '${index.key}' after ${maxRetries + 1} attempts`));