UNPKG

appwrite-utils-cli

Version:

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.

20 lines (19 loc) 871 B
import { indexSchema } from "appwrite-utils"; import { Databases, IndexType, Query } from "node-appwrite"; import { tryAwaitWithRetry } from "../utils/helperFunctions.js"; // import {} export const createOrUpdateIndex = async (dbId, db, collectionId, index) => { const existingIndex = await db.listIndexes(dbId, collectionId, [ Query.equal("key", index.key), ]); if (existingIndex.total > 0) { await db.deleteIndex(dbId, collectionId, existingIndex.indexes[0].key); } const newIndex = await db.createIndex(dbId, collectionId, index.key, index.type, index.attributes, index.orders); return newIndex; }; export const createOrUpdateIndexes = async (dbId, db, collectionId, indexes) => { for (const index of indexes) { await tryAwaitWithRetry(async () => await createOrUpdateIndex(dbId, db, collectionId, index)); } };