Skip to content

Commit

Permalink
Merge branch 'master' into docs-page-track-relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
rikinsk authored Oct 14, 2020
2 parents 46961aa + 6299d1c commit 6ee8295
Show file tree
Hide file tree
Showing 99 changed files with 4,710 additions and 1,745 deletions.
1 change: 1 addition & 0 deletions .circleci/server-upgrade-downgrade/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ get_server_upgrade_tests() {
--deselect test_graphql_mutations.py::TestGraphqlInsertPermission::test_backend_user_no_admin_secret_fail \
--deselect test_graphql_mutations.py::TestGraphqlMutationCustomSchema::test_update_article \
--deselect test_graphql_queries.py::TestGraphQLQueryEnums::test_introspect_user_role \
--deselect test_schema_stitching.py::TestRemoteSchemaQueriesOverWebsocket::test_remote_query_error \
"${args[@]}" 1>/dev/null 2>/dev/null
set +x
cat "$tmpfile"
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ This release contains the [PDV refactor (#4111)](https://github.com/hasura/graph

(Add entries here in the order of: server, console, cli, docs, others)

- server: add `--websocket-compression` command-line flag for enabling websocket compression (fix #3292)
- server: some mutations that cannot be performed will no longer be in the schema (for instance, `delete_by_pk` mutations won't be shown to users that do not have select permissions on all primary keys) (#4111)
- server: miscellaneous description changes (#4111)
- server: treat the absence of `backend_only` configuration and `backend_only: false` equally (closing #5059) (#4111)
Expand All @@ -77,14 +78,17 @@ This release contains the [PDV refactor (#4111)](https://github.com/hasura/graph
- server: accept only non-negative integers for batch size and refetch interval (close #5653) (#5759)
- server: limit the length of event trigger names (close #5786)
**NOTE:** If you have event triggers with names greater than 42 chars, then you should update their names to avoid running into Postgres identifier limit bug (#5786)
- server: validate remote schema queries (fixes #4143)
- console: allow user to cascade Postgres dependencies when dropping Postgres objects (close #5109) (#5248)
- console: mark inconsistent remote schemas in the UI (close #5093) (#5181)
- cli: add missing global flags for seed command (#5565)
- cli: allow seeds as alias for seed command (#5693)
- console: remove ONLY as default for ALTER TABLE in column alter operations (close #5512) #5706
- console: add option to flag an insertion as a migration from `Data` section (close #1766) (#4933)
- console: add `<3 hasura` section to view updates and notifications from Hasura (#5070)
- console: add notifications (#5070)
- console: down migrations improvements (close #3503, #4988) (#4790)
- docs: add docs page on networking with docker (close #4346) (#4811)
- docs: add tabs for console / cli / api workflows (close #3593) (#4948)
- docs: add postgres concepts page to docs (close #4440) (#4471)


Expand Down
10 changes: 5 additions & 5 deletions console/src/components/Common/utils/v1QueryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ export type Header = {

export const getRunSqlQuery = (
sql: string,
shouldCascade?: boolean,
readOnly?: boolean
cascade = false,
read_only = false
) => {
return {
type: 'run_sql',
args: {
sql: terminateSql(sql),
cascade: !!shouldCascade,
read_only: !!readOnly,
cascade,
read_only,
},
};
};
Expand Down Expand Up @@ -306,7 +306,7 @@ export const getFetchCustomTypesQuery = () => {
};
};

type CustomRootFields = {
export type CustomRootFields = {
select: string;
select_by_pk: string;
select_aggregate: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const setDefaults = () => ({
});

const MAKE_REQUEST = 'Actions/Permissions/MAKE_REQUEST';
export const makeRequest = () => ({ type: MAKE_REQUEST });
export const makePermRequest = () => ({ type: MAKE_REQUEST });
const REQUEST_SUCCESS = 'Actions/Permissions/REQUEST_SUCCESS';
export const setRequestSuccess = () => ({ type: REQUEST_SUCCESS });
const REQUEST_FAILURE = 'Actions/Permissions/REQUEST_FAILURE';
Expand Down
36 changes: 17 additions & 19 deletions console/src/components/Services/Actions/Permissions/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,48 @@ import {
getDropActionPermissionQuery,
} from '../../../Common/utils/v1QueryUtils';
import { findActionPermission } from '../utils';
import Migration from '../../../../utils/migration/Migration';

export const getActionPermissionQueries = (
export const getActionPermissionMigration = (
permissionEdit,
allPermissions,
actionName
) => {
const { role, newRole, filter } = permissionEdit;

const upQueries = [];
const downQueries = [];

const permRole = (newRole || role).trim();

const existingPerm = findActionPermission(allPermissions, permRole);

const migration = new Migration();
if (newRole || (!newRole && !existingPerm)) {
upQueries.push(
getCreateActionPermissionQuery(
migration.add(
(getCreateActionPermissionQuery(
{
role: permRole,
filter,
},
actionName
)
),
getDropActionPermissionQuery(permRole, actionName))
);
downQueries.push(getDropActionPermissionQuery(permRole, actionName));
}

if (existingPerm) {
upQueries.push(getDropActionPermissionQuery(permRole, actionName));
upQueries.push(
getCreateActionPermissionQuery({ role: permRole, filter }, actionName)
migration.add(
getDropActionPermissionQuery(permRole, actionName),
getDropActionPermissionQuery(permRole, actionName)
);
downQueries.push(getDropActionPermissionQuery(permRole, actionName));
upQueries.push(

migration.add(
getCreateActionPermissionQuery({ role: permRole, filter }, actionName)
); // TODO Down queries
migration.add(
getCreateActionPermissionQuery(
{ role: permRole, filter: existingPerm.definition.select.filter },
actionName
)
);
); // TODO Down queries
}

return {
upQueries,
downQueries,
};
return migration;
};
94 changes: 50 additions & 44 deletions console/src/components/Services/Actions/ServerIO.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,19 @@ import {
} from './Modify/reducer';

import {
makeRequest as makePermRequest,
makePermRequest,
setRequestSuccess as setPermRequestSuccess,
setRequestFailure as setPermRequestFailure,
} from './Permissions/reducer';
import { getActionPermissionMigration } from './Permissions/utils';
import Migration from '../../../utils/migration/Migration';
import {
findAction,
getActionPermissions,
removePersistedDerivedAction,
persistDerivedAction,
updatePersistedDerivation,
} from './utils';
import { getActionPermissionQueries } from './Permissions/utils';

export const fetchActions = () => {
return (dispatch, getState) => {
Expand Down Expand Up @@ -177,6 +178,8 @@ export const createAction = () => (dispatch, getState) => {
return;
}
}
// Migration queries start
const migration = new Migration();

const customFieldsQueryUp = generateSetCustomTypesQuery(
reformCustomTypes(mergedTypes)
Expand All @@ -185,6 +188,7 @@ export const createAction = () => (dispatch, getState) => {
const customFieldsQueryDown = generateSetCustomTypesQuery(
reformCustomTypes(existingTypesList)
);
migration.add(customFieldsQueryUp, customFieldsQueryDown);

const actionQueryUp = generateCreateActionQuery(
state.name,
Expand All @@ -194,8 +198,8 @@ export const createAction = () => (dispatch, getState) => {

const actionQueryDown = generateDropActionQuery(state.name);

const upQueries = [customFieldsQueryUp, actionQueryUp];
const downQueries = [actionQueryDown, customFieldsQueryDown];
migration.add(actionQueryUp, actionQueryDown);
// Migration queries end

const migrationName = `create_action_${state.name}`;
const requestMsg = 'Creating action...';
Expand All @@ -219,8 +223,8 @@ export const createAction = () => (dispatch, getState) => {
makeMigrationCall(
dispatch,
getState,
upQueries,
downQueries,
migration.upMigration,
migration.downMigration,
migrationName,
customOnSuccess,
customOnError,
Expand Down Expand Up @@ -325,22 +329,19 @@ export const saveAction = currentAction => (dispatch, getState) => {
currentAction.comment
);

let upQueries;
let downQueries;
// Migration queries start
const migration = new Migration();
if (!isActionNameChange) {
upQueries = [customFieldsQueryUp, updateCurrentActionQuery];
downQueries = [customFieldsQueryDown, rollbackActionQuery];
migration.add(customFieldsQueryUp, customFieldsQueryDown);
migration.add(updateCurrentActionQuery, rollbackActionQuery);
} else {
const isOk = getConfirmation(
'You seem to have changed the action name. This will cause the permissions to be dropped.'
);
if (!isOk) return;
upQueries = [
dropCurrentActionQuery,
customFieldsQueryUp,
createNewActionQuery,
];
downQueries = [actionQueryDown, customFieldsQueryDown, oldActionQueryUp];
migration.add(dropCurrentActionQuery, oldActionQueryUp);
migration.add(customFieldsQueryUp, customFieldsQueryDown);
migration.add(createNewActionQuery, actionQueryDown);
}

const migrationName = `modify_action_${currentAction.action_name}_to_${state.name}`;
Expand Down Expand Up @@ -368,8 +369,8 @@ export const saveAction = currentAction => (dispatch, getState) => {
makeMigrationCall(
dispatch,
getState,
upQueries,
downQueries,
migration.upMigration,
migration.downMigration,
migrationName,
customOnSuccess,
customOnError,
Expand All @@ -385,11 +386,17 @@ export const deleteAction = currentAction => (dispatch, getState) => {
if (!isOk) {
return;
}
const upQuery = generateDropActionQuery(currentAction.action_name);
const downQuery = generateCreateActionQuery(
currentAction.action_name,
currentAction.action_defn,
currentAction.comment

// Migration queries start
const migration = new Migration();

migration.add(
generateDropActionQuery(currentAction.action_name),
generateCreateActionQuery(
currentAction.action_name,
currentAction.action_defn,
currentAction.comment
)
);

const migrationName = `delete_action_${currentAction.action_name}`;
Expand All @@ -410,8 +417,8 @@ export const deleteAction = currentAction => (dispatch, getState) => {
makeMigrationCall(
dispatch,
getState,
[upQuery],
[downQuery],
migration.upMigration,
migration.downMigration,
migrationName,
customOnSuccess,
customOnError,
Expand Down Expand Up @@ -478,9 +485,9 @@ export const addActionRel = (relConfig, successCb, existingRelConfig) => (
const customTypesQueryDown = generateSetCustomTypesQuery(
reformCustomTypes(existingTypes)
);

const upQueries = [customTypesQueryUp];
const downQueries = [customTypesQueryDown];
// Migration queries start
const migration = new Migration();
migration.add(customTypesQueryUp, customTypesQueryDown);

const migrationName = `save_rel_${relConfig.name}_on_${relConfig.typename}`;
const requestMsg = 'Saving relationship...';
Expand All @@ -500,8 +507,8 @@ export const addActionRel = (relConfig, successCb, existingRelConfig) => (
makeMigrationCall(
dispatch,
getState,
upQueries,
downQueries,
migration.upMigration,
migration.downMigration,
migrationName,
customOnSuccess,
customOnError,
Expand Down Expand Up @@ -537,9 +544,8 @@ export const removeActionRel = (relName, typename, successCb) => (
const customTypesQueryDown = generateSetCustomTypesQuery(
reformCustomTypes(existingTypes)
);

const upQueries = [customTypesQueryUp];
const downQueries = [customTypesQueryDown];
const migration = new Migration();
migration.add(customTypesQueryUp, customTypesQueryDown);

const migrationName = 'remove_action_rel'; // TODO: better migration name
const requestMsg = 'Removing relationship...';
Expand All @@ -560,8 +566,8 @@ export const removeActionRel = (relName, typename, successCb) => (
makeMigrationCall(
dispatch,
getState,
upQueries,
downQueries,
migration.upMigration,
migration.downMigration,
migrationName,
customOnSuccess,
customOnError,
Expand All @@ -584,7 +590,7 @@ export const saveActionPermission = (successCb, errorCb) => (
findAction(allActions, currentAction)
);

const { upQueries, downQueries } = getActionPermissionQueries(
const migration = getActionPermissionMigration(
permissionEdit,
allPermissions,
currentAction
Expand Down Expand Up @@ -614,8 +620,8 @@ export const saveActionPermission = (successCb, errorCb) => (
makeMigrationCall(
dispatch,
getState,
upQueries,
downQueries,
migration.upMigration,
migration.downMigration,
migrationName,
customOnSuccess,
customOnError,
Expand All @@ -639,10 +645,10 @@ export const removeActionPermission = (successCb, errorCb) => (

const { role, filter } = permissionEdit;

const upQuery = getDropActionPermissionQuery(role, currentAction);
const downQuery = getCreateActionPermissionQuery(
{ role, filter },
currentAction
const migration = new Migration();
migration.add(
getDropActionPermissionQuery(role, currentAction),
getCreateActionPermissionQuery({ role, filter }, currentAction)
);

const migrationName = 'removing_action_perm';
Expand All @@ -669,8 +675,8 @@ export const removeActionPermission = (successCb, errorCb) => (
makeMigrationCall(
dispatch,
getState,
[upQuery],
[downQuery],
migration.upMigration,
migration.downMigration,
migrationName,
customOnSuccess,
customOnError,
Expand Down
Loading

0 comments on commit 6ee8295

Please sign in to comment.