Skip to content

Commit 75b0fa8

Browse files
authored
feat: add action "Create async replication" (#959)
1 parent 0d13d53 commit 75b0fa8

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/containers/Tenant/i18n/en.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@
2929
"actions.createExternalTable": "Create external table...",
3030
"actions.createTopic": "Create topic...",
3131
"actions.createColumnTable": "Create column table...",
32+
"actions.createAsyncReplication": "Create async replication...",
3233
"actions.createView": "Create view...",
3334
"actions.dropTable": "Drop table...",
3435
"actions.dropTopic": "Drop topic...",
3536
"actions.dropView": "Drop view...",
3637
"actions.alterTable": "Alter table...",
3738
"actions.alterTopic": "Alter topic...",
3839
"actions.selectQuery": "Select query...",
39-
"actions.upsertQuery": "Upsert query..."
40+
"actions.upsertQuery": "Upsert query...",
41+
"actions.alterReplication": "Alter async replicaton...",
42+
"actions.dropReplication": "Drop async replicaton..."
4043
}

src/containers/Tenant/utils/queryTemplates.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ CREATE TABLE \`${path}/ydb_column_table\` (
4242
PARTITION BY HASH(id)
4343
WITH (STORE = COLUMN)`;
4444
};
45+
export const createAsyncReplicationTemplate = () => {
46+
return `CREATE OBJECT secret_name (TYPE SECRET) WITH value="secret_value";
47+
48+
CREATE ASYNC REPLICATION my_replication
49+
FOR \`/remote_database/table_name\` AS "local_table_name" --[, \`/remote_database/another_table_name\` AS "another_local_table_name" ...]
50+
WITH (
51+
CONNECTION_STRING=\`grpcs://mydb.ydb.tech:2135/?database=/remote_database\`,
52+
TOKEN_SECRET_NAME = "secret_name",
53+
-- ENDPOINT="mydb.ydb.tech:2135",
54+
-- DATABASE=\`/remote_database\`,
55+
-- USER="user",
56+
-- PASSWORD_SECRET_NAME="your_password"
57+
);`;
58+
};
4559
export const alterTableTemplate = (path: string) => {
4660
return `ALTER TABLE \`${path}\`
4761
ADD COLUMN is_deleted Bool;`;
@@ -131,3 +145,10 @@ export const createViewTemplate = (path: string) => {
131145
export const dropViewTemplate = (path: string) => {
132146
return `DROP VIEW \`${path}\`;`;
133147
};
148+
export const dropAsyncReplicationTemplate = (path: string) => {
149+
return `DROP ASYNC REPLICATION \`${path}\`;`;
150+
};
151+
152+
export const alterAsyncReplicationTemplate = (path: string) => {
153+
return `ALTER ASYNC REPLICATION \`${path}\` SET (STATE = "DONE", FAILOVER_MODE = "FORCE");`;
154+
};

src/containers/Tenant/utils/schemaActions.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ import createToast from '../../../utils/createToast';
99
import i18n from '../i18n';
1010

1111
import {
12+
alterAsyncReplicationTemplate,
1213
alterTableTemplate,
1314
alterTopicTemplate,
15+
createAsyncReplicationTemplate,
1416
createColumnTableTemplate,
1517
createExternalTableTemplate,
1618
createTableTemplate,
1719
createTopicTemplate,
1820
createViewTemplate,
21+
dropAsyncReplicationTemplate,
1922
dropExternalTableTemplate,
2023
dropTopicTemplate,
2124
dropViewTemplate,
@@ -49,6 +52,9 @@ const bindActions = (
4952
return {
5053
createTable: inputQuery(createTableTemplate, 'script'),
5154
createColumnTable: inputQuery(createColumnTableTemplate, 'script'),
55+
createAsyncReplication: inputQuery(createAsyncReplicationTemplate, 'script'),
56+
alterAsyncReplication: inputQuery(alterAsyncReplicationTemplate, 'script'),
57+
dropAsyncReplication: inputQuery(dropAsyncReplicationTemplate, 'script'),
5258
alterTable: inputQuery(alterTableTemplate, 'script'),
5359
selectQuery: inputQuery(selectQueryTemplate),
5460
upsertQuery: inputQuery(upsertQueryTemplate),
@@ -92,6 +98,10 @@ export const getActions =
9298
[
9399
{text: i18n('actions.createTable'), action: actions.createTable},
94100
{text: i18n('actions.createColumnTable'), action: actions.createColumnTable},
101+
{
102+
text: i18n('actions.createAsyncReplication'),
103+
action: actions.createAsyncReplication,
104+
},
95105
{text: i18n('actions.createTopic'), action: actions.createTopic},
96106
{text: i18n('actions.createView'), action: actions.createView},
97107
],
@@ -135,12 +145,20 @@ export const getActions =
135145
[{text: i18n('actions.dropView'), action: actions.dropView}],
136146
];
137147

148+
const ASYNC_REPLICATION_SET: ActionsSet = [
149+
[copyItem],
150+
[
151+
{text: i18n('actions.alterReplication'), action: actions.alterAsyncReplication},
152+
{text: i18n('actions.dropReplication'), action: actions.dropAsyncReplication},
153+
],
154+
];
155+
138156
const JUST_COPY: ActionsSet = [copyItem];
139157

140158
// verbose mapping to guarantee a correct actions set for new node types
141159
// TS will error when a new type is added in the lib but is not mapped here
142160
const nodeTypeToActions: Record<NavigationTreeNodeType, ActionsSet> = {
143-
async_replication: JUST_COPY,
161+
async_replication: ASYNC_REPLICATION_SET,
144162

145163
database: DIR_SET,
146164
directory: DIR_SET,

0 commit comments

Comments
 (0)