-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flav/views only for managed datasources (#6608)
* s/datasource/data_source * Only create a data source view for managed data sources with a connection * Create data source with provider * Add migration to delete un managed data source views * 🙈 * ✨ * ✨
- Loading branch information
Showing
19 changed files
with
110 additions
and
62 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
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
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
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
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
64 changes: 64 additions & 0 deletions
64
front/migrations/20240730_delete_unmanaged_data_source_views.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,64 @@ | ||
import type { LightWorkspaceType } from "@dust-tt/types"; | ||
import assert from "assert"; | ||
|
||
import { Authenticator } from "@app/lib/auth"; | ||
import { DataSourceResource } from "@app/lib/resources/data_source_resource"; | ||
import { DataSourceViewResource } from "@app/lib/resources/data_source_view_resource"; | ||
import type { Logger } from "@app/logger/logger"; | ||
import { makeScript, runOnAllWorkspaces } from "@app/scripts/helpers"; | ||
|
||
async function deleteUnmanagedDataSourceViewsForWorkspace( | ||
workspace: LightWorkspaceType, | ||
logger: Logger, | ||
execute: boolean | ||
) { | ||
const auth = await Authenticator.internalAdminForWorkspace(workspace.sId); | ||
|
||
// List workspace data sources. | ||
const dataSources = await DataSourceResource.listByWorkspace(auth); | ||
|
||
// List workspace data source views. | ||
const dataSourceViews = await DataSourceViewResource.listByWorkspace(auth); | ||
|
||
logger.info( | ||
`Found ${dataSourceViews.length} data source views for workspace(${workspace.sId}).` | ||
); | ||
|
||
const viewsToDelete: DataSourceViewResource[] = []; | ||
for (const dataSourceView of dataSourceViews) { | ||
const ds = dataSources.find((ds) => ds.id === dataSourceView.dataSourceId); | ||
assert(ds, `Data source ${dataSourceView.dataSourceId} not found.`); | ||
|
||
// If data source is not managed, delete the view. | ||
if (!ds.isManaged()) { | ||
viewsToDelete.push(dataSourceView); | ||
} | ||
} | ||
|
||
logger.info( | ||
`About to delete ${viewsToDelete.length} unmanaged data source views for workspace(${workspace.sId}).` | ||
); | ||
|
||
if (!execute) { | ||
return; | ||
} | ||
|
||
for (const view of viewsToDelete) { | ||
await view.delete(auth); | ||
logger.info(`Deleted view for data source ${view.dataSourceId}.`); | ||
} | ||
|
||
logger.info( | ||
`Deleted all unmanaged data source views for workspace(${workspace.sId}).` | ||
); | ||
} | ||
|
||
makeScript({}, async ({ execute }, logger) => { | ||
return runOnAllWorkspaces(async (workspace) => { | ||
await deleteUnmanagedDataSourceViewsForWorkspace( | ||
workspace, | ||
logger, | ||
execute | ||
); | ||
}); | ||
}); |
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
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
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
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