fix(desktop): show CREATE OR REPLACE for view structure DDL
This commit is contained in:
1 parent
0212231421
commit
816b0a0996
4 files changed
+93
-6
No files matched your search
@@ -3086,6 +3086,7 @@ defineExpose({
|
||||
:catalog="activeTab.catalog"
|
||||
:schema="activeTab.schema"
|
||||
:table-name="activeTab.structureTableName || ''"
|
||||
:table-type="activeTab.structureTableType"
|
||||
:initial-tab="activeTab.structureInitialTab"
|
||||
:initial-tab-request-id="activeTab.structureInitialTabRequestId"
|
||||
:initial-target="activeTab.structureInitialTarget"
|
||||
|
||||
@@ -190,6 +190,8 @@ const props = defineProps<{
|
||||
catalog?: string;
|
||||
schema?: string;
|
||||
tableName: string;
|
||||
/** `view` loads `CREATE OR REPLACE VIEW` instead of table DDL. */
|
||||
tableType?: "table" | "view";
|
||||
initialTab?: TableInfoTab;
|
||||
initialTabRequestId?: number;
|
||||
initialTarget?: TableStructureEditorTarget;
|
||||
@@ -431,13 +433,23 @@ function applyDdlGenerationPreferences(sql: string, dialect: SqlFormatDialect):
|
||||
return formatGeneratedDdlIdentifierQuotes(unqualified, dialect, false, { preserveCaseSensitiveIdentifiers: tableStoresCaseSensitiveIdentifiers.value });
|
||||
}
|
||||
|
||||
function ddlRequest() {
|
||||
type StructureDdlRequest = {
|
||||
connectionId: string;
|
||||
database: string;
|
||||
schema: string;
|
||||
tableName: string;
|
||||
catalog?: string;
|
||||
objectType?: "VIEW";
|
||||
};
|
||||
|
||||
function ddlRequest(): StructureDdlRequest {
|
||||
return {
|
||||
connectionId: props.connectionId,
|
||||
database: props.database,
|
||||
schema: metadataSchema.value,
|
||||
tableName: props.tableName,
|
||||
catalog: props.catalog,
|
||||
objectType: props.tableType === "view" ? "VIEW" : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2533,7 +2545,7 @@ async function fetchTableCommentValue(connectionId: string, database: string, sc
|
||||
}
|
||||
}
|
||||
|
||||
function loadCachedTableComment(request: ReturnType<typeof ddlRequest>, force = false): Promise<{ value: string | undefined; cacheStatus: "memory" | "disk" | "remote" }> {
|
||||
function loadCachedTableComment(request: StructureDdlRequest, force = false): Promise<{ value: string | undefined; cacheStatus: "memory" | "disk" | "remote" }> {
|
||||
return loadObjectMetadataFacet(request, "comment", () => fetchTableCommentValue(request.connectionId, request.database, request.schema, request.tableName, request.catalog), { force });
|
||||
}
|
||||
|
||||
|
||||
+13
@@ -417,6 +417,19 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
describe("TableStructureEditor DDL tab", () => {
|
||||
it("loads CREATE OR REPLACE VIEW ddl when editing a view", async () => {
|
||||
const viewDdl = "CREATE OR REPLACE VIEW `active_users` AS\nSELECT id FROM users;";
|
||||
mocks.loadObjectDdl.mockResolvedValue({ ddl: viewDdl, cacheStatus: "remote" });
|
||||
|
||||
const root = await mountStructureEditor({ database: "app", schema: "app", tableName: "active_users", tableType: "view" });
|
||||
await clickTab(root, "ddl");
|
||||
await vi.waitFor(() => expect(ddlEditorText(root)).toContain("CREATE OR REPLACE VIEW"), { timeout: 3000 });
|
||||
|
||||
expect(ddlEditorText(root)).toContain("`active_users`");
|
||||
expect(ddlEditorText(root)).not.toContain("CREATE TABLE");
|
||||
expect(mocks.loadObjectDdl).toHaveBeenCalledWith(expect.objectContaining({ tableName: "active_users", objectType: "VIEW" }), expect.anything());
|
||||
});
|
||||
|
||||
it("keeps the DDL rendered when the tab is left and revisited", async () => {
|
||||
// Regression for #7818/#7778: the second visit re-mounts the pane one tick
|
||||
// after the tab activates, and nothing re-fetches (the DDL is already
|
||||
|
||||
Reference in new issue
Block a user