Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: connect database (#20473)

ecmadao510a803f80cc
diff --git a/frontend/src/react/components/sql-editor/ConnectionPane/ConnectionPane.tsx b/frontend/src/react/components/sql-editor/ConnectionPane/ConnectionPane.tsx
index a5fe4d1b05..594fb65d1d 100644
--- a/frontend/src/react/components/sql-editor/ConnectionPane/ConnectionPane.tsx
+++ b/frontend/src/react/components/sql-editor/ConnectionPane/ConnectionPane.tsx
@@ -30,6 +30,7 @@ import { useCurrentUser } from "@/react/hooks/useAppState";
import { useSQLEditorFeature } from "@/react/hooks/useSQLEditorBridge";
import type { DatabaseFilter } from "@/react/lib/databaseFilter";
import { instanceNamePrefix } from "@/react/lib/resourceName";
+import { getConnectionForSQLEditorTab } from "@/react/lib/sqlEditorConnection";
import { cn } from "@/react/lib/utils";
import { useAppStore } from "@/react/stores/app";
import { useSQLEditorStore } from "@/react/stores/sqlEditor";
@@ -59,7 +60,6 @@ import { DataSourceType } from "@/types/proto-es/v1/instance_service_pb";
import { PlanFeature } from "@/types/proto-es/v1/subscription_service_pb";
import {
extractDatabaseResourceName,
- getConnectionForSQLEditorTab,
getInstanceResource,
getValueFromSearchParams,
getValuesFromSearchParams,
diff --git a/frontend/src/react/components/sql-editor/ConnectionPane/DatabaseGroupTag.test.tsx b/frontend/src/react/components/sql-editor/ConnectionPane/DatabaseGroupTag.test.tsx
index 1facd17d21..775cb725c9 100644
--- a/frontend/src/react/components/sql-editor/ConnectionPane/DatabaseGroupTag.test.tsx
+++ b/frontend/src/react/components/sql-editor/ConnectionPane/DatabaseGroupTag.test.tsx
@@ -16,18 +16,23 @@ vi.mock("react-i18next", () => ({
useTranslation: () => ({ t: (key: string) => key }),
}));
-vi.mock("@/react/stores/app", () => ({
- useAppStore: (selector: (state: unknown) => unknown) =>
- selector({
- fetchDBGroup: mocks.fetchDBGroup,
- // Proxy so `dbGroupsByName[name]` resolves through the per-test
- // `getDBGroupByName` mock (preserves the existing test bodies).
- dbGroupsByName: new Proxy(
- {},
- { get: (_t, prop: string) => mocks.getDBGroupByName(prop) }
- ),
- }),
-}));
+vi.mock("@/react/stores/app", () => {
+ const state = {
+ fetchDBGroup: mocks.fetchDBGroup,
+ // Proxy so `dbGroupsByName[name]` resolves through the per-test
+ // `getDBGroupByName` mock (preserves the existing test bodies).
+ dbGroupsByName: new Proxy(
+ {},
+ { get: (_t, prop: string) => mocks.getDBGroupByName(prop) }
+ ),
+ };
+ return {
+ useAppStore: Object.assign(
+ (selector: (s: typeof state) => unknown) => selector(state),
+ { getState: () => state }
+ ),
+ };
+});
vi.mock("@/types/proto-es/v1/database_group_service_pb", () => ({
DatabaseGroupView: { FULL: 2 },
diff --git a/frontend/src/react/components/sql-editor/MaskingReasonPopover.test.tsx b/frontend/src/react/components/sql-editor/MaskingReasonPopover.test.tsx
index 5c27e523a8..5d7ba0aa1b 100644
--- a/frontend/src/react/components/sql-editor/MaskingReasonPopover.test.tsx
+++ b/frontend/src/react/components/sql-editor/MaskingReasonPopover.test.tsx
@@ -21,11 +21,15 @@ vi.mock("react-i18next", () => ({
useTranslation: mocks.useTranslation,
}));
-vi.mock("@/react/stores/app", () => ({
- useAppStore: (
- selector: (s: { hasFeature: typeof mocks.hasFeature }) => unknown
- ) => selector({ hasFeature: mocks.hasFeature }),
-}));
+vi.mock("@/react/stores/app", () => {
+ const state = { hasFeature: mocks.hasFeature };
+ return {
+ useAppStore: Object.assign(
+ (selector: (s: typeof state) => unknown) => selector(state),
+ { getState: () => state }
+ ),
+ };
+});
vi.mock("@/react/hooks/useAppProject", () => ({
useAppProject: () => mocks.projectData,
diff --git a/frontend/src/react/components/sql-editor/OpenAIButton.test.tsx b/frontend/src/react/components/sql-editor/OpenAIButton.test.tsx
index 32317067fc..e674371206 100644
--- a/frontend/src/react/components/sql-editor/OpenAIButton.test.tsx
+++ b/frontend/src/react/components/sql-editor/OpenAIButton.test.tsx
@@ -49,13 +49,18 @@ vi.mock("@/store", () => ({
useSettingV1Store: mocks.useSettingV1Store,
}));
-vi.mock("@/react/stores/app", () => ({
- useAppStore: (selector: (s: unknown) => unknown) =>
- selector({
- getOrFetchSettingByName: mocks.getOrFetchSettingByName,
- getSettingByName: () => mocks.aiSetting,
- }),
-}));
+vi.mock("@/react/stores/app", () => {
+ const state = {
+ getOrFetchSettingByName: mocks.getOrFetchSettingByName,
+ getSettingByName: () => mocks.aiSetting,
+ };
+ return {
+ useAppStore: Object.assign(
+ (selector: (s: typeof state) => unknown) => selector(state),
+ { getState: () => state }
+ ),
+ };
+});
// `useConnectionOfCurrentSQLEditorTab` now lives on the Pinia bridge hook.
vi.mock("@/react/hooks/useSQLEditorBridge", () => ({
diff --git a/frontend/src/react/components/sql-editor/RequestQueryButton.test.tsx b/frontend/src/react/components/sql-editor/RequestQueryButton.test.tsx
index 163e9933ad..7fa0dec173 100644
--- a/frontend/src/react/components/sql-editor/RequestQueryButton.test.tsx
+++ b/frontend/src/react/components/sql-editor/RequestQueryButton.test.tsx
@@ -44,15 +44,24 @@ vi.mock("@/react/hooks/useAppProject", () => ({
useAppProject: () => mocks.projectData,
}));
-vi.mock("@/react/stores/app", () => ({
- useAppStore: (selector: (state: unknown) => unknown) =>
- selector({
- roleList: mocks.roleList,
- loadSubscription: mocks.loadSubscription,
- hasInstanceFeature: mocks.hasInstanceFeature,
- hasFeature: mocks.appHasFeature,
- }),
-}));
+vi.mock("@/react/stores/app", () => {
+ // Build the state object lazily on every read so per-test reassignments
+ // like `mocks.roleList = [...]` are reflected. Capturing at module init
+ // would freeze the empty default and break the role-selection cases.
+ const buildState = () => ({
+ roleList: mocks.roleList,
+ loadSubscription: mocks.loadSubscription,
+ hasInstanceFeature: mocks.hasInstanceFeature,
+ hasFeature: mocks.appHasFeature,
+ });
+ type State = ReturnType<typeof buildState>;
+ return {
+ useAppStore: Object.assign(
+ (selector: (s: State) => unknown) => selector(buildState()),
+ { getState: buildState }
+ ),
+ };
+});
vi.mock("@/react/stores/sqlEditor/editor-vue-state", () => ({
useSQLEditorVueState: mocks.useSQLEditorVueState,
diff --git a/frontend/src/react/components/sql-editor/SQLEditorRouteShell.tsx b/frontend/src/react/components/sql-editor/SQLEditorRouteShell.tsx
index ca20e78f17..01eba7962c 100644
--- a/frontend/src/react/components/sql-editor/SQLEditorRouteShell.tsx
+++ b/frontend/src/react/components/sql-editor/SQLEditorRouteShell.tsx
@@ -8,6 +8,7 @@ import {
} from "@/react/components/ComponentPermissionGuard";
import { useAppProject } from "@/react/hooks/useAppProject";
import { useClampResultRowsLimitToPolicy } from "@/react/hooks/useSQLEditorBridge";
+import { extractWorksheetConnection } from "@/react/lib/sqlEditorConnection";
import { useCurrentRoute, useNavigate } from "@/react/router";
import { useAppStore } from "@/react/stores/app";
import type { AsidePanelTab } from "@/react/stores/sqlEditor";
@@ -40,7 +41,6 @@ import {
extractDatabaseResourceName,
extractInstanceResourceName,
extractProjectResourceName,
- extractWorksheetConnection,
extractWorksheetID,
getDefaultPagination,
getSheetStatement,
diff --git a/frontend/src/react/components/sql-editor/SheetConnectionIcon.test.tsx b/frontend/src/react/components/sql-editor/SheetConnectionIcon.test.tsx
index 9a2621b922..4ab5e2066b 100644
--- a/frontend/src/react/components/sql-editor/SheetConnectionIcon.test.tsx
+++ b/frontend/src/react/components/sql-editor/SheetConnectionIcon.test.tsx
@@ -17,7 +17,7 @@ const mocks = vi.hoisted(() => ({
>(),
}));
-vi.mock("@/utils", () => ({
+vi.mock("@/react/lib/sqlEditorConnection", () => ({
isConnectedSQLEditorTab: mocks.isConnectedSQLEditorTab,
getConnectionForSQLEditorTab: mocks.getConnectionForSQLEditorTab,
}));
diff --git a/frontend/src/react/components/sql-editor/SheetConnectionIcon.tsx b/frontend/src/react/components/sql-editor/SheetConnectionIcon.tsx
index dc28428c11..34023b6998 100644
--- a/frontend/src/react/components/sql-editor/SheetConnectionIcon.tsx
+++ b/frontend/src/react/components/sql-editor/SheetConnectionIcon.tsx
@@ -1,7 +1,10 @@
import { Unlink } from "lucide-react";
import { EngineIcon, getEngineIconSrc } from "@/react/components/EngineIcon";
+import {
+ getConnectionForSQLEditorTab,
+ isConnectedSQLEditorTab,
+} from "@/react/lib/sqlEditorConnection";
import type { SQLEditorTab } from "@/types";
-import { getConnectionForSQLEditorTab, isConnectedSQLEditorTab } from "@/utils";
type Props = {
readonly tab: SQLEditorTab;
diff --git a/frontend/src/react/components/sql-editor/TreeNodeSuffix.test.tsx b/frontend/src/react/components/sql-editor/TreeNodeSuffix.test.tsx
index 70736353ff..9e1b9d040c 100644
--- a/frontend/src/react/components/sql-editor/TreeNodeSuffix.test.tsx
+++ b/frontend/src/react/components/sql-editor/TreeNodeSuffix.test.tsx
@@ -36,14 +36,19 @@ vi.mock("@/react/hooks/usePiniaBridge", () => ({
usePiniaBridge: mocks.usePiniaBridge,
}));
-vi.mock("@/react/stores/app", () => ({
- useAppStore: (selector: (state: unknown) => unknown) =>
- selector({
- getWorksheetByName: mocks.getWorksheetByName,
- getUserByIdentifier: mocks.getUserByIdentifier,
- getOrFetchUserByIdentifier: mocks.getOrFetchUserByIdentifier,
- }),
-}));
+vi.mock("@/react/stores/app", () => {
+ const state = {
+ getWorksheetByName: mocks.getWorksheetByName,
+ getUserByIdentifier: mocks.getUserByIdentifier,
+ getOrFetchUserByIdentifier: mocks.getOrFetchUserByIdentifier,
+ };
+ return {
+ useAppStore: Object.assign(
+ (selector: (s: typeof state) => unknown) => selector(state),
+ { getState: () => state }
+ ),
+ };
+});
vi.mock("@/react/stores/sqlEditor/tab", () => ({
getSQLEditorTabsState: mocks.getSQLEditorTabsState,
diff --git a/frontend/src/react/hooks/useExecuteSQL.ts b/frontend/src/react/hooks/useExecuteSQL.ts
index 7c3292cd19..b7a815ff9d 100644
--- a/frontend/src/react/hooks/useExecuteSQL.ts
+++ b/frontend/src/react/hooks/useExecuteSQL.ts
@@ -4,6 +4,7 @@ import { cloneDeep, isEmpty } from "lodash-es";
import { useCallback, useEffect, useRef } from "react";
import { useTranslation } from "react-i18next";
import { v4 as uuidv4 } from "uuid";
+import { isConnectedSQLEditorTab } from "@/react/lib/sqlEditorConnection";
import { useAppStore } from "@/react/stores/app";
import { useSQLEditorStore as useSQLEditorReactStore } from "@/react/stores/sqlEditor";
import { getSQLEditorEditorState } from "@/react/stores/sqlEditor/editor";
@@ -34,7 +35,6 @@ import {
getInstanceResource,
getValidDataSourceByPolicy,
hasPermissionToCreateChangeDatabaseIssueInProject,
- isConnectedSQLEditorTab,
} from "@/utils";
import { flattenNoSQLResult } from "@/utils/sqlResult";
import { sqlEditorEvents } from "@/views/sql-editor/events";
diff --git a/frontend/src/react/lib/sqlEditorConnection.ts b/frontend/src/react/lib/sqlEditorConnection.ts
new file mode 100644
index 0000000000..9a465660f0
--- /dev/null
+++ b/frontend/src/react/lib/sqlEditorConnection.ts
@@ -0,0 +1,84 @@
+import { useAppStore } from "@/react/stores/app";
+import type { SQLEditorConnection, SQLEditorTab } from "@/types";
+import { isValidDatabaseName, isValidInstanceName } from "@/types";
+import type { Database } from "@/types/proto-es/v1/database_service_pb";
+import type { InstanceResource } from "@/types/proto-es/v1/instance_service_pb";
+import { emptySQLEditorConnection, extractDatabaseResourceName } from "@/utils";
+import { getInstanceResource } from "@/utils/v1/database";
+import { instanceV1AllowsCrossDatabaseQuery } from "@/utils/v1/instance";
+
+/**
+ * Resolves the live `Database` + `InstanceResource` for a SQL editor tab's
+ * connection. Lives under `@/react/lib/` (not `@/utils/`) because the lookup
+ * goes through the React app store — putting it under `@/utils/` would
+ * create a static ESM cycle: `@/utils` → `@/react/stores/app` → ...slices...
+ * → `@/types` → ... → back into `@/utils`. Hosting on the React side breaks
+ * the import graph cleanly while keeping the migration off Pinia.
+ */
+export const getConnectionForSQLEditorTab = (tab?: SQLEditorTab) => {
+ const target: {
+ instance: InstanceResource | undefined;
+ database: Database | undefined;
+ } = {
+ instance: undefined,
+ database: undefined,
+ };
+ if (!tab) {
+ return target;
+ }
+ const { connection } = tab;
+ if (connection.database) {
+ const database = useAppStore
+ .getState()
+ .getDatabaseByName(connection.database);
+ target.database = database;
+ target.instance = getInstanceResource(database);
+ }
+ return target;
+};
+
+export const isConnectedSQLEditorTab = (tab: SQLEditorTab): boolean => {
+ const { instance, database } = getConnectionForSQLEditorTab(tab);
+ if (!instance) {
+ return false;
+ }
+ if (!isValidInstanceName(instance.name)) {
+ return false;
+ }
+
+ if (instanceV1AllowsCrossDatabaseQuery(instance)) {
+ // Connecting to instance directly.
+ return true;
+ }
+ return !!database && isValidDatabaseName(database.name);
+};
+
+/**
+ * Resolves the connection record for a worksheet by hydrating its database
+ * through the React app store. Bails on the `unknownDatabase` fallback so a
+ * draft tab whose database was deleted or no longer readable doesn't get
+ * `instances/-1/databases/-1` written into its connection — downstream
+ * `migrateDraftsFromCache` would attempt to create a worksheet against that
+ * bogus target and drop the local draft on failure.
+ */
+export const extractWorksheetConnection = async (worksheet: {
+ database: string;
+}): Promise<SQLEditorConnection> => {
+ const connection = emptySQLEditorConnection();
+ if (worksheet.database) {
+ try {
+ const database = await useAppStore
+ .getState()
+ .getOrFetchDatabaseByName(worksheet.database);
+ if (isValidDatabaseName(database.name)) {
+ const { instance } = extractDatabaseResourceName(database.name);
+ connection.instance = instance;
+ connection.database = database.name;
+ }
+ } catch {
+ // Skip — leave the connection empty so the tab opens disconnected
+ // rather than against a corrupt target.
+ }
+ }
+ return connection;
+};
diff --git a/frontend/src/react/stores/sqlEditor/tab.ts b/frontend/src/react/stores/sqlEditor/tab.ts
index acfd5c1c83..b0b917abdc 100644
--- a/frontend/src/react/stores/sqlEditor/tab.ts
+++ b/frontend/src/react/stores/sqlEditor/tab.ts
@@ -3,6 +3,10 @@ import { cloneDeep, head, isUndefined, omitBy, pick } from "lodash-es";
import { create, type StoreApi, type UseBoundStore } from "zustand";
import { immer } from "zustand/middleware/immer";
import { useShallow } from "zustand/react/shallow";
+import {
+ extractWorksheetConnection,
+ isConnectedSQLEditorTab,
+} from "@/react/lib/sqlEditorConnection";
import { useAppStore } from "@/react/stores/app";
import {
migrateDraftsFromCache,
@@ -17,9 +21,7 @@ import { DataSourceType } from "@/types/proto-es/v1/instance_service_pb";
import { PlanFeature } from "@/types/proto-es/v1/subscription_service_pb";
import {
defaultSQLEditorTab,
- extractWorksheetConnection,
getSheetStatement,
- isConnectedSQLEditorTab,
storageKeySqlEditorCurrentTab,
storageKeySqlEditorTabs,
} from "@/utils";
diff --git a/frontend/src/react/stores/sqlEditor/worksheet.ts b/frontend/src/react/stores/sqlEditor/worksheet.ts
index 0f992e68c0..cd42cd465d 100644
--- a/frontend/src/react/stores/sqlEditor/worksheet.ts
+++ b/frontend/src/react/stores/sqlEditor/worksheet.ts
@@ -1,5 +1,6 @@
import { create } from "@bufbuild/protobuf";
import { isUndefined } from "lodash-es";
+import { extractWorksheetConnection } from "@/react/lib/sqlEditorConnection";
import { useAppStore } from "@/react/stores/app";
import { isValidProjectName } from "@/types";
import {
@@ -7,7 +8,6 @@ import {
Worksheet_Visibility,
WorksheetSchema,
} from "@/types/proto-es/v1/worksheet_service_pb";
-import { extractWorksheetConnection } from "@/utils";
import { sqlEditorEvents } from "@/views/sql-editor/events";
import { openWorksheetByName } from "@/views/sql-editor/Sheet";
import { getSQLEditorEditorState } from "./editor";
diff --git a/frontend/src/store/modules/sqlEditor/legacy/migration.ts b/frontend/src/store/modules/sqlEditor/legacy/migration.ts
index 663c3d1821..d1f6a2eee4 100644
--- a/frontend/src/store/modules/sqlEditor/legacy/migration.ts
+++ b/frontend/src/store/modules/sqlEditor/legacy/migration.ts
@@ -1,6 +1,7 @@
import { create } from "@bufbuild/protobuf";
import { isUndefined, omit, omitBy } from "lodash-es";
import { computed, reactive } from "vue";
+import { extractWorksheetConnection } from "@/react/lib/sqlEditorConnection";
import { useAppStore } from "@/react/stores/app";
import type { EditorPanelViewState, SQLEditorTab } from "@/types";
import { DEFAULT_SQL_EDITOR_TAB_MODE } from "@/types";
@@ -10,7 +11,6 @@ import {
} from "@/types/proto-es/v1/worksheet_service_pb";
import {
defaultSQLEditorTab,
- extractWorksheetConnection,
useDynamicLocalStorage,
WebStorageHelper,
} from "@/utils";
diff --git a/frontend/src/utils/sqlEditor.ts b/frontend/src/utils/sqlEditor.ts
index 77abf671cd..7a6e89a5cb 100644
--- a/frontend/src/utils/sqlEditor.ts
+++ b/frontend/src/utils/sqlEditor.ts
@@ -1,6 +1,6 @@
import { head } from "lodash-es";
import { v1 as uuidv1 } from "uuid";
-import { useDatabaseV1Store, useQueryDataPolicy } from "@/store";
+import { useQueryDataPolicy } from "@/store";
import type {
QueryDataSourceType,
SQLEditorConnection,
@@ -9,18 +9,12 @@ import type {
import {
DEFAULT_SQL_EDITOR_TAB_MODE,
defaultViewState,
- isValidDatabaseName,
- isValidInstanceName,
UNKNOWN_DATABASE_NAME,
} from "@/types";
import type { Database } from "@/types/proto-es/v1/database_service_pb";
-import {
- DataSourceType,
- type InstanceResource,
-} from "@/types/proto-es/v1/instance_service_pb";
+import { DataSourceType } from "@/types/proto-es/v1/instance_service_pb";
import { wrapRefAsPromise } from "@/utils";
import { getInstanceResource } from "./v1/database";
-import { instanceV1AllowsCrossDatabaseQuery } from "./v1/instance";
export const defaultSQLEditorTab = (): SQLEditorTab => {
return {
@@ -56,28 +50,6 @@ export const emptySQLEditorConnection = (): SQLEditorConnection => {
};
};
-export const getConnectionForSQLEditorTab = (tab?: SQLEditorTab) => {
- const target: {
- instance: InstanceResource | undefined;
- database: Database | undefined;
- } = {
- instance: undefined,
- database: undefined,
- };
- if (!tab) {
- return target;
- }
- const { connection } = tab;
- if (connection.database) {
- const database = useDatabaseV1Store().getDatabaseByName(
- connection.database
- );
- target.database = database;
- target.instance = getInstanceResource(database);
- }
- return target;
-};
-
export const isSameSQLEditorConnection = (
a: SQLEditorConnection,
b: SQLEditorConnection
@@ -85,21 +57,10 @@ export const isSameSQLEditorConnection = (
return a.instance === b.instance && a.database === b.database;
};
-export const isConnectedSQLEditorTab = (tab: SQLEditorTab) => {
- const { instance, database } = getConnectionForSQLEditorTab(tab);
- if (!instance) {
- return false;
- }
- if (!isValidInstanceName(instance.name)) {
- return false;
- }
-
- if (instanceV1AllowsCrossDatabaseQuery(instance)) {
- // Connecting to instance directly.
- return true;
- }
- return database && isValidDatabaseName(database.name);
-};
+// `getConnectionForSQLEditorTab` and `isConnectedSQLEditorTab` moved to
+// `@/react/lib/sqlEditorConnection` so the database lookup can go through
+// the React app store without dragging `@/react/stores/app` into the
+// `@/utils` import graph (which would create a static ESM cycle).
export const getValidDataSourceByPolicy = async (
database: Database,
diff --git a/frontend/src/utils/v1/worksheet.ts b/frontend/src/utils/v1/worksheet.ts
index 99cb6a152c..cc3cf4ccdc 100644
--- a/frontend/src/utils/v1/worksheet.ts
+++ b/frontend/src/utils/v1/worksheet.ts
@@ -1,18 +1,9 @@
-import {
- getCurrentUserV1,
- useDatabaseV1Store,
- useProjectV1Store,
-} from "@/store";
+import { getCurrentUserV1, useProjectV1Store } from "@/store";
import { extractUserEmail } from "@/store/modules/v1/common";
import { UNKNOWN_ID, UNKNOWN_PROJECT_NAME } from "@/types";
import type { Worksheet } from "@/types/proto-es/v1/worksheet_service_pb";
import { Worksheet_Visibility } from "@/types/proto-es/v1/worksheet_service_pb";
-import {
- emptySQLEditorConnection,
- extractDatabaseResourceName,
- hasProjectPermissionV2,
- hasWorkspacePermissionV2,
-} from "@/utils";
+import { hasProjectPermissionV2, hasWorkspacePermissionV2 } from "@/utils";
export const extractWorksheetID = (name: string) => {
const pattern = /(?:^|\/)worksheets\/([^/]+)(?:$|\/)/;
@@ -83,21 +74,7 @@ export const isWorksheetWritableV1 = (sheet: Worksheet) => {
return false;
};
-export const extractWorksheetConnection = async (worksheet: {
- database: string;
-}) => {
- const connection = emptySQLEditorConnection();
- if (worksheet.database) {
- try {
- const database = await useDatabaseV1Store().getOrFetchDatabaseByName(
- worksheet.database
- );
- const { instance } = extractDatabaseResourceName(database.name);
- connection.instance = instance;
- connection.database = database.name;
- } catch {
- // Skip.
- }
- }
- return connection;
-};
+// `extractWorksheetConnection` moved to `@/react/lib/sqlEditorConnection`
+// so the database lookup can go through the React app store without
+// dragging `@/react/stores/app` into the `@/utils` import graph (which
+// would create a static ESM cycle).
diff --git a/frontend/src/views/sql-editor/Sheet/context.ts b/frontend/src/views/sql-editor/Sheet/context.ts
index b458f5dc59..55f60fc474 100644
--- a/frontend/src/views/sql-editor/Sheet/context.ts
+++ b/frontend/src/views/sql-editor/Sheet/context.ts
@@ -6,6 +6,7 @@ import { create, type StoreApi, type UseBoundStore } from "zustand";
import { immer } from "zustand/middleware/immer";
import { useShallow } from "zustand/react/shallow";
import { t } from "@/plugins/i18n";
+import { extractWorksheetConnection } from "@/react/lib/sqlEditorConnection";
import { useAppStore } from "@/react/stores/app";
import {
getSQLEditorEditorState,
@@ -24,7 +25,6 @@ import {
Worksheet_Visibility,
} from "@/types/proto-es/v1/worksheet_service_pb";
import {
- extractWorksheetConnection,
getSheetStatement,
isWorksheetReadableV1,
storageKeySqlEditorWorksheetFilter,