1 parent
e0be55ddf3
commit
3e9c383732
4 files changed
+109
-8
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
DBX_NEO4J_ELEMENT_ID_COLUMN,
|
||||
DBX_ROWID_COLUMN,
|
||||
DBX_TDENGINE_TBNAME_COLUMN,
|
||||
canDeleteExistingTdengineRows,
|
||||
@@ -75,6 +76,25 @@ describe("tableEditing", () => {
|
||||
expect(editableRowIdentifierColumns("postgres", [column("id", true), column("email")], [index(["email"])])).toEqual(["id"]);
|
||||
});
|
||||
|
||||
it.each(["oracle", "oceanbase-oracle"] as const)("prefers physical %s indexes over the ROWID fallback", (databaseType) => {
|
||||
const columns = [column("OFFER_RELA_ID"), column("ORI_OFFER_ID")];
|
||||
const primaryIndex = { ...index(["OFFER_RELA_ID"], false), is_primary: true };
|
||||
|
||||
expect(editableRowIdentifierColumns(databaseType, columns, [index(["ORI_OFFER_ID"]), primaryIndex], "TABLE")).toEqual(["OFFER_RELA_ID"]);
|
||||
expect(editableRowIdentifierColumns(databaseType, columns, [index(["ORI_OFFER_ID"])], "TABLE")).toEqual(["ORI_OFFER_ID"]);
|
||||
expect(editableRowIdentifierColumns(databaseType, columns, [index(["ORI_OFFER_ID"], false)], "TABLE")).toEqual([DBX_ROWID_COLUMN]);
|
||||
expect(editableRowIdentifierColumns(databaseType, columns, [index(["ORI_OFFER_ID"], true, "ORI_OFFER_ID IS NOT NULL")], "TABLE")).toEqual([DBX_ROWID_COLUMN]);
|
||||
expect(editableRowIdentifierColumns(databaseType, columns, [], "TABLE")).toEqual([DBX_ROWID_COLUMN]);
|
||||
});
|
||||
|
||||
it("keeps synthetic row identifiers scoped to their existing fallbacks", () => {
|
||||
const columns = [column("ID"), column("NAME")];
|
||||
|
||||
expect(editableRowIdentifierColumns("oracle", columns, [], "VIEW")).toEqual([]);
|
||||
expect(editableRowIdentifierColumns("oracle", columns, [], "MATERIALIZED_VIEW")).toEqual([]);
|
||||
expect(editableRowIdentifierColumns("neo4j", columns, [index(["ID"])], "TABLE")).toEqual([DBX_NEO4J_ELEMENT_ID_COLUMN]);
|
||||
});
|
||||
|
||||
it("allows ClickHouse table editing when row identifiers are available", () => {
|
||||
expect(isTableDataEditable("clickhouse", ["id"], "BASE TABLE")).toBe(true);
|
||||
expect(canEditExistingTableRows("clickhouse", undefined, ["id"])).toBe(true);
|
||||
|
||||
@@ -26,9 +26,10 @@ export function editablePrimaryKeys(databaseType: DatabaseType | undefined, colu
|
||||
|
||||
export function editableRowIdentifierColumns(databaseType: DatabaseType | undefined, columns: ColumnInfo[], indexes?: IndexInfo[], tableType?: string): string[] {
|
||||
const primaryKeys = editablePrimaryKeys(databaseType, columns, tableType);
|
||||
if (primaryKeys.length > 0) return primaryKeys;
|
||||
const oracleRowIdFallback = getDatabaseCapability(databaseType).syntheticKey === "oracle-rowid" && primaryKeys.length === 1 && primaryKeys[0]?.toUpperCase() === DBX_ROWID_COLUMN;
|
||||
if (primaryKeys.length > 0 && !oracleRowIdFallback) return primaryKeys;
|
||||
const uniqueIndex = indexes?.filter((index) => !index.filter && index.columns.length > 0 && (index.is_primary || index.is_unique)).sort((left, right) => Number(right.is_primary) - Number(left.is_primary) || left.columns.length - right.columns.length)[0];
|
||||
return uniqueIndex?.columns ?? [];
|
||||
return uniqueIndex?.columns ?? primaryKeys;
|
||||
}
|
||||
|
||||
export function isTableDataEditable(databaseType: DatabaseType | undefined, primaryKeys: string[], tableType?: string): boolean {
|
||||
|
||||
Reference in new issue
Block a user