fix(tabs): allow saving a saved sql tab after clearing content

Closes #9247
This commit is contained in:
t8y2 authored and GitHub committed 2026-09-16 23:24:10 +08:00
1 parent 57e98b6d86
commit b891bf80fd
4 files changed
+66 -5

No files matched your search

@@ -0,0 +1,22 @@
import type { QueryTab } from "@/types/database";
/** Tab fields that decide whether its SQL can be persisted. */
export type SqlTabSaveTarget = Pick<QueryTab, "externalSqlPath" | "savedSqlId" | "sql" | "objectSource">;
/**
* Whether the tab's SQL can be saved at all.
*
* A tab that already has a persistence target — an external `.sql` file or a
* saved-SQL library entry — stays saveable after its content is emptied.
* Deleting everything is a legitimate edit that must reach the target, and the
* emptied state is also the only state in which the user can observe the guard.
*
* A brand-new tab has nothing to persist, and an emptied object-source tab would
* push a body-less `CREATE` for a routine or view to the server, so both keep the
* content requirement.
*/
export function canSaveSqlTab(tab: SqlTabSaveTarget): boolean {
if (tab.externalSqlPath || tab.sql.trim()) return true;
if (tab.objectSource) return false;
return !!tab.savedSqlId;
}