mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 17:31:56 +03:00
This commit is contained in:
parent
4178230d93
commit
689c97e9a1
@ -7,3 +7,25 @@ export const sqlEscapeText = text => {
|
||||
|
||||
return `E'${_text}'`;
|
||||
};
|
||||
|
||||
// detect DDL statements in SQL
|
||||
export const checkSchemaModification = _sql => {
|
||||
let _isSchemaModification = false;
|
||||
|
||||
const sqlStatements = _sql
|
||||
.toLowerCase()
|
||||
.split(';')
|
||||
.map(s => s.trim());
|
||||
|
||||
sqlStatements.forEach(statement => {
|
||||
if (
|
||||
statement.startsWith('create ') ||
|
||||
statement.startsWith('alter ') ||
|
||||
statement.startsWith('drop ')
|
||||
) {
|
||||
_isSchemaModification = true;
|
||||
}
|
||||
});
|
||||
|
||||
return _isSchemaModification;
|
||||
};
|
||||
|
@ -6,6 +6,7 @@ import 'brace/mode/sql';
|
||||
import Modal from '../../../Common/Modal/Modal';
|
||||
import Button from '../../../Common/Button/Button';
|
||||
import { parseCreateSQL } from './utils';
|
||||
import { checkSchemaModification } from '../../../Common/utils/sqlUtils';
|
||||
|
||||
import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger';
|
||||
import Tooltip from 'react-bootstrap/lib/Tooltip';
|
||||
@ -62,16 +63,6 @@ const RawSQL = ({
|
||||
</Tooltip>
|
||||
);
|
||||
|
||||
const isSchemaModification = _sql => {
|
||||
const formattedSQL = _sql.toLowerCase();
|
||||
|
||||
return (
|
||||
formattedSQL.includes('create') ||
|
||||
formattedSQL.includes('alter') ||
|
||||
formattedSQL.includes('drop')
|
||||
);
|
||||
};
|
||||
|
||||
const submitSQL = () => {
|
||||
// check migration mode global
|
||||
if (migrationMode) {
|
||||
@ -84,7 +75,7 @@ const RawSQL = ({
|
||||
}
|
||||
if (!isMigration && globals.consoleMode === CLI_CONSOLE_MODE) {
|
||||
// if migration is not checked, check if is schema modification
|
||||
if (isSchemaModification(sql)) {
|
||||
if (checkSchemaModification(sql)) {
|
||||
dispatch(modalOpen());
|
||||
const confirmation = false;
|
||||
if (confirmation) {
|
||||
@ -166,14 +157,14 @@ const RawSQL = ({
|
||||
dispatch({ type: SET_SQL, data: val });
|
||||
|
||||
// set migration checkbox true
|
||||
if (isSchemaModification(val)) {
|
||||
if (checkSchemaModification(val)) {
|
||||
dispatch({ type: SET_MIGRATION_CHECKED, data: true });
|
||||
} else {
|
||||
dispatch({ type: SET_MIGRATION_CHECKED, data: false });
|
||||
}
|
||||
|
||||
// set track this checkbox true
|
||||
const objects = parseCreateSQL(val, true);
|
||||
const objects = parseCreateSQL(val);
|
||||
if (objects.length) {
|
||||
let allObjectsTrackable = true;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user