Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/containers/Tenant/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"actions.manageColumns": "Manage columns...",
"actions.manageAutoPartitioning": "Manage auto partitioning...",
"actions.manageReadReplicas": "Add read-only replicas...",
"actions.manageTTL": "Manage TTL...",
"actions.enableTTL": "Enable TTL...",
"actions.disableTTL": "Disable TTL...",
"actions.addTableIndex": "Add index...",
"actions.addVectorIndex": "Add vector index...",
"actions.addFulltextIndex": "Add fulltext index...",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {disableTTLTemplate, enableTTLTemplate} from '../schemaQueryTemplates';

describe('schemaQueryTemplates', () => {
describe('enableTTLTemplate', () => {
test('does not suggest disabling TTL with a zero interval', () => {
const template = enableTTLTemplate({path: '/local/table', relativePath: 'table'});

expect(template).toContain('ALTER TABLE `table` SET');
expect(template).toContain('TTL = Interval("PT24H")');
expect(template).not.toContain('To disable TTL');
expect(template).not.toContain('PT0S');
});
});

describe('disableTTLTemplate', () => {
test('resets TTL for the selected table', () => {
const template = disableTTLTemplate({path: '/local/table', relativePath: 'table'});

expect(template).toContain('https://ydb.tech/docs/en/yql/reference/recipes/ttl');
expect(template).toContain('ALTER TABLE `table` RESET (TTL);');
});
});
});
21 changes: 14 additions & 7 deletions src/containers/Tenant/utils/schemaActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
createTopicTemplate,
createTransferTemplate,
createViewTemplate,
disableTTLTemplate,
dropAsyncReplicationTemplate,
dropExternalTableTemplate,
dropStreamingQueryTemplate,
Expand All @@ -49,9 +50,9 @@ import {
dropTopicTemplate,
dropTransferTemplate,
dropViewTemplate,
enableTTLTemplate,
manageAutoPartitioningTemplate,
manageReadReplicasTemplate,
manageTTLTemplate,
selectQueryTemplate,
showCreateTableTemplate,
upsertQueryTemplate,
Expand Down Expand Up @@ -192,7 +193,8 @@ const bindActions = (
manageReadReplicasTemplate,
stripEllipsis(i18n('actions.manageReadReplicas')),
),
manageTTL: inputQuery(manageTTLTemplate, stripEllipsis(i18n('actions.manageTTL'))),
enableTTL: inputQuery(enableTTLTemplate, stripEllipsis(i18n('actions.enableTTL'))),
disableTTL: inputQuery(disableTTLTemplate, stripEllipsis(i18n('actions.disableTTL'))),
selectQuery: inputQuery(selectQueryTemplate, stripEllipsis(i18n('actions.selectQuery'))),
showCreateTable: inputQuery(
showCreateTableTemplate,
Expand Down Expand Up @@ -344,9 +346,13 @@ export const getActions =
text: i18n('actions.manageReadReplicas'),
action: actions.manageReadReplicas,
};
const manageTTLItem = {
text: i18n('actions.manageTTL'),
action: actions.manageTTL,
const enableTTLItem = {
text: i18n('actions.enableTTL'),
action: actions.enableTTL,
};
const disableTTLItem = {
text: i18n('actions.disableTTL'),
action: actions.disableTTL,
};

const alterRowTableGroupItem = {
Expand All @@ -355,12 +361,13 @@ export const getActions =
manageColumnsItem,
manageAutoPartitioningItem,
manageReadReplicasItem,
manageTTLItem,
enableTTLItem,
disableTTLItem,
],
};
const alterColumnTableGroupItem = {
text: i18n('actions.alterTable'),
items: [manageColumnsItem, manageAutoPartitioningItem, manageTTLItem],
items: [manageColumnsItem, manageAutoPartitioningItem, enableTTLItem],
Comment thread
Raubzeug marked this conversation as resolved.
};

let DB_SET: ActionsSet = [[copyItem, connectToDBItem], createEntitiesSet];
Expand Down
15 changes: 12 additions & 3 deletions src/containers/Tenant/utils/schemaQueryTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export const manageReadReplicasTemplate = (params?: SchemaQueryParams) => {
)`;
};

export const manageTTLTemplate = (params?: SchemaQueryParams) => {
export const enableTTLTemplate = (params?: SchemaQueryParams) => {
const path = params?.relativePath
? `\`${normalizeParameter(params.relativePath)}\``
: '${1:<my_table>}';
Expand All @@ -169,11 +169,20 @@ ALTER TABLE ${path} SET (
-- Examples:
-- TTL = Interval("PT1H") ON created_at -- Delete rows 1 hour after created_at
-- TTL = Interval("P7D") ON expire_at -- Delete rows 7 days after expire_at
-- To disable TTL:
-- TTL = Interval("PT0S") ON column_name -- Set interval to 0 to disable TTL
)`;
};

export const disableTTLTemplate = (params?: SchemaQueryParams) => {
const path = params?.relativePath
? `\`${normalizeParameter(params.relativePath)}\``
: '${1:<my_table>}';

return `-- Disable Time to Live (TTL) for automatic row deletion, see docs for more information
-- https://ydb.tech/docs/en/yql/reference/recipes/ttl#disable

ALTER TABLE ${path} RESET (TTL);`;
};

export const selectQueryTemplate = (params?: SchemaQueryParams) => {
const path = params?.relativePath
? `\`${normalizeParameter(params.relativePath)}\``
Expand Down
Loading