这是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
8 changes: 8 additions & 0 deletions console/src/components/Common/Common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,10 @@ input {
margin-right: 20px !important;
}

.add_mar_right_mid {
margin-right: 10px !important;
}

.add_mar_right_small {
margin-right: 5px !important;
}
Expand All @@ -522,6 +526,10 @@ input {
margin-left: 5px;
}

.add_mar_left_mid {
margin-left: 10px;
}

.add_mar_small {
margin-right: 10px !important;
}
Expand Down
2 changes: 1 addition & 1 deletion console/src/components/Services/Common/Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const showErrorNotification = (title, message, reqBody, error) => {
modMessage = error ? error : message;
}

let finalJson = error ? error.message : '{}';
let finalJson = error ? error.message : null;

if (error && 'action' in error) {
refreshBtn = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const gqlTableErrorNotif = [
'',
{
custom:
'Table name cannot contain special characters. It can have alphabets, numbers (cannot start with numbers) and _ (can start with _)',
'Table name cannot contain special characters. It can have alphabets, numbers and _ (cannot start with numbers)',
},
'Error renaming table!',
];
Expand All @@ -17,7 +17,7 @@ const gqlColumnErrorNotif = [
'',
{
custom:
'Column name cannot contain special characters. It can have alphabets, numbers (cannot start with numbers) and _ (can start with _)',
'Column name cannot contain special characters. It can have alphabets, numbers and _ (cannot start with numbers)',
},
'Error renaming column!',
];
Expand All @@ -28,7 +28,7 @@ const gqlViewErrorNotif = [
'',
{
custom:
'View name cannot contain special characters. It can have alphabets, numbers (cannot start with numbers) and _ (can start with _)',
'View name cannot contain special characters. It can have alphabets, numbers and _ (cannot start with numbers)',
},
'Error renaming view!',
];
Expand All @@ -39,15 +39,26 @@ const gqlRelErrorNotif = [
'',
{
custom:
'Relationship name cannot contain special characters. It can have alphabets, numbers (cannot start with numbers) and _ (can start with _)',
'Relationship name cannot contain special characters. It can have alphabets, numbers and _ (cannot start with numbers)',
},
'Error renaming relationship!',
];

const gqlSchemaErrorNotif = [
'Error creating schema!',
'Schema name cannot contain special characters',
'',
{
custom:
'Schema name cannot contain special characters. It can have alphabets, numbers and _ (cannot start with numbers)',
},
];

export default gqlPattern;
export {
gqlTableErrorNotif,
gqlViewErrorNotif,
gqlColumnErrorNotif,
gqlRelErrorNotif,
gqlSchemaErrorNotif,
};
128 changes: 128 additions & 0 deletions console/src/components/Services/Data/Schema/Actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import gqlPattern, { gqlSchemaErrorNotif } from '../Common/GraphQLValidation';
import { showErrorNotification } from '../../Common/Notification';
import { makeMigrationCall, fetchSchemaList } from '../DataActions';

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

const getCreateSchemaSql = schemaName => `create schema "${schemaName}";`;

export const createNewSchema = (schemaName, successCb, errorCb) => {
return (dispatch, getState) => {
if (!gqlPattern.test(schemaName)) {
return dispatch(
showErrorNotification(
gqlSchemaErrorNotif[0],
gqlSchemaErrorNotif[1],
gqlSchemaErrorNotif[2],
gqlSchemaErrorNotif[3]
)
);
}

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

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

const migrationName = `create_schema_${schemaName}`;
const requestMsg = 'Creating schema';
const successMsg = 'Successfully created schema';
const errorMsg = 'Error creating schema';

const customOnSuccess = () => {
dispatch(fetchSchemaList());
if (successCb) {
successCb();
}
};
const customOnError = () => {
if (errorCb) {
errorCb();
}
};

makeMigrationCall(
dispatch,
getState,
migrationUp,
migrationDown,
migrationName,
customOnSuccess,
customOnError,
requestMsg,
successMsg,
errorMsg
);
};
};

export const deleteCurrentSchema = (successCb, errorCb) => {
return (dispatch, getState) => {
const { currentSchema } = getState().tables;

if (currentSchema === 'public') {
return dispatch(
showErrorNotification('Dropping public schema is not supported')
);
}

const isOk = window.confirm(
`Are you sure you want to delete the postgres schema: "${currentSchema}"`
);

if (!isOk) {
return;
}

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

const customOnSuccess = () => {
dispatch(fetchSchemaList());
if (successCb) {
successCb();
}
};
const customOnError = () => {
if (errorCb) {
errorCb();
}
};

makeMigrationCall(
dispatch,
getState,
migrationUp,
[],
migrationName,
customOnSuccess,
customOnError,
requestMsg,
successMsg,
errorMsg
);
};
};
Loading