这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions console/src/components/Common/utils/sqlUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,10 @@ export const getCreatePkSql = ({
export const getDropPkSql = ({ schemaName, tableName, constraintName }) => {
return `alter table "${schemaName}"."${tableName}" drop constraint "${constraintName}";`;
};

export const terminateSql = sql => {
const sqlSanitised = sql.trim();
return sqlSanitised[sqlSanitised.length - 1] !== ';'
? sqlSanitised + ';'
: sqlSanitised;
};
30 changes: 29 additions & 1 deletion console/src/components/Common/utils/v1QueryUtils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { terminateSql } from './sqlUtils';

export const getRunSqlQuery = (sql, shouldCascade, readOnly) => {
return {
type: 'run_sql',
args: {
sql,
sql: terminateSql(sql),
cascade: !!shouldCascade,
read_only: !!readOnly,
},
Expand Down Expand Up @@ -50,3 +52,29 @@ export const getSetCustomRootFieldsQuery = (
},
};
};

export const getSetTableEnumQuery = (tableDef, isEnum) => {
return {
type: 'set_table_is_enum',
args: {
table: tableDef,
is_enum: isEnum,
},
};
};

export const getTrackTableQuery = tableDef => {
return {
type: 'add_existing_table_or_view',
args: tableDef,
};
};

export const getUntrackTableQuery = tableDef => {
return {
type: 'untrack_table',
args: {
table: tableDef,
},
};
};
18 changes: 4 additions & 14 deletions console/src/components/Services/Data/Add/AddActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { setTable } from '../DataActions.js';

import { isPostgresFunction } from '../utils';
import { sqlEscapeText } from '../../../Common/utils/sqlUtils';
import { getRunSqlQuery } from '../../../Common/utils/v1QueryUtils';
import { getTableModifyRoute } from '../../../Common/utils/routesUtils';

const SET_DEFAULTS = 'AddTable/SET_DEFAULTS';
Expand Down Expand Up @@ -315,16 +316,10 @@ const createTableSql = () => {
if (hasUUIDDefault) {
const sqlCreateExtension = 'CREATE EXTENSION IF NOT EXISTS pgcrypto;';

upQueryArgs.push({
type: 'run_sql',
args: { sql: sqlCreateExtension },
});
upQueryArgs.push(getRunSqlQuery(sqlCreateExtension));
}

upQueryArgs.push({
type: 'run_sql',
args: { sql: sqlCreateTable },
});
upQueryArgs.push(getRunSqlQuery(sqlCreateTable));

upQueryArgs.push({
type: 'add_existing_table_or_view',
Expand All @@ -345,12 +340,7 @@ const createTableSql = () => {

const downQuery = {
type: 'bulk',
args: [
{
type: 'run_sql',
args: { sql: sqlDropTable },
},
],
args: [getRunSqlQuery(sqlDropTable)],
};

// make request
Expand Down
34 changes: 12 additions & 22 deletions console/src/components/Services/Data/DataActions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sanitize from 'sanitize-filename';

import { getSchemaBaseRoute } from '../../Common/utils/routesUtils';
import { getRunSqlQuery } from '../../Common/utils/v1QueryUtils';
import Endpoints, { globalCookiePolicy } from '../../../Endpoints';
import requestAction from '../../../utils/requestAction';
import defaultState from './DataState';
Expand Down Expand Up @@ -547,28 +548,17 @@ const makeMigrationCall = (
};

const getBulkColumnInfoFetchQuery = schema => {
const fetchColumnTypes = {
type: 'run_sql',
args: {
sql: fetchColumnTypesQuery,
read_only: true,
},
};
const fetchTypeDefaultValues = {
type: 'run_sql',
args: {
sql: fetchColumnDefaultFunctions(schema),
read_only: true,
},
};

const fetchValidTypeCasts = {
type: 'run_sql',
args: {
sql: fetchColumnCastsQuery,
read_only: true,
},
};
const fetchColumnTypes = getRunSqlQuery(fetchColumnTypesQuery, false, true);
const fetchTypeDefaultValues = getRunSqlQuery(
fetchColumnDefaultFunctions(schema),
false,
true
);
const fetchValidTypeCasts = getRunSqlQuery(
fetchColumnCastsQuery,
false,
true
);

return {
type: 'bulk',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { fetchTrackedFunctions } from '../DataActions';

import _push from '../push';
import { getSchemaBaseRoute } from '../../../Common/utils/routesUtils';
import { getRunSqlQuery } from '../../../Common/utils/v1QueryUtils';

/* Constants */

Expand Down Expand Up @@ -193,19 +194,11 @@ const deleteFunctionSql = () => {
const sqlDropFunction =
'DROP FUNCTION ' + functionNameWithSchema + functionArgString;

const sqlUpQueries = [
{
type: 'run_sql',
args: { sql: sqlDropFunction },
},
];
const sqlUpQueries = [getRunSqlQuery(sqlDropFunction)];

const sqlDownQueries = [];
if (functionDefinition && functionDefinition.length > 0) {
sqlDownQueries.push({
type: 'run_sql',
args: { sql: functionDefinition },
});
sqlDownQueries.push(getRunSqlQuery(functionDefinition));
}

// Apply migrations
Expand Down
12 changes: 2 additions & 10 deletions console/src/components/Services/Data/RawSQL/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { parseCreateSQL } from './utils';
import dataHeaders from '../Common/Headers';
import returnMigrateUrl from '../Common/getMigrateUrl';
import { getRunSqlQuery } from '../../../Common/utils/v1QueryUtils';

const MAKING_REQUEST = 'RawSQL/MAKING_REQUEST';
const SET_SQL = 'RawSQL/SET_SQL';
Expand Down Expand Up @@ -43,16 +44,7 @@ const executeSQL = (isMigration, migrationName) => (dispatch, getState) => {
const isCascadeChecked = getState().rawSQL.isCascadeChecked;

let url = Endpoints.rawSQL;
const schemaChangesUp = [
{
type: 'run_sql',
args: {
sql: sql,
cascade: isCascadeChecked,
read_only: readOnlyMode,
},
},
];
const schemaChangesUp = [getRunSqlQuery(sql, isCascadeChecked, readOnlyMode)];
// check if track view enabled

if (getState().rawSQL.isTableTrackChecked) {
Expand Down
28 changes: 4 additions & 24 deletions console/src/components/Services/Data/Schema/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import gqlPattern, { gqlSchemaErrorNotif } from '../Common/GraphQLValidation';
import { showErrorNotification } from '../../Common/Notification';
import { makeMigrationCall, fetchSchemaList } from '../DataActions';
import { getConfirmation } from '../../../Common/utils/jsUtils';
import { getRunSqlQuery } from '../../../Common/utils/v1QueryUtils';

const getDropSchemaSql = schemaName => `drop schema "${schemaName}" cascade;`;

Expand All @@ -19,23 +20,9 @@ export const createNewSchema = (schemaName, successCb, errorCb) => {
);
}

const migrationUp = [
{
type: 'run_sql',
args: {
sql: getCreateSchemaSql(schemaName),
},
},
];
const migrationUp = [getRunSqlQuery(getCreateSchemaSql(schemaName))];

const migrationDown = [
{
type: 'run_sql',
args: {
sql: getDropSchemaSql(schemaName),
},
},
];
const migrationDown = [getRunSqlQuery(getDropSchemaSql(schemaName))];

const migrationName = `create_schema_${schemaName}`;
const requestMsg = 'Creating schema';
Expand Down Expand Up @@ -86,14 +73,7 @@ export const deleteCurrentSchema = (successCb, errorCb) => {
return;
}

const migrationUp = [
{
type: 'run_sql',
args: {
sql: getDropSchemaSql(currentSchema),
},
},
];
const migrationUp = [getRunSqlQuery(getDropSchemaSql(currentSchema))];
const migrationName = `drop_schema_${currentSchema}`;
const requestMsg = 'Dropping schema';
const successMsg = 'Successfully dropped schema';
Expand Down
Loading