Skip to content

Commit

Permalink
add a backfill script
Browse files Browse the repository at this point in the history
  • Loading branch information
aubin-tchoi committed Dec 16, 2024
1 parent b85a02e commit 38c4a94
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions connectors/migrations/20241216_backfill_confluence_folders.ts
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}`
);
}
}
});

0 comments on commit 38c4a94

Please sign in to comment.