Skip to content

Commit e7c053d

Browse files
authored
fix: specify complete index name in environment variables (#10067)
* fix: specify complete index name in environment variables
1 parent 9317c99 commit e7c053d

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

scripts/algolia.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
*
1515
* If you want to run it locally,
1616
* 1. Make sure you have the required env vars set up
17-
* 2. be careful to change to `ALGOLIA_INDEX_PREFIX` to value different from `sentry-`
18-
* to avoid nuking the production index
17+
* 2. Be careful to change to `DOCS_INDEX_NAME` to a value different
18+
* from the productoin docs index name (specified in the `@sentry-internal/global-search`)
19+
* to avoid accidental deletions
1920
* 3. Run a production build of the app before running this script
2021
*/
2122

@@ -35,21 +36,20 @@ const staticHtmlFilesPath = join(process.cwd(), '.next', 'server', 'app');
3536

3637
const ALGOLIA_APP_ID = process.env.ALGOLIA_APP_ID;
3738
const ALGOLIA_API_KEY = process.env.ALGOLIA_API_KEY;
38-
const ALGOLIA_INDEX_PREFIX = process.env.ALGOLIA_INDEX_PREFIX;
39+
const DOCS_INDEX_NAME = process.env.DOCS_INDEX_NAME;
3940

4041
if (!ALGOLIA_APP_ID) {
4142
throw new Error('`ALGOLIA_APP_ID` env var must be configured in repo secrets');
4243
}
4344
if (!ALGOLIA_API_KEY) {
4445
throw new Error('`ALGOLIA_API_KEY` env var must be configured in repo secrets');
4546
}
46-
if (!ALGOLIA_INDEX_PREFIX) {
47-
throw new Error('`ALGOLIA_INDEX_PREFIX` env var must be configured in repo secrets');
47+
if (!DOCS_INDEX_NAME) {
48+
throw new Error('`DOCS_INDEX_NAME` env var must be configured in repo secrets');
4849
}
4950

50-
const indexName = `${ALGOLIA_INDEX_PREFIX}docs`;
5151
const client = algoliasearch(ALGOLIA_APP_ID, ALGOLIA_API_KEY);
52-
const index = client.initIndex(indexName);
52+
const index = client.initIndex(DOCS_INDEX_NAME);
5353

5454
indexAndUpload();
5555
async function indexAndUpload() {
@@ -62,9 +62,9 @@ async function indexAndUpload() {
6262
console.log(
6363
'🔥 Found %d existing Algolia records in `%s`',
6464
existingRecordIds.length,
65-
indexName
65+
DOCS_INDEX_NAME
6666
);
67-
console.log('🔥 Saving new records to `%s`...', indexName);
67+
console.log('🔥 Saving new records to `%s`...', DOCS_INDEX_NAME);
6868
const saveResult = await index.saveObjects(records, {
6969
batchSize: 10000,
7070
autoGenerateObjectIDIfNotExist: true,
@@ -82,7 +82,7 @@ async function indexAndUpload() {
8282
console.log(
8383
'🔥 Deleted %d stale records from `%s`',
8484
deleteResult.objectIDs.length,
85-
indexName
85+
DOCS_INDEX_NAME
8686
);
8787
}
8888

0 commit comments

Comments
 (0)