From 6e8fc82ab9379a1520d61b71b0a4183ac56ab9ef Mon Sep 17 00:00:00 2001 From: rikinsk Date: Wed, 13 Mar 2019 17:44:39 +0530 Subject: [PATCH] show migration name section if is migration is checked --- .../components/Services/Data/RawSQL/RawSQL.js | 600 ++++++++++-------- 1 file changed, 339 insertions(+), 261 deletions(-) diff --git a/console/src/components/Services/Data/RawSQL/RawSQL.js b/console/src/components/Services/Data/RawSQL/RawSQL.js index c20147dd05c43..285a2e160509b 100644 --- a/console/src/components/Services/Data/RawSQL/RawSQL.js +++ b/console/src/components/Services/Data/RawSQL/RawSQL.js @@ -22,33 +22,6 @@ import globals from '../../../../Globals'; import semverCheck from '../../../../helpers/semver'; import './AceEditorFix.css'; -const cascadeTip = ( - - Cascade all the dependent metadata references like relationships and - permissions. - -); -const migrationTip = ( - - Modifications to the underlying postgres schema should be tracked as - migrations - -); -const migrationNameTip = ( - - Use this to change the name of the generated migration files. Defaults to - 'run_sql_migration' - -); -const trackTableTip = hasFunctionSupport => ( - - {`If you are creating a table/view${ - hasFunctionSupport ? '/function' : '' - }, you can track them to query them - with GraphQL`} - -); - const RawSQL = ({ sql, resultType, @@ -68,6 +41,33 @@ const RawSQL = ({ }) => { const styles = require('../../../Common/TableCommon/Table.scss'); + const cascadeTip = ( + + Cascade all the dependent metadata references like relationships and + permissions. + + ); + const migrationTip = ( + + Modifications to the underlying postgres schema should be tracked as + migrations + + ); + const migrationNameTip = ( + + Use this to change the name of the generated migration files. Defaults to + 'run_sql_migration' + + ); + const trackTableTip = _hasFunctionSupport => ( + + {`If you are creating a table/view${ + _hasFunctionSupport ? '/function' : '' + }, you can track them to query them + with GraphQL`} + + ); + let alert = null; if (ongoingRequest) { @@ -96,9 +96,10 @@ const RawSQL = ({ ); } - const functionText = semverCheck('customFunctionSection', serverVersion) - ? 'Function' - : ''; + const hasFunctionSupport = semverCheck( + 'customFunctionSection', + serverVersion + ); const isSchemaModification = _sql => { const formattedSQL = _sql.toLowerCase(); @@ -140,97 +141,324 @@ const RawSQL = ({ } }; - const handleSQLChange = val => { - dispatch({ type: SET_SQL, data: val }); + const getMigrationModal = () => { + const onModalClose = () => { + dispatch(modalClose()); + }; - // set migration checkbox true - if (isSchemaModification(val)) { - dispatch({ type: SET_MIGRATION_CHECKED, data: true }); - } else { - dispatch({ type: SET_MIGRATION_CHECKED, data: false }); - } + const onConfirmNoMigration = () => { + const isMigration = document.getElementById('migration-checkbox').checked; + dispatch(modalClose()); + dispatch(executeSQL(isMigration)); + }; + + return ( + + + Run SQL + + +
+
+
+ Your SQL Statement is most likely modifying the database schema. + Are you sure its not a migration? +
+
+
+
+ + Cancel + + Yes, i confirm + + +
+ ); + }; - // set track this checkbox true - const objects = parseCreateSQL(val, true); - if (objects.length) { - let allObjectsTrackable = true; + const getSQLSection = () => { + const handleSQLChange = val => { + dispatch({ type: SET_SQL, data: val }); + + // set migration checkbox true + if (isSchemaModification(val)) { + dispatch({ type: SET_MIGRATION_CHECKED, data: true }); + } else { + dispatch({ type: SET_MIGRATION_CHECKED, data: false }); + } - const trackedObjectNames = allSchemas.map(schema => { - return [schema.table_schema, schema.table_name].join('.'); - }); + // set track this checkbox true + const objects = parseCreateSQL(val, true); + if (objects.length) { + let allObjectsTrackable = true; - for (let i = 0; i < objects.length; i++) { - const object = objects[i]; + const trackedObjectNames = allSchemas.map(schema => { + return [schema.table_schema, schema.table_name].join('.'); + }); - if (object.type === 'function') { - allObjectsTrackable = false; - break; - } else { - const objectName = [object.schema, object.name].join('.'); + for (let i = 0; i < objects.length; i++) { + const object = objects[i]; - if (trackedObjectNames.includes(objectName)) { + if (object.type === 'function') { allObjectsTrackable = false; break; + } else { + const objectName = [object.schema, object.name].join('.'); + + if (trackedObjectNames.includes(objectName)) { + allObjectsTrackable = false; + break; + } } } - } - if (allObjectsTrackable) { - dispatch({ type: SET_TRACK_TABLE_CHECKED, data: true }); + if (allObjectsTrackable) { + dispatch({ type: SET_TRACK_TABLE_CHECKED, data: true }); + } else { + dispatch({ type: SET_TRACK_TABLE_CHECKED, data: false }); + } } else { dispatch({ type: SET_TRACK_TABLE_CHECKED, data: false }); } - } else { - dispatch({ type: SET_TRACK_TABLE_CHECKED, data: false }); + }; + + return ( +
+

SQL:

+ { + submitSQL(); + }, + }, + ]} + onChange={handleSQLChange} + /> +
+ ); + }; + + const getResultTable = () => { + let resultTable = null; + + if (resultType && resultType !== 'command') { + const getTableHeadings = () => { + return resultHeaders.map((columnName, i) => ( + {columnName} + )); + }; + + const getRows = () => { + return result.map((row, i) => ( + + {row.map((columnValue, j) => ( + {columnValue} + ))} + + )); + }; + + resultTable = ( +
+

SQL Result:

+
+ + + {getTableHeadings()} + + {getRows()} +
+
+
+
+
+ ); } + + return resultTable; }; - const onModalClose = () => { - dispatch(modalClose()); + const getNotesSection = () => { + return ( +
+ Notes + +
+ ); }; - const onConfirmNoMigration = () => { - const isMigration = document.getElementById('migration-checkbox').checked; - dispatch(modalClose()); - dispatch(executeSQL(isMigration)); + const getMetadataCascadeSection = () => { + return ( +
+ { + dispatch({ + type: SET_CASCADE_CHECKED, + data: !isCascadeChecked, + }); + }} + /> + Cascade metadata + +