fix(sql): restore SQL file schema for sidebar locate
This commit is contained in:
1 parent
440c41f5b9
commit
e9a90173a6
11 files changed
+175
-53
No files matched your search
@@ -1260,7 +1260,7 @@ async function writeExternalSqlTab(tab: QueryTab, options: { closeAfterSave?: bo
|
||||
expectedMissing: options.expectedMissing,
|
||||
});
|
||||
if (result.kind !== "written") return "retry";
|
||||
rememberExternalSqlFileTarget(tab.externalSqlPath, { connectionId: tab.connectionId, database: tab.database, catalog: tab.catalog });
|
||||
rememberExternalSqlFileTarget(tab.externalSqlPath, { connectionId: tab.connectionId, database: tab.database, catalog: tab.catalog, schema: tab.schema });
|
||||
queryStore.markExternalSqlFileSaved(tab.id, result.version);
|
||||
toast(t("savedSql.saved"), 2000);
|
||||
if (options.closeAfterSave) queryStore.closeTab(tab.id, { force: true });
|
||||
@@ -1593,7 +1593,7 @@ async function saveExternalSqlTabAs(tab: QueryTab): Promise<boolean> {
|
||||
const saved = await api.saveExternalSqlFile(defaultSavedSqlName(tab.title), await formattedSqlForSave(tab));
|
||||
if (!saved) return false;
|
||||
queryStore.linkExternalSqlPath(tab.id, saved.path, sqlFileTitleFromPath(saved.path), saved.version);
|
||||
rememberExternalSqlFileTarget(saved.path, { connectionId: tab.connectionId, database: tab.database, catalog: tab.catalog });
|
||||
rememberExternalSqlFileTarget(saved.path, { connectionId: tab.connectionId, database: tab.database, catalog: tab.catalog, schema: tab.schema });
|
||||
invalidateSaveSqlFolderSelection();
|
||||
showSaveSqlDialog.value = false;
|
||||
closePendingSavedTab();
|
||||
@@ -1619,6 +1619,9 @@ function applyExternalSqlFileTarget(tab: QueryTab, path: string) {
|
||||
if (target.catalog !== undefined || tab.catalog !== undefined) queryStore.updateCatalog(tab.id, target.catalog, target.database);
|
||||
else queryStore.updateDatabase(tab.id, target.database);
|
||||
}
|
||||
// updateConnection/updateCatalog/updateDatabase all reset the schema, so the
|
||||
// remembered schema has to be reapplied after them.
|
||||
if (target.schema !== tab.schema) queryStore.updateSchema(tab.id, target.schema);
|
||||
}
|
||||
|
||||
async function openSqlFile() {
|
||||
@@ -1689,7 +1692,7 @@ async function openSqlFilePath(path: string) {
|
||||
await desktopOpenTabsRestorationBarrier?.settled;
|
||||
const snapshot = await api.readExternalSqlFileSnapshot(path);
|
||||
const target = resolveExternalSqlFileTarget(path, (savedConnectionId) => !!connectionStore.getConfig(savedConnectionId), unassociatedExternalSqlFileTarget());
|
||||
queryStore.openExternalSqlFile(target.connectionId, target.database, path, snapshot.content, snapshot.version, target.catalog);
|
||||
queryStore.openExternalSqlFile(target.connectionId, target.database, path, snapshot.content, snapshot.version, target.catalog, target.schema);
|
||||
} catch (e: any) {
|
||||
toast(t("toolbar.sqlOpenFailed", { message: externalSqlFileOpenErrorMessage(e, (key, params) => t(key, params)) }), 5000);
|
||||
}
|
||||
@@ -2146,14 +2149,14 @@ async function changeActiveConnection(connectionId: string) {
|
||||
if (!connection) return;
|
||||
const initialDatabase = resolveDefaultDatabase(connection, []);
|
||||
queryStore.updateConnection(tab.id, connectionId, initialDatabase);
|
||||
if (tab.externalSqlPath) rememberExternalSqlFileTarget(tab.externalSqlPath, { connectionId, database: initialDatabase, catalog: undefined });
|
||||
if (tab.externalSqlPath) rememberExternalSqlFileTarget(tab.externalSqlPath, { connectionId, database: initialDatabase, catalog: undefined, schema: undefined });
|
||||
connectionStore.activeConnectionId = connectionId;
|
||||
try {
|
||||
await connectionStore.ensureConnected(connectionId);
|
||||
const options = await getDatabaseOptions(connectionId);
|
||||
const database = resolveDefaultDatabase(connection, options);
|
||||
queryStore.updateDatabase(tab.id, database);
|
||||
if (tab.externalSqlPath) rememberExternalSqlFileTarget(tab.externalSqlPath, { connectionId, database, catalog: undefined });
|
||||
if (tab.externalSqlPath) rememberExternalSqlFileTarget(tab.externalSqlPath, { connectionId, database, catalog: undefined, schema: undefined });
|
||||
if (connection.default_schema || connection.db_type === "oracle") {
|
||||
try {
|
||||
// A configured default wins. Otherwise Oracle returns the session's current schema first.
|
||||
@@ -2161,6 +2164,7 @@ async function changeActiveConnection(connectionId: string) {
|
||||
const schema = schemaAfterConnectionSwitch(connection.db_type, orderedSchemas, connection.default_schema);
|
||||
if (schema && activeTab.value?.id === tab.id && activeTab.value.connectionId === connectionId) {
|
||||
queryStore.updateSchema(tab.id, schema);
|
||||
if (tab.externalSqlPath) rememberExternalSqlFileTarget(tab.externalSqlPath, { connectionId, database, catalog: undefined, schema });
|
||||
}
|
||||
} catch {
|
||||
// Schema metadata failure must not turn a successful connection switch into a connection error.
|
||||
@@ -2180,7 +2184,7 @@ function changeActiveDatabase(database: string) {
|
||||
const tab = activeTab.value;
|
||||
if (tab) {
|
||||
queryStore.updateDatabase(tab.id, database);
|
||||
if (tab.externalSqlPath) rememberExternalSqlFileTarget(tab.externalSqlPath, { connectionId: tab.connectionId, database, catalog: tab.catalog });
|
||||
if (tab.externalSqlPath) rememberExternalSqlFileTarget(tab.externalSqlPath, { connectionId: tab.connectionId, database, catalog: tab.catalog, schema: tab.schema });
|
||||
if (databaseRequiredTabId.value === tab.id && database) {
|
||||
databaseRequiredTabId.value = null;
|
||||
}
|
||||
@@ -2191,7 +2195,7 @@ function changeActiveCatalog(catalog: string | undefined, database: string) {
|
||||
const tab = activeTab.value;
|
||||
if (tab) {
|
||||
queryStore.updateCatalog(tab.id, catalog, database);
|
||||
if (tab.externalSqlPath) rememberExternalSqlFileTarget(tab.externalSqlPath, { connectionId: tab.connectionId, database, catalog });
|
||||
if (tab.externalSqlPath) rememberExternalSqlFileTarget(tab.externalSqlPath, { connectionId: tab.connectionId, database, catalog, schema: tab.schema });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2209,7 +2213,9 @@ async function clearActiveDefaultDatabase() {
|
||||
|
||||
function changeActiveSchema(schema: string | undefined) {
|
||||
const tab = activeTab.value;
|
||||
if (tab) queryStore.updateSchema(tab.id, schema);
|
||||
if (!tab) return;
|
||||
queryStore.updateSchema(tab.id, schema);
|
||||
if (tab.externalSqlPath) rememberExternalSqlFileTarget(tab.externalSqlPath, { connectionId: tab.connectionId, database: tab.database, catalog: tab.catalog, schema });
|
||||
}
|
||||
|
||||
function openGitHub() {
|
||||
@@ -2332,7 +2338,7 @@ async function handleQuickOpenSelect(item: any) {
|
||||
try {
|
||||
const snapshot = await api.readExternalSqlFileSnapshot(item.filePath);
|
||||
const target = resolveExternalSqlFileTarget(item.filePath, (savedConnectionId) => !!connectionStore.getConfig(savedConnectionId), unassociatedExternalSqlFileTarget());
|
||||
queryStore.openExternalSqlFile(target.connectionId, target.database, item.filePath, snapshot.content, snapshot.version, target.catalog);
|
||||
queryStore.openExternalSqlFile(target.connectionId, target.database, item.filePath, snapshot.content, snapshot.version, target.catalog, target.schema);
|
||||
} catch (e: any) {
|
||||
toast(
|
||||
externalSqlFileOpenErrorMessage(e, (key, params) => t(key, params)),
|
||||
|
||||
Reference in new issue
Block a user