mirror of
https://github.com/hasura/graphql-engine.git
synced 2025-01-05 22:34:22 +03:00
console: allow editing comments on views (fix #8846)
GITHUB_PR_NUMBER: 8847 GITHUB_PR_URL: https://github.com/hasura/graphql-engine/pull/8847 PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5625 Co-authored-by: Gordan Nekić <48327736+gnekich@users.noreply.github.com> GitOrigin-RevId: e54b3024533dab51231e2a9ac578c115d4a21dcb
This commit is contained in:
parent
ff25d27ab1
commit
432c481c9c
@ -1430,7 +1430,7 @@ const deleteConstraintSql = (tableName, cName) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const saveTableCommentSql = () => {
|
const saveTableCommentSql = tableType => {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const source = getState().tables.currentDataSource;
|
const source = getState().tables.currentDataSource;
|
||||||
const updatedComment =
|
const updatedComment =
|
||||||
@ -1439,12 +1439,30 @@ const saveTableCommentSql = () => {
|
|||||||
const currentSchema = getState().tables.currentSchema;
|
const currentSchema = getState().tables.currentSchema;
|
||||||
const tableName = getState().tables.currentTable;
|
const tableName = getState().tables.currentTable;
|
||||||
|
|
||||||
const commentQueryUp = dataSource.getAlterTableCommentSql({
|
// For now the saveTableCommentSql is also used for views, we need to make a check
|
||||||
|
// tableType should be returned by findViewType in ModifyView.js
|
||||||
|
const property = `${tableType}`.toLowerCase();
|
||||||
|
|
||||||
|
const commentQueryUp =
|
||||||
|
property === 'view'
|
||||||
|
? dataSource.getAlterViewCommentSql({
|
||||||
|
viewName: tableName,
|
||||||
|
schemaName: currentSchema,
|
||||||
|
comment: updatedComment ?? null,
|
||||||
|
})
|
||||||
|
: dataSource.getAlterTableCommentSql({
|
||||||
tableName,
|
tableName,
|
||||||
schemaName: currentSchema,
|
schemaName: currentSchema,
|
||||||
comment: updatedComment ?? null,
|
comment: updatedComment ?? null,
|
||||||
});
|
});
|
||||||
const commentDownQuery = dataSource.getAlterTableCommentSql({
|
const commentDownQuery =
|
||||||
|
property === 'view'
|
||||||
|
? dataSource.getAlterViewCommentSql({
|
||||||
|
viewName: tableName,
|
||||||
|
schemaName: currentSchema,
|
||||||
|
comment: null,
|
||||||
|
})
|
||||||
|
: dataSource.getAlterTableCommentSql({
|
||||||
tableName,
|
tableName,
|
||||||
schemaName: currentSchema,
|
schemaName: currentSchema,
|
||||||
comment: null,
|
comment: null,
|
||||||
@ -1457,8 +1475,7 @@ const saveTableCommentSql = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Apply migrations
|
// Apply migrations
|
||||||
const migrationName =
|
const migrationName = `alter_${property}_${currentSchema}_${tableName}_update_comment`;
|
||||||
'alter_table_' + currentSchema + '_' + tableName + '_update_comment';
|
|
||||||
|
|
||||||
const requestMsg = 'Updating Comment...';
|
const requestMsg = 'Updating Comment...';
|
||||||
const successMsg = 'Comment Updated';
|
const successMsg = 'Comment Updated';
|
||||||
|
@ -288,6 +288,15 @@ export interface DataSourcesAPI {
|
|||||||
columnName: string;
|
columnName: string;
|
||||||
columnType?: string;
|
columnType?: string;
|
||||||
}) => string;
|
}) => string;
|
||||||
|
getAlterViewCommentSql: ({
|
||||||
|
viewName,
|
||||||
|
schemaName,
|
||||||
|
comment,
|
||||||
|
}: {
|
||||||
|
viewName: string;
|
||||||
|
schemaName: string;
|
||||||
|
comment: string;
|
||||||
|
}) => string;
|
||||||
getAlterFunctionCommentSql: ({
|
getAlterFunctionCommentSql: ({
|
||||||
functionName,
|
functionName,
|
||||||
schemaName,
|
schemaName,
|
||||||
|
@ -375,6 +375,7 @@ export const bigquery: DataSourcesAPI = {
|
|||||||
},
|
},
|
||||||
getAlterTableCommentSql: () => '',
|
getAlterTableCommentSql: () => '',
|
||||||
getAlterColumnCommentSql: () => '',
|
getAlterColumnCommentSql: () => '',
|
||||||
|
getAlterViewCommentSql: () => '',
|
||||||
getAlterFunctionCommentSql: () => '',
|
getAlterFunctionCommentSql: () => '',
|
||||||
getSetColumnDefaultSql: () => {
|
getSetColumnDefaultSql: () => {
|
||||||
return '';
|
return '';
|
||||||
|
@ -1009,6 +1009,9 @@ WHERE
|
|||||||
return `${dropCommonCommentStatement},@level1type = N'TABLE', @level1name = '${tableName}',@level2type = N'COLUMN', @level2name = '${columnName}';
|
return `${dropCommonCommentStatement},@level1type = N'TABLE', @level1name = '${tableName}',@level2type = N'COLUMN', @level2name = '${columnName}';
|
||||||
${commonCommentStatement},@level1type = N'TABLE', @level1name = '${tableName}',@level2type = N'COLUMN', @level2name = '${columnName}'`;
|
${commonCommentStatement},@level1type = N'TABLE', @level1name = '${tableName}',@level2type = N'COLUMN', @level2name = '${columnName}'`;
|
||||||
},
|
},
|
||||||
|
getAlterViewCommentSql: () => {
|
||||||
|
return '';
|
||||||
|
},
|
||||||
getAlterFunctionCommentSql: () => {
|
getAlterFunctionCommentSql: () => {
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
|
@ -35,6 +35,7 @@ import {
|
|||||||
getAdditionalColumnsInfoQuerySql,
|
getAdditionalColumnsInfoQuerySql,
|
||||||
getAlterTableCommentSql,
|
getAlterTableCommentSql,
|
||||||
getAlterColumnCommentSql,
|
getAlterColumnCommentSql,
|
||||||
|
getAlterViewCommentSql,
|
||||||
getAlterFunctionCommentSql,
|
getAlterFunctionCommentSql,
|
||||||
} from './sqlUtils';
|
} from './sqlUtils';
|
||||||
import { getTableSupportedQueries } from '../postgresql';
|
import { getTableSupportedQueries } from '../postgresql';
|
||||||
@ -254,5 +255,6 @@ WHERE
|
|||||||
violationActions,
|
violationActions,
|
||||||
getAlterTableCommentSql,
|
getAlterTableCommentSql,
|
||||||
getAlterColumnCommentSql,
|
getAlterColumnCommentSql,
|
||||||
|
getAlterViewCommentSql,
|
||||||
getAlterFunctionCommentSql,
|
getAlterFunctionCommentSql,
|
||||||
};
|
};
|
||||||
|
@ -199,6 +199,11 @@ export const getAlterColumnCommentSql: DataSourcesAPI['getAlterColumnCommentSql'
|
|||||||
)} modify column \`${columnName}\` ${columnType} comment ${commentStr};`;
|
)} modify column \`${columnName}\` ${columnType} comment ${commentStr};`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getAlterViewCommentSql: DataSourcesAPI['getAlterViewCommentSql'] =
|
||||||
|
() => {
|
||||||
|
return '';
|
||||||
|
};
|
||||||
|
|
||||||
export const getAlterFunctionCommentSql: DataSourcesAPI['getAlterFunctionCommentSql'] =
|
export const getAlterFunctionCommentSql: DataSourcesAPI['getAlterFunctionCommentSql'] =
|
||||||
() => {
|
() => {
|
||||||
return '';
|
return '';
|
||||||
|
@ -32,6 +32,8 @@ COMMIT TRANSACTION;"
|
|||||||
|
|
||||||
exports[`postgresql datasource tests getAlterTableCommentSql should generate SQL for modifying table comment 1`] = `"comment on table \\"public\\".\\"users\\" is E'user\\\\'s comment'"`;
|
exports[`postgresql datasource tests getAlterTableCommentSql should generate SQL for modifying table comment 1`] = `"comment on table \\"public\\".\\"users\\" is E'user\\\\'s comment'"`;
|
||||||
|
|
||||||
|
exports[`postgresql datasource tests getAlterViewCommentSql should generate SQL for modifying view comment 1`] = `"comment on view \\"public\\".\\"view_users\\" is E'user\\\\'s comment'"`;
|
||||||
|
|
||||||
exports[`postgresql datasource tests getDataTriggerInvocations should generate SQL to fetch invocations for an event 1`] = `
|
exports[`postgresql datasource tests getDataTriggerInvocations should generate SQL to fetch invocations for an event 1`] = `
|
||||||
"SELECT *
|
"SELECT *
|
||||||
FROM \\"hdb_catalog\\".\\"event_invocation_logs\\"
|
FROM \\"hdb_catalog\\".\\"event_invocation_logs\\"
|
||||||
|
@ -62,6 +62,21 @@ describe('postgresql datasource tests', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getAlterViewCommentSql', () => {
|
||||||
|
const { getAlterViewCommentSql } = postgres;
|
||||||
|
it('should generate SQL for modifying view comment', () => {
|
||||||
|
const query = getAlterViewCommentSql({
|
||||||
|
viewName: 'view_users',
|
||||||
|
schemaName: 'public',
|
||||||
|
comment: "user's comment",
|
||||||
|
});
|
||||||
|
expect(query).toContain('comment on view');
|
||||||
|
expect(query).toContain('"public"."view_users"');
|
||||||
|
expect(query).toContain("E'user\\'s comment'");
|
||||||
|
expect(query).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('getAlterFunctionCommentSql', () => {
|
describe('getAlterFunctionCommentSql', () => {
|
||||||
const { getAlterFunctionCommentSql } = postgres;
|
const { getAlterFunctionCommentSql } = postgres;
|
||||||
it('should generate SQL for modifying function comment', () => {
|
it('should generate SQL for modifying function comment', () => {
|
||||||
|
@ -73,6 +73,7 @@ import {
|
|||||||
schemaListQuery,
|
schemaListQuery,
|
||||||
getAlterTableCommentSql,
|
getAlterTableCommentSql,
|
||||||
getAlterColumnCommentSql,
|
getAlterColumnCommentSql,
|
||||||
|
getAlterViewCommentSql,
|
||||||
getAlterFunctionCommentSql,
|
getAlterFunctionCommentSql,
|
||||||
getDataTriggerInvocations,
|
getDataTriggerInvocations,
|
||||||
getDataTriggerLogsCountQuery,
|
getDataTriggerLogsCountQuery,
|
||||||
@ -869,6 +870,7 @@ export const postgres: DataSourcesAPI = {
|
|||||||
schemaListQuery,
|
schemaListQuery,
|
||||||
getAlterTableCommentSql,
|
getAlterTableCommentSql,
|
||||||
getAlterColumnCommentSql,
|
getAlterColumnCommentSql,
|
||||||
|
getAlterViewCommentSql,
|
||||||
getAlterFunctionCommentSql,
|
getAlterFunctionCommentSql,
|
||||||
getDataTriggerInvocations,
|
getDataTriggerInvocations,
|
||||||
getDataTriggerLogsCountQuery,
|
getDataTriggerLogsCountQuery,
|
||||||
|
@ -680,6 +680,13 @@ export const getAlterColumnCommentSql: DataSourcesAPI['getAlterColumnCommentSql'
|
|||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getAlterViewCommentSql: DataSourcesAPI['getAlterViewCommentSql'] =
|
||||||
|
({ viewName, schemaName, comment }) => {
|
||||||
|
return `comment on view "${schemaName}"."${viewName}" is ${
|
||||||
|
comment ? sqlEscapeText(comment) : 'NULL'
|
||||||
|
}`;
|
||||||
|
};
|
||||||
|
|
||||||
export const getAlterFunctionCommentSql: DataSourcesAPI['getAlterFunctionCommentSql'] =
|
export const getAlterFunctionCommentSql: DataSourcesAPI['getAlterFunctionCommentSql'] =
|
||||||
({ functionName, schemaName, comment }) => {
|
({ functionName, schemaName, comment }) => {
|
||||||
return `
|
return `
|
||||||
|
Loading…
Reference in New Issue
Block a user