feat(oracle): show table constraints in structure editor
This commit is contained in:
1 parent
76b8f2f54b
commit
f9c4f290f5
19 files changed
+413
-20
No files matched your search
@@ -7,8 +7,15 @@ describe("tableMetadataCapabilities", () => {
|
||||
columns: false,
|
||||
indexes: true,
|
||||
foreignKeys: false,
|
||||
constraints: false,
|
||||
triggers: false,
|
||||
ddl: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("exposes structured constraints only for dialects that implement list_constraints", () => {
|
||||
expect(getTableMetadataCapabilities("oracle").constraints).toBe(true);
|
||||
expect(getTableMetadataCapabilities("mysql").constraints).toBe(false);
|
||||
expect(getTableMetadataCapabilities(undefined).constraints).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -4,6 +4,7 @@ export interface TableMetadataCapabilities {
|
||||
columns: boolean;
|
||||
indexes: boolean;
|
||||
foreignKeys: boolean;
|
||||
constraints: boolean;
|
||||
triggers: boolean;
|
||||
ddl: boolean;
|
||||
}
|
||||
@@ -12,11 +13,18 @@ const defaultCapabilities: TableMetadataCapabilities = {
|
||||
columns: true,
|
||||
indexes: true,
|
||||
foreignKeys: true,
|
||||
// Structured PK/UNIQUE/CHECK constraint metadata (list_constraints) is only
|
||||
// implemented by a handful of agent-backed drivers today; leave it off by
|
||||
// default so every other dialect doesn't grow a permanently empty tab.
|
||||
constraints: false,
|
||||
triggers: true,
|
||||
ddl: true,
|
||||
};
|
||||
|
||||
const capabilityByType: Partial<Record<DatabaseType, Partial<TableMetadataCapabilities>>> = {
|
||||
oracle: {
|
||||
constraints: true,
|
||||
},
|
||||
mongodb: {
|
||||
columns: false,
|
||||
foreignKeys: false,
|
||||
@@ -108,11 +116,19 @@ export function firstStructureMetadataTab(capabilities: TableMetadataCapabilitie
|
||||
if (capabilities.columns) return "columns";
|
||||
if (capabilities.indexes) return "indexes";
|
||||
if (capabilities.foreignKeys) return "foreignKeys";
|
||||
if (capabilities.constraints) return "constraints";
|
||||
if (capabilities.triggers) return "triggers";
|
||||
if (!isCreateMode && capabilities.ddl) return "ddl";
|
||||
return "columns";
|
||||
}
|
||||
|
||||
export function isStructureMetadataTabSupported(tab: TableInfoTab, capabilities: TableMetadataCapabilities, isCreateMode: boolean): boolean {
|
||||
return (tab === "columns" && capabilities.columns) || (tab === "indexes" && capabilities.indexes) || (tab === "foreignKeys" && capabilities.foreignKeys) || (tab === "triggers" && capabilities.triggers) || (tab === "ddl" && capabilities.ddl && !isCreateMode);
|
||||
return (
|
||||
(tab === "columns" && capabilities.columns) ||
|
||||
(tab === "indexes" && capabilities.indexes) ||
|
||||
(tab === "foreignKeys" && capabilities.foreignKeys) ||
|
||||
(tab === "constraints" && capabilities.constraints) ||
|
||||
(tab === "triggers" && capabilities.triggers) ||
|
||||
(tab === "ddl" && capabilities.ddl && !isCreateMode)
|
||||
);
|
||||
}
|
||||
@@ -5,6 +5,7 @@ export interface TableStructureRefreshScope {
|
||||
columns: boolean;
|
||||
indexes: boolean;
|
||||
foreignKeys: boolean;
|
||||
constraints: boolean;
|
||||
triggers: boolean;
|
||||
tableComment: boolean;
|
||||
}
|
||||
@@ -12,15 +13,17 @@ export interface TableStructureRefreshScope {
|
||||
export function visibleTableStructureRefreshScope(activeTab: TableInfoTab): TableStructureRefreshScope {
|
||||
switch (activeTab) {
|
||||
case "columns":
|
||||
return { columns: true, indexes: false, foreignKeys: false, triggers: false, tableComment: true };
|
||||
return { columns: true, indexes: false, foreignKeys: false, constraints: false, triggers: false, tableComment: true };
|
||||
case "indexes":
|
||||
return { columns: true, indexes: true, foreignKeys: false, triggers: false, tableComment: true };
|
||||
return { columns: true, indexes: true, foreignKeys: false, constraints: false, triggers: false, tableComment: true };
|
||||
case "foreignKeys":
|
||||
return { columns: true, indexes: false, foreignKeys: true, triggers: false, tableComment: true };
|
||||
return { columns: true, indexes: false, foreignKeys: true, constraints: false, triggers: false, tableComment: true };
|
||||
case "constraints":
|
||||
return { columns: false, indexes: false, foreignKeys: false, constraints: true, triggers: false, tableComment: true };
|
||||
case "triggers":
|
||||
return { columns: false, indexes: false, foreignKeys: false, triggers: true, tableComment: true };
|
||||
return { columns: false, indexes: false, foreignKeys: false, constraints: false, triggers: true, tableComment: true };
|
||||
case "ddl":
|
||||
return { columns: false, indexes: false, foreignKeys: false, triggers: false, tableComment: false };
|
||||
return { columns: false, indexes: false, foreignKeys: false, constraints: false, triggers: false, tableComment: false };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +33,12 @@ export function unloadedTableStructureRefreshScope(activeTab: TableInfoTab, load
|
||||
columns: visibleScope.columns && !loadedFacets.has("columns"),
|
||||
indexes: visibleScope.indexes && !loadedFacets.has("indexes"),
|
||||
foreignKeys: visibleScope.foreignKeys && !loadedFacets.has("foreign-keys"),
|
||||
constraints: visibleScope.constraints && !loadedFacets.has("constraints"),
|
||||
triggers: visibleScope.triggers && !loadedFacets.has("triggers"),
|
||||
tableComment: visibleScope.tableComment && !loadedFacets.has("comment"),
|
||||
};
|
||||
}
|
||||
|
||||
export function hasTableStructureRefreshWork(scope: TableStructureRefreshScope): boolean {
|
||||
return scope.columns || scope.indexes || scope.foreignKeys || scope.triggers || scope.tableComment;
|
||||
return scope.columns || scope.indexes || scope.foreignKeys || scope.constraints || scope.triggers || scope.tableComment;
|
||||
}
|
||||
Reference in new issue
Block a user