-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b85a02e
commit 38c4a94
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
connectors/migrations/20241216_backfill_confluence_folders.ts
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,33 @@ | ||
import { makeScript } from "scripts/helpers"; | ||
|
||
import { makeSpaceInternalId } from "@connectors/connectors/confluence/lib/internal_ids"; | ||
import { dataSourceConfigFromConnector } from "@connectors/lib/api/data_source_config"; | ||
import { upsertFolderNode } from "@connectors/lib/data_sources"; | ||
import { ConfluenceSpace } from "@connectors/lib/models/confluence"; | ||
import { ConnectorResource } from "@connectors/resources/connector_resource"; | ||
|
||
makeScript({}, async ({ execute }, logger) => { | ||
const connectors = await ConnectorResource.listByType("confluence", {}); | ||
|
||
for (const connector of connectors) { | ||
const confluenceSpaces = await ConfluenceSpace.findAll({ | ||
attributes: ["spaceId", "name"], | ||
where: { connectorId: connector.id }, | ||
}); | ||
const dataSourceConfig = dataSourceConfigFromConnector(connector); | ||
if (execute) { | ||
for (const space of confluenceSpaces) { | ||
await upsertFolderNode({ | ||
dataSourceConfig, | ||
folderId: makeSpaceInternalId(space.spaceId), | ||
parents: [makeSpaceInternalId(space.spaceId)], | ||
title: space.name, | ||
}); | ||
} | ||
} else { | ||
logger.info( | ||
`Found ${confluenceSpaces.length} spaces for connector ${connector.id}` | ||
); | ||
} | ||
} | ||
}); |