feat(xugu): discover and manage scheduler jobs
This commit is contained in:
1 parent
1c0e97b52a
commit
a849979dd1
28 files changed
+731
-42
No files matched your search
@@ -0,0 +1,15 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildXuguSchedulerJobSql } from "@/lib/database/xuguSchedulerJobSql";
|
||||
|
||||
describe("buildXuguSchedulerJobSql", () => {
|
||||
it("uses DBMS_SCHEDULER actions and safely quotes the job name", () => {
|
||||
expect(buildXuguSchedulerJobSql("enable", "nightly'load")).toBe("EXEC DBMS_SCHEDULER.ENABLE('nightly''load');");
|
||||
expect(buildXuguSchedulerJobSql("disable", "nightly")).toBe("EXEC DBMS_SCHEDULER.DISABLE('nightly', FALSE);");
|
||||
expect(buildXuguSchedulerJobSql("run", "nightly")).toBe("EXEC DBMS_SCHEDULER.RUN_JOB('nightly', TRUE);");
|
||||
expect(buildXuguSchedulerJobSql("drop", "nightly")).toBe("EXEC DBMS_SCHEDULER.DROP_JOB('nightly', FALSE);");
|
||||
});
|
||||
|
||||
it("refuses an empty scheduler job name", () => {
|
||||
expect(buildXuguSchedulerJobSql("enable", " ")).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { DatabaseType } from "@/types/database";
|
||||
|
||||
export type SidebarObjectKind = "TABLE" | "VIEW" | "MATERIALIZED_VIEW" | "PROCEDURE" | "FUNCTION" | "TRIGGER" | "EVENT" | "SEQUENCE" | "SYNONYM" | "PACKAGE" | "PACKAGE_BODY" | "TYPE" | "TYPE_BODY";
|
||||
export type SidebarObjectKind = "TABLE" | "VIEW" | "MATERIALIZED_VIEW" | "PROCEDURE" | "FUNCTION" | "TRIGGER" | "EVENT" | "SEQUENCE" | "SYNONYM" | "JOB" | "PACKAGE" | "PACKAGE_BODY" | "TYPE" | "TYPE_BODY";
|
||||
|
||||
export interface DatabaseObjectCapabilities {
|
||||
sidebarObjects: SidebarObjectKind[];
|
||||
@@ -168,6 +168,7 @@ export function normalizeSidebarObjectKind(type: string): SidebarObjectKind {
|
||||
if (value.includes("VIEW")) return "VIEW";
|
||||
if (value.includes("SEQ")) return "SEQUENCE";
|
||||
if (value.includes("SYNONYM")) return "SYNONYM";
|
||||
if (value.includes("JOB")) return "JOB";
|
||||
if (value.includes("PROC")) return "PROCEDURE";
|
||||
if (value.includes("FUNC")) return "FUNCTION";
|
||||
return "TABLE";
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
export type XuguSchedulerJobAction = "enable" | "disable" | "run" | "drop";
|
||||
|
||||
/**
|
||||
* Build the DBMS_SCHEDULER statements supported by the first Xugu job
|
||||
* management slice. Scheduler jobs are database-scoped; names are string
|
||||
* arguments rather than schema-qualified identifiers.
|
||||
*/
|
||||
export function buildXuguSchedulerJobSql(action: XuguSchedulerJobAction, name: string): string | null {
|
||||
const jobName = name.trim();
|
||||
if (!jobName) return null;
|
||||
const literal = quoteXuguString(jobName);
|
||||
switch (action) {
|
||||
case "enable":
|
||||
return `EXEC DBMS_SCHEDULER.ENABLE(${literal});`;
|
||||
case "disable":
|
||||
return `EXEC DBMS_SCHEDULER.DISABLE(${literal}, FALSE);`;
|
||||
case "run":
|
||||
return `EXEC DBMS_SCHEDULER.RUN_JOB(${literal}, TRUE);`;
|
||||
case "drop":
|
||||
return `EXEC DBMS_SCHEDULER.DROP_JOB(${literal}, FALSE);`;
|
||||
}
|
||||
}
|
||||
|
||||
function quoteXuguString(value: string): string {
|
||||
return `'${value.replaceAll("'", "''")}'`;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { isXuguPublicSynonymScope, isXuguPublicSynonymTreeNode, sortXuguSchemaInfos, XUGU_PUBLIC_SYNONYM_SCOPE, xuguSchemaDisplayName } from "@/lib/sidebar/xuguPublicSynonyms";
|
||||
import { isXuguPublicSynonymScope, isXuguPublicSynonymTreeNode, isXuguSchedulerJobScope, isXuguSyntheticTreeNode, sortXuguSchemaInfos, XUGU_PUBLIC_SYNONYM_SCOPE, XUGU_SCHEDULER_JOB_SCOPE, xuguSchemaDisplayName } from "@/lib/sidebar/xuguPublicSynonyms";
|
||||
import { compareSidebarNames } from "@/lib/database/databaseTree";
|
||||
|
||||
describe("Xugu public synonym scope", () => {
|
||||
@@ -35,6 +35,15 @@ describe("Xugu public synonym scope", () => {
|
||||
expect(sortXuguSchemaInfos(schemas, compareSidebarNames).map((schema) => schema.name)).toEqual(["AppSchema", "GUEST", "SYSDBA", XUGU_PUBLIC_SYNONYM_SCOPE]);
|
||||
});
|
||||
|
||||
it("places the database-scoped scheduler root after real schemas and public synonyms", () => {
|
||||
const schemas = [{ name: XUGU_SCHEDULER_JOB_SCOPE }, { name: "APP_TEST" }, { name: XUGU_PUBLIC_SYNONYM_SCOPE }];
|
||||
|
||||
expect(isXuguSchedulerJobScope(XUGU_SCHEDULER_JOB_SCOPE)).toBe(true);
|
||||
expect(xuguSchemaDisplayName(XUGU_SCHEDULER_JOB_SCOPE)).toBe("Scheduled jobs");
|
||||
expect(isXuguSyntheticTreeNode("xugu", "schema", XUGU_SCHEDULER_JOB_SCOPE)).toBe(true);
|
||||
expect(sortXuguSchemaInfos(schemas, compareSidebarNames).map((schema) => schema.name)).toEqual(["APP_TEST", XUGU_PUBLIC_SYNONYM_SCOPE, XUGU_SCHEDULER_JOB_SCOPE]);
|
||||
});
|
||||
|
||||
it("does not treat the real GUEST schema as a public-synonym scope", () => {
|
||||
const schemas = [{ name: "GUEST" }, { name: XUGU_PUBLIC_SYNONYM_SCOPE }];
|
||||
expect(sortXuguSchemaInfos(schemas, compareSidebarNames).map((schema) => schema.name)).toEqual(["GUEST", XUGU_PUBLIC_SYNONYM_SCOPE]);
|
||||
|
||||
@@ -55,10 +55,24 @@ const objectBrowserNodeTypes = new Set<TreeNodeType>(["database", "schema", "obj
|
||||
export function shouldOpenObjectBrowserOnSingleClick(type: TreeNodeType, enabled: boolean): boolean {
|
||||
return enabled && objectBrowserNodeTypes.has(type);
|
||||
}
|
||||
const sourceNodeTypes = new Set<TreeNodeType>(["materialized_view", "procedure", "function", "trigger", "event", "sequence", "synonym", "package", "package-body", "type", "type-body"]);
|
||||
const sourceNodeTypes = new Set<TreeNodeType>(["materialized_view", "procedure", "function", "trigger", "event", "sequence", "synonym", "job", "package", "package-body", "type", "type-body"]);
|
||||
const savedSqlNodeTypes = new Set<TreeNodeType>(["saved-sql-file"]);
|
||||
const tableChildGroupNodeTypes = new Set<TreeNodeType>(["group-columns", "group-indexes", "group-fkeys", "group-triggers", "group-constraints", "group-partitions", "group-table-partitions", "group-table-subpartitions"]);
|
||||
const databaseChildGroupNodeTypes = new Set<TreeNodeType>(["group-tables", "group-dolt-system-tables", "group-views", "group-materialized-views", "group-procedures", "group-functions", "group-triggers", "group-events", "group-sequences", "group-synonyms", "group-packages", "group-types"]);
|
||||
const databaseChildGroupNodeTypes = new Set<TreeNodeType>([
|
||||
"group-tables",
|
||||
"group-dolt-system-tables",
|
||||
"group-views",
|
||||
"group-materialized-views",
|
||||
"group-procedures",
|
||||
"group-functions",
|
||||
"group-triggers",
|
||||
"group-events",
|
||||
"group-sequences",
|
||||
"group-synonyms",
|
||||
"group-jobs",
|
||||
"group-packages",
|
||||
"group-types",
|
||||
]);
|
||||
const displayPathObjectNodeTypes = new Set<TreeNodeType>(["table", "view", "materialized_view", "procedure", "function", "trigger", "event"]);
|
||||
|
||||
export function objectSourceKindForTreeNode(type: TreeNodeType): ObjectSourceKind | null {
|
||||
@@ -70,6 +84,7 @@ export function objectSourceKindForTreeNode(type: TreeNodeType): ObjectSourceKin
|
||||
if (type === "event") return "EVENT";
|
||||
if (type === "sequence") return "SEQUENCE";
|
||||
if (type === "synonym") return "SYNONYM";
|
||||
if (type === "job") return "JOB";
|
||||
if (type === "package") return "PACKAGE";
|
||||
if (type === "package-body") return "PACKAGE_BODY";
|
||||
if (type === "type") return "TYPE";
|
||||
|
||||
@@ -17,6 +17,7 @@ const treeGroupNodeTypes = new Set<TreeNodeType>([
|
||||
"group-functions",
|
||||
"group-sequences",
|
||||
"group-synonyms",
|
||||
"group-jobs",
|
||||
"group-packages",
|
||||
"group-types",
|
||||
"group-partitions",
|
||||
|
||||
@@ -112,6 +112,8 @@ export function getTreeNodeIconInfo(node: TreeNode): TreeNodeIconInfo | null {
|
||||
return { icon: ListTree, colorClass: "text-emerald-500" };
|
||||
case "synonym":
|
||||
return { icon: Link2, colorClass: "text-sky-500" };
|
||||
case "job":
|
||||
return { icon: Clock, colorClass: "text-orange-400" };
|
||||
case "package":
|
||||
return { icon: Package, colorClass: "text-cyan-500" };
|
||||
case "package-body":
|
||||
@@ -132,6 +134,8 @@ export function getTreeNodeIconInfo(node: TreeNode): TreeNodeIconInfo | null {
|
||||
return { icon: ListTree, colorClass: "text-emerald-500" };
|
||||
case "group-synonyms":
|
||||
return { icon: Link2, colorClass: "text-sky-500" };
|
||||
case "group-jobs":
|
||||
return { icon: Clock, colorClass: "text-orange-400" };
|
||||
case "group-packages":
|
||||
return { icon: Package, colorClass: "text-cyan-500" };
|
||||
case "group-partitions":
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
*/
|
||||
export const XUGU_PUBLIC_SYNONYM_SCOPE = "\u0000DBX_XUGU_PUBLIC_SYNONYMS";
|
||||
export const XUGU_PUBLIC_SYNONYM_SCOPE_LABEL = "Public synonyms";
|
||||
export const XUGU_SCHEDULER_JOB_SCOPE = "\u0000DBX_XUGU_SCHEDULER_JOBS";
|
||||
export const XUGU_SCHEDULER_JOB_SCOPE_LABEL = "Scheduled jobs";
|
||||
|
||||
/**
|
||||
* Keep the synthetic public-synonym scope visually separate from real
|
||||
@@ -14,27 +16,48 @@ export const XUGU_PUBLIC_SYNONYM_SCOPE_LABEL = "Public synonyms";
|
||||
export function sortXuguSchemaInfos<T extends { name: string }>(schemas: readonly T[], compareNames: (left: string, right: string) => number): T[] {
|
||||
const realSchemas: T[] = [];
|
||||
const publicSynonymScopes: T[] = [];
|
||||
const schedulerJobScopes: T[] = [];
|
||||
|
||||
for (const schema of schemas) {
|
||||
if (isXuguPublicSynonymScope(schema.name)) {
|
||||
publicSynonymScopes.push(schema);
|
||||
} else if (isXuguSchedulerJobScope(schema.name)) {
|
||||
schedulerJobScopes.push(schema);
|
||||
} else {
|
||||
realSchemas.push(schema);
|
||||
}
|
||||
}
|
||||
|
||||
realSchemas.sort((left, right) => compareNames(left.name, right.name));
|
||||
return [...realSchemas, ...publicSynonymScopes];
|
||||
return [...realSchemas, ...publicSynonymScopes, ...schedulerJobScopes];
|
||||
}
|
||||
|
||||
export function isXuguPublicSynonymScope(schema: string | null | undefined): boolean {
|
||||
return schema === XUGU_PUBLIC_SYNONYM_SCOPE;
|
||||
}
|
||||
|
||||
export function isXuguSchedulerJobScope(schema: string | null | undefined): boolean {
|
||||
return schema === XUGU_SCHEDULER_JOB_SCOPE;
|
||||
}
|
||||
|
||||
export function isXuguSyntheticScope(schema: string | null | undefined): boolean {
|
||||
return isXuguPublicSynonymScope(schema) || isXuguSchedulerJobScope(schema);
|
||||
}
|
||||
|
||||
export function xuguSchemaDisplayName(schema: string): string {
|
||||
return isXuguPublicSynonymScope(schema) ? XUGU_PUBLIC_SYNONYM_SCOPE_LABEL : schema;
|
||||
if (isXuguPublicSynonymScope(schema)) return XUGU_PUBLIC_SYNONYM_SCOPE_LABEL;
|
||||
if (isXuguSchedulerJobScope(schema)) return XUGU_SCHEDULER_JOB_SCOPE_LABEL;
|
||||
return schema;
|
||||
}
|
||||
|
||||
export function isXuguPublicSynonymTreeNode(databaseType: string | null | undefined, nodeType: string, schema: string | null | undefined): boolean {
|
||||
return databaseType === "xugu" && nodeType === "schema" && isXuguPublicSynonymScope(schema);
|
||||
}
|
||||
|
||||
export function isXuguSchedulerJobTreeNode(databaseType: string | null | undefined, nodeType: string, schema: string | null | undefined): boolean {
|
||||
return databaseType === "xugu" && nodeType === "schema" && isXuguSchedulerJobScope(schema);
|
||||
}
|
||||
|
||||
export function isXuguSyntheticTreeNode(databaseType: string | null | undefined, nodeType: string, schema: string | null | undefined): boolean {
|
||||
return databaseType === "xugu" && nodeType === "schema" && isXuguSyntheticScope(schema);
|
||||
}
|
||||
@@ -774,6 +774,13 @@ const groupDefs: Array<{
|
||||
nodeType: "group-synonyms",
|
||||
childType: "synonym",
|
||||
},
|
||||
{
|
||||
key: "__jobs",
|
||||
label: "tree.schedulerJobs",
|
||||
objectTypes: ["JOB"],
|
||||
nodeType: "group-jobs",
|
||||
childType: "job",
|
||||
},
|
||||
{
|
||||
key: "__packages",
|
||||
label: "tree.packages",
|
||||
@@ -790,7 +797,7 @@ const groupDefs: Array<{
|
||||
},
|
||||
];
|
||||
|
||||
const objectGroupNodeTypes = new Set<TreeNodeType>(["group-tables", "group-dolt-system-tables", "group-views", "group-materialized-views", "group-procedures", "group-functions", "group-triggers", "group-events", "group-sequences", "group-synonyms", "group-packages", "group-types"]);
|
||||
const objectGroupNodeTypes = new Set<TreeNodeType>(["group-tables", "group-dolt-system-tables", "group-views", "group-materialized-views", "group-procedures", "group-functions", "group-triggers", "group-events", "group-sequences", "group-synonyms", "group-jobs", "group-packages", "group-types"]);
|
||||
|
||||
export function buildObjectGroupPlaceholderNodes({
|
||||
nodeId,
|
||||
|
||||
Reference in new issue
Block a user