这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c67bfc2
fix migration schema down order
soorajshankar May 16, 2020
1f316be
fix down migration of a renamed column fails #3503
soorajshankar May 17, 2020
b87b8a7
Merge branch 'master' into chore/migration-schema-down-changes
soorajshankar May 29, 2020
23cc4ff
Migration Helper
soorajshankar May 30, 2020
8ea7ab0
Merge branch 'master' of https://github.com/hasura/graphql-engine int…
soorajshankar May 30, 2020
da21269
Merge branch 'chore/migration-schema-down-changes' of https://github.…
soorajshankar May 30, 2020
d6b0f0d
added utility getColumnUpdateMigration
soorajshankar May 30, 2020
2f99e19
house keeping
soorajshankar May 30, 2020
7c53a78
utils claenup
soorajshankar May 30, 2020
2759e92
typo function name
soorajshankar Jun 2, 2020
f71ef80
Merge branch 'master' into chore/migration-schema-down-changes
soorajshankar Jun 2, 2020
a7ccd01
Default pg comments on downquery :squash #3801
soorajshankar Jun 2, 2020
495e954
Merge branch 'master' into chore/migration-schema-down-changes
soorajshankar Jun 2, 2020
fdefb5f
Merge branch 'master' into chore/migration-schema-down-changes
soorajshankar Jun 3, 2020
22ca623
Update console/src/utils/migration/Migration.ts
soorajshankar Jun 5, 2020
bab03d4
review comments #4790
soorajshankar Jun 5, 2020
9e7aa3d
Merge branch 'master' of https://github.com/hasura/graphql-engine int…
soorajshankar Jun 5, 2020
dd7de3d
WIP: migration module with auto reversal logic
soorajshankar Jun 8, 2020
abcf409
Merge branch 'master' of https://github.com/hasura/graphql-engine int…
soorajshankar Jun 10, 2020
4a19513
WIP: Migration changes
soorajshankar Jun 10, 2020
9bdceb7
lint
soorajshankar Jun 10, 2020
b137d15
rename migration fix
soorajshankar Jun 10, 2020
326bf59
changelog
soorajshankar Jun 11, 2020
7522a14
removed extra makeRequest
soorajshankar Jun 11, 2020
9fd5e93
makeRequest with Migration calls
soorajshankar Jun 11, 2020
b663750
house keeping
soorajshankar Jun 11, 2020
5b2030e
modify scheme migration changes
soorajshankar Jun 11, 2020
1a73d15
Merge branch 'master' into chore/migration-schema-down-changes
soorajshankar Jun 11, 2020
10827b8
Update console/src/utils/migration/Migration.ts
soorajshankar Jun 15, 2020
9db7cd6
Merge branch 'master' of https://github.com/hasura/graphql-engine int…
soorajshankar Jun 19, 2020
8a91c20
review comments
soorajshankar Jun 19, 2020
87f8b61
Merge branch 'master' into chore/migration-schema-down-changes
soorajshankar Jun 22, 2020
9a332a9
Update console/src/utils/migration/utils.ts
Jun 22, 2020
260c286
Merge branch 'master' of https://github.com/hasura/graphql-engine int…
soorajshankar Jun 24, 2020
d187671
Merge branch 'master' into chore/migration-schema-down-changes
Jul 8, 2020
8059041
Update CHANGELOG.md
Jul 8, 2020
5a852bb
Update CHANGELOG.md
Jul 8, 2020
5336905
Merge branch 'master' of https://github.com/hasura/graphql-engine int…
soorajshankar Jul 23, 2020
a4e3fdf
add comments only for run_sql up migrations
soorajshankar Jul 23, 2020
58a8d25
format
soorajshankar Jul 23, 2020
777e640
format
soorajshankar Jul 27, 2020
66ce794
format
soorajshankar Jul 27, 2020
3a69bd5
Merge branch 'master' of https://github.com/hasura/graphql-engine int…
soorajshankar Jul 27, 2020
f058f82
Merge branch 'master' into chore/migration-schema-down-changes
rikinsk Aug 6, 2020
680afdc
Merge branch 'master' into chore/migration-schema-down-changes
rikinsk Aug 11, 2020
3072e50
add down migration comments for runSQL migrations
soorajshankar Aug 27, 2020
ea0fc8d
Merge branch 'master' of https://github.com/hasura/graphql-engine int…
soorajshankar Aug 27, 2020
af532c0
fix types
soorajshankar Aug 27, 2020
bd937f2
Merge branch 'master' into chore/migration-schema-down-changes
soorajshankar Aug 28, 2020
3190c58
fix type
soorajshankar Aug 28, 2020
0797ce2
Merge branch 'master' of https://github.com/hasura/graphql-engine int…
soorajshankar Oct 13, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ This release contains the [PDV refactor (#4111)](https://github.com/hasura/graph
- 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 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