diff --git a/src/containers/Tenant/Query/NewSQL/NewSQL.tsx b/src/containers/Tenant/Query/NewSQL/NewSQL.tsx index 8331b018e8..0c9f8fee24 100644 --- a/src/containers/Tenant/Query/NewSQL/NewSQL.tsx +++ b/src/containers/Tenant/Query/NewSQL/NewSQL.tsx @@ -79,6 +79,10 @@ export function NewSQL() { text: i18n('action.drop-index'), action: actions.dropTableIndex, }, + { + text: i18n('action.show-create-table'), + action: actions.showCreateTable, + }, ], }, { diff --git a/src/containers/Tenant/Query/NewSQL/i18n/en.json b/src/containers/Tenant/Query/NewSQL/i18n/en.json index e2730d7a3d..36d81f767d 100644 --- a/src/containers/Tenant/Query/NewSQL/i18n/en.json +++ b/src/containers/Tenant/Query/NewSQL/i18n/en.json @@ -36,6 +36,7 @@ "action.alter-transfer": "Alter transfer", "action.drop-transfer": "Drop transfer", "action.create-streaming-query": "Create streaming query", + "action.show-create-table": "Show Create SQL", "action.alter-streaming-query-settings": "Alter query settings", "action.alter-streaming-query-text": "Alter query text", "action.drop-streaming-query": "Drop query" diff --git a/src/containers/Tenant/i18n/en.json b/src/containers/Tenant/i18n/en.json index 46e11c5be9..502e0e7228 100644 --- a/src/containers/Tenant/i18n/en.json +++ b/src/containers/Tenant/i18n/en.json @@ -45,6 +45,7 @@ "actions.manageAutoPartitioning": "Manage auto partitioning...", "actions.addTableIndex": "Add index...", "actions.createCdcStream": "Create changefeed...", + "actions.showCreateTable": "Show Create SQL...", "actions.alterTopic": "Alter topic...", "actions.selectQuery": "Select query...", "actions.upsertQuery": "Upsert query...", diff --git a/src/containers/Tenant/utils/newSQLQueryActions.ts b/src/containers/Tenant/utils/newSQLQueryActions.ts index 61aa045ecf..06e6540b7d 100644 --- a/src/containers/Tenant/utils/newSQLQueryActions.ts +++ b/src/containers/Tenant/utils/newSQLQueryActions.ts @@ -30,6 +30,7 @@ import { grantPrivilegeTemplate, revokePrivilegeTemplate, selectQueryTemplate, + showCreateTableTemplate, updateTableTemplate, upsertQueryTemplate, } from './schemaQueryTemplates'; @@ -73,5 +74,6 @@ export const bindActions = (changeUserInput: (input: string) => void) => { dropGroup: inputQuery(dropGroupTemplate), addTableIndex: inputQuery(addTableIndex), dropTableIndex: inputQuery(dropTableIndex), + showCreateTable: inputQuery(showCreateTableTemplate), }; }; diff --git a/src/containers/Tenant/utils/schemaActions.tsx b/src/containers/Tenant/utils/schemaActions.tsx index 4b63ddf2f7..5992f91646 100644 --- a/src/containers/Tenant/utils/schemaActions.tsx +++ b/src/containers/Tenant/utils/schemaActions.tsx @@ -1,4 +1,4 @@ -import {CirclePlus, Copy, DisplayPulse, PlugConnection} from '@gravity-ui/icons'; +import {CirclePlus, Code, Copy, DisplayPulse, PlugConnection} from '@gravity-ui/icons'; import {Flex, Spin} from '@gravity-ui/uikit'; import copy from 'copy-to-clipboard'; import type {NavigationTreeNodeType} from 'ydb-ui-components'; @@ -46,6 +46,7 @@ import { dropViewTemplate, manageAutoPartitioningTemplate, selectQueryTemplate, + showCreateTableTemplate, upsertQueryTemplate, } from './schemaQueryTemplates'; import type {YdbNavigationTreeProps} from './types'; @@ -128,6 +129,7 @@ const bindActions = ( dropTable: inputQuery(dropTableTemplate), manageAutoPartitioning: inputQuery(manageAutoPartitioningTemplate), selectQuery: inputQuery(selectQueryTemplate), + showCreateTable: inputQuery(showCreateTableTemplate), upsertQuery: inputQuery(upsertQueryTemplate), createExternalTable: inputQuery(createExternalTableTemplate), dropExternalTable: inputQuery(dropExternalTableTemplate), @@ -244,6 +246,7 @@ export const getActions = }, ], }; + let DB_SET: ActionsSet = [[copyItem, connectToDBItem], createEntitiesSet]; const DIR_SET: ActionsSet = [[copyItem], createEntitiesSet]; @@ -263,6 +266,12 @@ export const getActions = DIR_SET.splice(1, 0, [createDirectoryItem]); } + const showCreateTableItem = { + text: i18n('actions.showCreateTable'), + action: actions.showCreateTable, + iconStart: , + }; + const ROW_TABLE_SET: ActionsSet = [ [copyItem], [ @@ -281,6 +290,7 @@ export const getActions = {text: i18n('actions.addTableIndex'), action: actions.addTableIndex}, {text: i18n('actions.createCdcStream'), action: actions.createCdcStream}, ], + [showCreateTableItem], ]; const COLUMN_TABLE_SET: ActionsSet = [ [copyItem], @@ -290,6 +300,7 @@ export const getActions = {text: i18n('actions.selectQuery'), action: actions.selectQuery}, {text: i18n('actions.upsertQuery'), action: actions.upsertQuery}, ], + [showCreateTableItem], ]; const TOPIC_SET: ActionsSet = [ diff --git a/src/containers/Tenant/utils/schemaQueryTemplates.ts b/src/containers/Tenant/utils/schemaQueryTemplates.ts index 682d5b3e39..6f80ed51c6 100644 --- a/src/containers/Tenant/utils/schemaQueryTemplates.ts +++ b/src/containers/Tenant/utils/schemaQueryTemplates.ts @@ -159,6 +159,14 @@ export const selectQueryTemplate = (params?: SchemaQueryParams) => { FROM ${path} ${filters}LIMIT \${5:10};`; }; + +export const showCreateTableTemplate = (params?: SchemaQueryParams) => { + const tablePath = params?.relativePath + ? `\`${normalizeParameter(params.relativePath)}\`` + : '${2:}'; + return `SHOW CREATE TABLE ${tablePath};`; +}; + export const upsertQueryTemplate = (params?: SchemaQueryParams) => { const path = params?.relativePath ? `\`${normalizeParameter(params.relativePath)}\``