3 files changed
+87
-10
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import type { QueryTab, ColumnInfo } from "@/types/database";
|
||||
import { queryResultSourceNameParts } from "@/lib/sql/queryResultSource";
|
||||
import type { QueryTab, ColumnInfo, DatabaseType } from "@/types/database";
|
||||
|
||||
export type DataTabTableMeta = NonNullable<QueryTab["tableMeta"]>;
|
||||
|
||||
@@ -15,6 +16,34 @@ function titleTableName(tab: QueryTab): string {
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Repair the one legacy identity shape known to lose its schema during tab
|
||||
* restoration. PostgreSQL permits dots inside quoted identifiers, so the tab
|
||||
* title alone is deliberately not split. The persisted SELECT must independently
|
||||
* parse to the same schema-qualified source before the identity is migrated.
|
||||
*/
|
||||
export function repairRestoredDataTabTableIdentity(tab: QueryTab, databaseType: DatabaseType | undefined): boolean {
|
||||
if (databaseType !== "postgres" || tab.mode !== "data" || tab.schema?.trim() || tab.tableMeta?.schema?.trim() || tab.tableMeta?.columns.length) return false;
|
||||
|
||||
const sourceSql = tab.resultBaseSql?.trim() || tab.lastExecutedSql?.trim() || tab.sql.trim();
|
||||
const source = queryResultSourceNameParts(sourceSql, { databaseType });
|
||||
const title = tab.title.trim();
|
||||
if (!source?.qualifier || title !== `${source.qualifier}.${source.name}`) return false;
|
||||
|
||||
const persistedTableName = tab.tableMeta?.tableName.trim();
|
||||
if (persistedTableName && persistedTableName !== title && persistedTableName !== source.name) return false;
|
||||
|
||||
tab.schema = source.qualifier;
|
||||
tab.tableMeta = {
|
||||
...tab.tableMeta,
|
||||
schema: source.qualifier,
|
||||
tableName: source.name,
|
||||
columns: tab.tableMeta?.columns ?? [],
|
||||
primaryKeys: tab.tableMeta?.primaryKeys ?? [],
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
function fallbackColumnInfo(name: string): ColumnInfo {
|
||||
return {
|
||||
name,
|
||||
|
||||
Reference in new issue
Block a user