Skip to content

Commit 86bbf6f

Browse files
committed
feat: add/drop table index template
1 parent a278618 commit 86bbf6f

File tree

7 files changed

+30
-0
lines changed

7 files changed

+30
-0
lines changed

src/containers/Tenant/Query/NewSQL/NewSQL.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ export function NewSQL() {
5858
text: i18n('action.drop-external-table'),
5959
action: actions.dropExternalTable,
6060
},
61+
{
62+
text: i18n('action.add-index'),
63+
action: actions.addTableIndex,
64+
},
65+
{
66+
text: i18n('action.drop-index'),
67+
action: actions.dropTableIndex,
68+
},
6169
],
6270
},
6371
{

src/containers/Tenant/Query/NewSQL/i18n/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"action.select-from-external-table": "Select from external table",
1111
"action.delete-rows": "Delete rows",
1212
"action.drop-table": "Drop table",
13+
"action.add-index": "Add index",
14+
"action.drop-index": "Drop index",
1315
"action.drop-external-table": "Drop external table",
1416
"menu.tables": "Tables",
1517
"menu.topics": "Topics",

src/containers/Tenant/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"actions.dropTopic": "Drop topic...",
3737
"actions.dropView": "Drop view...",
3838
"actions.alterTable": "Alter table...",
39+
"actions.addTableIndex": "Add index...",
3940
"actions.alterTopic": "Alter topic...",
4041
"actions.selectQuery": "Select query...",
4142
"actions.upsertQuery": "Upsert query...",

src/containers/Tenant/utils/newSQLQueryActions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {changeUserInput} from '../../../store/reducers/executeQuery';
22

33
import {
4+
addTableIndex,
45
alterAsyncReplicationTemplate,
56
alterTableTemplate,
67
alterTopicTemplate,
@@ -17,6 +18,7 @@ import {
1718
dropAsyncReplicationTemplate,
1819
dropExternalTableTemplate,
1920
dropGroupTemplate,
21+
dropTableIndex,
2022
dropTableTemplate,
2123
dropTopicTemplate,
2224
dropUserTemplate,
@@ -58,5 +60,7 @@ export const bindActions = (dispatch: React.Dispatch<any>) => {
5860
revokePrivilege: inputQuery(revokePrivilegeTemplate),
5961
dropUser: inputQuery(dropUserTemplate),
6062
dropGroup: inputQuery(dropGroupTemplate),
63+
addTableIndex: inputQuery(addTableIndex),
64+
dropTableIndex: inputQuery(dropTableIndex),
6165
};
6266
};

src/containers/Tenant/utils/newSQLQueryTemplates.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,11 @@ export const dropAsyncReplicationTemplate = () => {
248248
export const alterAsyncReplicationTemplate = () => {
249249
return `ALTER ASYNC REPLICATION \`$path\` SET (STATE=\`$state\`, FAILOVER_MODE=\`$failoverMode\`);`;
250250
};
251+
252+
export const addTableIndex = () => {
253+
return `ALTER TABLE \`$path\` ADD INDEX \`$indexName\` GLOBAL ON (\`$columnName\`);`;
254+
};
255+
256+
export const dropTableIndex = () => {
257+
return `ALTER TABLE \`$path\` DROP INDEX \`$indexName\`;`;
258+
};

src/containers/Tenant/utils/schemaActions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {transformPath} from '../ObjectSummary/transformPath';
1010
import i18n from '../i18n';
1111

1212
import {
13+
addTableIndex,
1314
alterAsyncReplicationTemplate,
1415
alterTableTemplate,
1516
alterTopicTemplate,
@@ -74,6 +75,7 @@ const bindActions = (
7475
dropTopic: inputQuery(dropTopicTemplate, 'script'),
7576
createView: inputQuery(createViewTemplate, 'script'),
7677
dropView: inputQuery(dropViewTemplate, 'script'),
78+
addTableIndex: inputQuery(addTableIndex, 'script'),
7779
copyPath: () => {
7880
try {
7981
copy(relativePath);
@@ -126,6 +128,7 @@ export const getActions =
126128
{text: i18n('actions.alterTable'), action: actions.alterTable},
127129
{text: i18n('actions.selectQuery'), action: actions.selectQuery},
128130
{text: i18n('actions.upsertQuery'), action: actions.upsertQuery},
131+
{text: i18n('actions.addTableIndex'), action: actions.addTableIndex},
129132
],
130133
];
131134

src/containers/Tenant/utils/schemaQueryTemplates.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,7 @@ export const dropAsyncReplicationTemplate = (path: string) => {
153153
export const alterAsyncReplicationTemplate = (path: string) => {
154154
return `ALTER ASYNC REPLICATION \`${path}\` SET (STATE = "DONE", FAILOVER_MODE = "FORCE");`;
155155
};
156+
157+
export const addTableIndex = (path: string) => {
158+
return `ALTER TABLE \`${path}\` ADD INDEX \`$indexName\` GLOBAL ON (\`$columnName\`);`;
159+
};

0 commit comments

Comments
 (0)