-
-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔨 add command for deleting Algolia index (#3777)
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { ALGOLIA_INDEXING } from "../../settings/serverSettings.js" | ||
import { ALGOLIA_INDEX_PREFIX } from "../../settings/clientSettings.js" | ||
import { getAlgoliaClient } from "./configureAlgolia.js" | ||
import { SearchIndexName } from "../../site/search/searchTypes.js" | ||
import { getIndexName } from "../../site/search/searchClient.js" | ||
|
||
const deleteAlgoliaIndex = async () => { | ||
if (!ALGOLIA_INDEXING) return | ||
|
||
if (ALGOLIA_INDEX_PREFIX === "") { | ||
console.error( | ||
"ALGOLIA_INDEX_PREFIX is not set, refusing to delete production indexes" | ||
) | ||
return | ||
} | ||
|
||
const client = getAlgoliaClient() | ||
if (!client) { | ||
console.error(`Failed to remove index (Algolia client not initialized)`) | ||
return | ||
} | ||
|
||
for (const suffix of [ | ||
SearchIndexName.Pages, | ||
SearchIndexName.Charts, | ||
SearchIndexName.ExplorerViews, | ||
]) { | ||
const indexName = getIndexName(suffix) | ||
const index = client.initIndex(indexName) | ||
try { | ||
await index.delete() | ||
console.log(`Index '${indexName}' removed successfully`) | ||
} catch (error) { | ||
console.error(`Error removing index '${indexName}':`, error) | ||
} | ||
} | ||
|
||
process.exit(0) | ||
} | ||
|
||
process.on("unhandledRejection", (e) => { | ||
console.error(e) | ||
process.exit(1) | ||
}) | ||
|
||
void deleteAlgoliaIndex() |