console: don't automatically set track this checkbox for commented sql

GITHUB_PR_NUMBER: 5815
GITHUB_PR_URL: https://github.com/hasura/graphql-engine/pull/5815

Co-authored-by: Abhijeet Khangarot <26903230+abhi40308@users.noreply.github.com>
GitOrigin-RevId: 7225d01eef40065a7b7ef617cd763988ef1e018d
This commit is contained in:
hasura-bot 2021-05-21 16:08:23 +05:30
parent e7b4ad85c9
commit e093399305
3 changed files with 19 additions and 4 deletions

View File

@ -10,7 +10,7 @@ import Tooltip from '../../../Common/Tooltip/Tooltip';
import KnowMoreLink from '../../../Common/KnowMoreLink/KnowMoreLink';
import Alert from '../../../Common/Alert';
import StatementTimeout from './StatementTimeout';
import { parseCreateSQL } from './utils';
import { parseCreateSQL, removeCommentsSQL } from './utils';
import styles from '../../../Common/TableCommon/Table.scss';
import {
executeSQL,
@ -178,18 +178,19 @@ const RawSQL = ({
const getSQLSection = () => {
const handleSQLChange = val => {
const cleanSql = removeCommentsSQL(val);
onChangeSQLText(val);
dispatch({ type: SET_SQL, data: val });
// set migration checkbox true
if (services[selectedDriver].checkSchemaModification(val)) {
if (services[selectedDriver].checkSchemaModification(cleanSql)) {
dispatch({ type: SET_MIGRATION_CHECKED, data: true });
} else {
dispatch({ type: SET_MIGRATION_CHECKED, data: false });
}
// set track this checkbox true
const objects = parseCreateSQL(val, selectedDriver);
const objects = parseCreateSQL(cleanSql, selectedDriver);
if (objects.length) {
let allObjectsTrackable = true;

View File

@ -1,6 +1,8 @@
import React, { FC } from 'react';
import ToolTip from '../../../Common/Tooltip/Tooltip';
import styles from '../../../Common/TableCommon/Table.scss';
import globals from '../../../../Globals';
import { CLI_CONSOLE_MODE } from '../../../../constants';
const StatementTimeout: FC<StatementTimeoutProps> = ({
isMigrationChecked,
@ -13,7 +15,9 @@ const StatementTimeout: FC<StatementTimeoutProps> = ({
Statement timeout (seconds)
<ToolTip message="Abort statements that take longer than the specified time" />
<input
disabled={isMigrationChecked}
disabled={
globals.consoleMode === CLI_CONSOLE_MODE && isMigrationChecked
}
title={
isMigrationChecked
? 'Setting statement timeout is not supported for migrations'

View File

@ -12,6 +12,16 @@ const getSQLValue = value => {
return sqlValue.replace(/['"]+/g, '');
};
export const removeCommentsSQL = sql => {
const commentsSQLRegex = /(--[^\r\n]*)|(\/\*[\w\W]*?(?=\*\/)\*\/)/; // eslint-disable-line
const regExp = commentsSQLRegex;
const comments = sql.match(new RegExp(regExp, 'gmi'));
if (!comments || !comments.length) return sql;
return comments.reduce((acc, comment) => acc.replace(comment, ''), sql);
};
const getDefaultSchema = driver => {
if (driver === 'postgres') return 'public';
if (driver === 'mssql') return 'dbo';