feat(dameng): show view validity and support recompilation
This commit is contained in:
1 parent
e4bda693fb
commit
6b81a98453
71 files changed
+1040
-38
No files matched your search
@@ -0,0 +1,20 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildDamengCompileViewSql } from "@/lib/database/damengCompileSql";
|
||||
|
||||
describe("buildDamengCompileViewSql", () => {
|
||||
it("quotes schema and view identifiers", () => {
|
||||
expect(buildDamengCompileViewSql({ schema: "APP", name: "ACTIVE_VIEW" })).toBe('ALTER VIEW "APP"."ACTIVE_VIEW" COMPILE;');
|
||||
});
|
||||
|
||||
it("escapes embedded double quotes", () => {
|
||||
expect(buildDamengCompileViewSql({ schema: 'APP"DATA', name: 'V"ACTIVE' })).toBe('ALTER VIEW "APP""DATA"."V""ACTIVE" COMPILE;');
|
||||
});
|
||||
|
||||
it("allows a database-level name when no schema is supplied", () => {
|
||||
expect(buildDamengCompileViewSql({ name: "ACTIVE_VIEW" })).toBe('ALTER VIEW "ACTIVE_VIEW" COMPILE;');
|
||||
});
|
||||
|
||||
it("rejects a blank view name", () => {
|
||||
expect(buildDamengCompileViewSql({ schema: "APP", name: " " })).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -25,6 +25,20 @@ describe("buildObjectBrowserRows", () => {
|
||||
|
||||
expect(rows[0]?.schema).toBeUndefined();
|
||||
});
|
||||
|
||||
it("preserves nullable view validity in browser rows", () => {
|
||||
const rows = buildObjectBrowserRows({
|
||||
objects: [
|
||||
{ name: "valid_view", object_type: "VIEW", valid: true },
|
||||
{ name: "invalid_view", object_type: "VIEW", valid: false },
|
||||
{ name: "unknown_view", object_type: "VIEW", valid: null },
|
||||
],
|
||||
database: "app",
|
||||
fallbackSchema: "app",
|
||||
});
|
||||
|
||||
expect(rows.map((row) => row.valid)).toEqual([true, false, null]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Object Browser pinned ordering", () => {
|
||||
|
||||
@@ -38,6 +38,40 @@ describe("case-sensitive database objects", () => {
|
||||
expect(new Set(viewGroup?.children?.map((node) => node.id) ?? []).size).toBe(2);
|
||||
});
|
||||
|
||||
it("preserves view validity in simple and grouped trees", () => {
|
||||
const objects: ObjectInfo[] = [
|
||||
{ name: "VALID_VIEW", object_type: "VIEW", schema: "dbx_test", valid: true },
|
||||
{ name: "INVALID_VIEW", object_type: "VIEW", schema: "dbx_test", valid: false },
|
||||
];
|
||||
|
||||
const simple = buildSimpleObjectTreeNodes({ ...context, schema: "dbx_test", objects });
|
||||
expect(simple.map((node) => node.valid)).toEqual([false, true]);
|
||||
|
||||
const grouped = buildGroupedObjectTreeNodes({ ...context, schema: "dbx_test", objects });
|
||||
expect(grouped.find((node) => node.type === "group-views")?.children?.map((node) => node.valid)).toEqual([false, true]);
|
||||
});
|
||||
|
||||
it("preserves view validity when building the table-like tree path", () => {
|
||||
const tables: TableInfo[] = [
|
||||
{ name: "VALID_VIEW", table_type: "VIEW", valid: true },
|
||||
{ name: "INVALID_VIEW", table_type: "VIEW", valid: false },
|
||||
];
|
||||
const nodes = buildTableTreeNodes({
|
||||
...context,
|
||||
schema: "dbx_test",
|
||||
tables,
|
||||
});
|
||||
|
||||
expect(nodes.map((node) => node.valid)).toEqual([false, true]);
|
||||
|
||||
const grouped = buildGroupedObjectTreeNodes({
|
||||
...context,
|
||||
schema: "dbx_test",
|
||||
objects: mergeTableInfosIntoObjects([], tables, "dbx_test"),
|
||||
});
|
||||
expect(grouped.find((node) => node.type === "group-views")?.children?.map((node) => node.valid)).toEqual([false, true]);
|
||||
});
|
||||
|
||||
it("keeps table nodes whose names differ only by case across pages", () => {
|
||||
const firstPage = buildTableTreeNodes({
|
||||
...context,
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
export interface DamengCompileViewSqlInput {
|
||||
schema?: string | null;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export function buildDamengCompileViewSql(input: DamengCompileViewSqlInput): string | null {
|
||||
const name = input.name.trim();
|
||||
if (!name) return null;
|
||||
const schema = input.schema?.trim();
|
||||
const qualifiedName = schema ? `${quoteDamengIdentifier(schema)}.${quoteDamengIdentifier(name)}` : quoteDamengIdentifier(name);
|
||||
return `ALTER VIEW ${qualifiedName} COMPILE;`;
|
||||
}
|
||||
|
||||
function quoteDamengIdentifier(value: string): string {
|
||||
return `"${value.replaceAll('"', '""')}"`;
|
||||
}
|
||||
@@ -121,6 +121,7 @@ export function objectBrowserRowLegacyPinnedTreeNodeIds(row: ObjectBrowserRow, c
|
||||
{
|
||||
name: row.name,
|
||||
table_type: row.type,
|
||||
valid: row.valid,
|
||||
comment: row.comment,
|
||||
parent_schema: row.partitionParentSchema,
|
||||
parent_name: row.partitionParentName,
|
||||
|
||||
@@ -24,6 +24,7 @@ export function buildTableTreeNodes({ nodeId, connectionId, database, schema, ta
|
||||
objectType,
|
||||
tableType: table.table_type,
|
||||
comment: table.comment,
|
||||
valid: table.valid,
|
||||
parentSchema: table.parent_schema,
|
||||
parentName: table.parent_name,
|
||||
catalog,
|
||||
@@ -53,6 +54,7 @@ function makeTableTreeEntry({
|
||||
objectType,
|
||||
tableType,
|
||||
comment,
|
||||
valid,
|
||||
parentSchema,
|
||||
parentName,
|
||||
catalog,
|
||||
@@ -66,6 +68,7 @@ function makeTableTreeEntry({
|
||||
objectType: DatabaseObjectTreeKind;
|
||||
tableType?: string;
|
||||
comment?: string | null;
|
||||
valid?: boolean | null;
|
||||
parentSchema?: string | null;
|
||||
parentName?: string | null;
|
||||
catalog?: string;
|
||||
@@ -79,6 +82,7 @@ function makeTableTreeEntry({
|
||||
type: objectType === "VIEW" ? ("view" as const) : objectType === "MATERIALIZED_VIEW" ? ("materialized_view" as const) : ("table" as const),
|
||||
tableType,
|
||||
comment,
|
||||
valid,
|
||||
connectionId,
|
||||
database,
|
||||
schema,
|
||||
@@ -248,6 +252,9 @@ export function mergeTableInfosIntoObjects(objects: readonly ObjectInfo[], table
|
||||
if (matchingObject && table.comment && !matchingObject.comment) {
|
||||
matchingObject.comment = table.comment;
|
||||
}
|
||||
if (matchingObject && matchingObject.valid == null && table.valid != null) {
|
||||
matchingObject.valid = table.valid;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
seen.add(key);
|
||||
@@ -257,6 +264,7 @@ export function mergeTableInfosIntoObjects(objects: readonly ObjectInfo[], table
|
||||
// downstream template strategies can distinguish special table kinds.
|
||||
object_type: table.table_type,
|
||||
schema: tableSchema,
|
||||
valid: table.valid,
|
||||
comment: table.comment,
|
||||
created_at: undefined,
|
||||
updated_at: undefined,
|
||||
@@ -541,6 +549,7 @@ function buildObjectTreeEntries({ nodeId, connectionId, database, schema, object
|
||||
objectType,
|
||||
tableType: obj.object_type,
|
||||
comment: obj.comment,
|
||||
valid: obj.valid,
|
||||
parentSchema: obj.parent_schema,
|
||||
parentName: obj.parent_name,
|
||||
}),
|
||||
@@ -658,6 +667,7 @@ export function buildSimpleObjectTreeNodes({ nodeId, connectionId, database, sch
|
||||
objectType,
|
||||
tableType: obj.object_type,
|
||||
comment: obj.comment,
|
||||
valid: obj.valid,
|
||||
parentSchema: obj.parent_schema,
|
||||
parentName: obj.parent_name,
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user