Skip to content

Commit

Permalink
feat: flag to allow destructive schema changes (#8273)
Browse files Browse the repository at this point in the history
* chore: dumping table changes

* chore: drop table POC

* feat: plumb destructive-updates flag

* feat: plumb rebuild

* chore: fix rebuild prompts

* test: adding unit and e2e tests

* feat: sweet jesus it works

* fix: iterative push lambda with updates

* chore: organize code better

* test: add unit and e2e tests

* chore: fit and finish

* chore: didn't save all the files

* test: fix some tests and add a couple more

* chore: address PR comments

* test: fix e2e failures

* chore: fix prompts dep version

* test: exclude new api tests from windows

* test: update test schema

* chore: address PR comments

* fix: messed up merge

* test: fix e2e failures
  • Loading branch information
edwardfoyle authored Oct 21, 2021
1 parent f078323 commit 18de856
Show file tree
Hide file tree
Showing 39 changed files with 1,445 additions and 226 deletions.
143 changes: 135 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6310,6 +6310,58 @@ jobs:
AMPLIFY_PATH: /home/circleci/repo/packages/amplify-cli/bin/amplify
TEST_SUITE: src/__tests__/api_5.test.ts
CLI_REGION: ap-southeast-1
api_6-amplify_e2e_tests:
working_directory: ~/repo
parameters:
os:
type: executor
default: linux
executor: << parameters.os >>
steps:
- attach_workspace:
at: ./
- restore_cache:
key: >-
amplify-cli-yarn-deps-{{ .Branch }}-{{ checksum "yarn.lock" }}-{{
arch }}
- restore_cache:
key: amplify-verdaccio-cache-{{ .Branch }}-{{ .Revision }}
- restore_cache:
key: amplify-pkg-binaries-{{ .Branch }}-{{ .Revision }}
- run:
name: Start verdaccio, install node CLI and amplify-app
command: |
source .circleci/local_publish_helpers.sh
startLocalRegistry "$(pwd)/.circleci/verdaccio.yaml"
setNpmRegistryUrlToLocal
changeNpmGlobalPath
npm install -g @aws-amplify/cli
npm install -g amplify-app
unsetNpmRegistryUrl
- run:
name: Run E2e Tests
command: |
source .circleci/local_publish_helpers.sh
retry runE2eTest
no_output_timeout: 90m
- run:
name: Scan And Cleanup E2E Test Artifacts
command: |
if ! yarn ts-node .circleci/scan_artifacts.ts; then
echo "Cleaning the repository"
git clean -fdx
exit 1
fi
when: always
- store_test_results:
path: packages/amplify-e2e-tests/
- store_artifacts:
path: ~/repo/packages/amplify-e2e-tests/amplify-e2e-reports
environment:
AMPLIFY_DIR: /home/circleci/repo/packages/amplify-cli/bin
AMPLIFY_PATH: /home/circleci/repo/packages/amplify-cli/bin/amplify
TEST_SUITE: src/__tests__/api_6.test.ts
CLI_REGION: ap-southeast-2
schema-iterative-update-4-amplify_e2e_tests:
working_directory: ~/repo
parameters:
Expand Down Expand Up @@ -6361,7 +6413,7 @@ jobs:
AMPLIFY_DIR: /home/circleci/repo/packages/amplify-cli/bin
AMPLIFY_PATH: /home/circleci/repo/packages/amplify-cli/bin/amplify
TEST_SUITE: src/__tests__/schema-iterative-update-4.test.ts
CLI_REGION: ap-southeast-2
CLI_REGION: us-east-2
api_4-amplify_e2e_tests_pkg:
parameters:
os:
Expand Down Expand Up @@ -10011,6 +10063,41 @@ jobs:
environment:
TEST_SUITE: src/__tests__/api_5.test.ts
CLI_REGION: ap-southeast-1
api_6-amplify_e2e_tests_pkg:
parameters:
os:
type: executor
default: os.linux
executor: << parameters.os >>
working_directory: ~/repo
steps:
- attach_workspace:
at: ./
- restore_cache:
key: >-
amplify-cli-yarn-deps-{{ .Branch }}-{{ checksum "yarn.lock" }}-{{
arch }}
- restore_cache:
key: amplify-verdaccio-cache-{{ .Branch }}-{{ .Revision }}
- restore_cache:
key: amplify-build-artifact-{{ .Revision }}-{{ arch }}
- restore_cache:
key: amplify-pkg-binaries-{{ .Branch }}-{{ .Revision }}
- install_yarn:
os: << parameters.os >>
- install_packaged_cli:
os: << parameters.os >>
- run_e2e_tests:
os: << parameters.os >>
- scan_e2e_test_artifacts:
os: << parameters.os >>
- store_test_results:
path: packages/amplify-e2e-tests/
- store_artifacts:
path: packages/amplify-e2e-tests/amplify-e2e-reports
environment:
TEST_SUITE: src/__tests__/api_6.test.ts
CLI_REGION: ap-southeast-2
schema-iterative-update-4-amplify_e2e_tests_pkg:
parameters:
os:
Expand Down Expand Up @@ -10045,7 +10132,7 @@ jobs:
path: packages/amplify-e2e-tests/amplify-e2e-reports
environment:
TEST_SUITE: src/__tests__/schema-iterative-update-4.test.ts
CLI_REGION: ap-southeast-2
CLI_REGION: us-east-2
AuthV2Transformer-e2e-graphql_e2e_tests:
working_directory: ~/repo
parameters:
Expand Down Expand Up @@ -12164,6 +12251,7 @@ workflows:
- schema-iterative-rollback-2-amplify_e2e_tests
- function_1-amplify_e2e_tests
- schema-iterative-update-3-amplify_e2e_tests
- schema-iterative-update-4-amplify_e2e_tests
- auth_6-amplify_e2e_tests
- frontend_config_drift-amplify_e2e_tests
- iam-permissions-boundary-amplify_e2e_tests
Expand Down Expand Up @@ -12254,7 +12342,7 @@ workflows:
- schema-iterative-rollback-1-amplify_e2e_tests
- migration-api-key-migration3-amplify_e2e_tests
- schema-auth-6-amplify_e2e_tests
- schema-iterative-update-4-amplify_e2e_tests
- api_6-amplify_e2e_tests
- api_4-amplify_e2e_tests_pkg
- custom_policies_function-amplify_e2e_tests_pkg
- hooks-amplify_e2e_tests_pkg
Expand All @@ -12269,6 +12357,7 @@ workflows:
- schema-iterative-rollback-2-amplify_e2e_tests_pkg
- function_1-amplify_e2e_tests_pkg
- schema-iterative-update-3-amplify_e2e_tests_pkg
- schema-iterative-update-4-amplify_e2e_tests_pkg
- auth_6-amplify_e2e_tests_pkg
- frontend_config_drift-amplify_e2e_tests_pkg
- iam-permissions-boundary-amplify_e2e_tests_pkg
Expand Down Expand Up @@ -12359,7 +12448,7 @@ workflows:
- schema-iterative-rollback-1-amplify_e2e_tests_pkg
- migration-api-key-migration3-amplify_e2e_tests_pkg
- schema-auth-6-amplify_e2e_tests_pkg
- schema-iterative-update-4-amplify_e2e_tests_pkg
- api_6-amplify_e2e_tests_pkg
- >-
migration_tests-auth-deployment-migration-auth-deployment-secrets-amplify_migration_tests_v4
- update_tests-function_migration_update-amplify_migration_tests_v4
Expand Down Expand Up @@ -12418,6 +12507,7 @@ workflows:
- schema-iterative-rollback-2-amplify_e2e_tests
- function_1-amplify_e2e_tests
- schema-iterative-update-3-amplify_e2e_tests
- schema-iterative-update-4-amplify_e2e_tests
- auth_6-amplify_e2e_tests
- frontend_config_drift-amplify_e2e_tests
- iam-permissions-boundary-amplify_e2e_tests
Expand Down Expand Up @@ -12508,7 +12598,7 @@ workflows:
- schema-iterative-rollback-1-amplify_e2e_tests
- migration-api-key-migration3-amplify_e2e_tests
- schema-auth-6-amplify_e2e_tests
- schema-iterative-update-4-amplify_e2e_tests
- api_6-amplify_e2e_tests
- api_4-amplify_e2e_tests_pkg
- custom_policies_function-amplify_e2e_tests_pkg
- hooks-amplify_e2e_tests_pkg
Expand All @@ -12523,6 +12613,7 @@ workflows:
- schema-iterative-rollback-2-amplify_e2e_tests_pkg
- function_1-amplify_e2e_tests_pkg
- schema-iterative-update-3-amplify_e2e_tests_pkg
- schema-iterative-update-4-amplify_e2e_tests_pkg
- auth_6-amplify_e2e_tests_pkg
- frontend_config_drift-amplify_e2e_tests_pkg
- iam-permissions-boundary-amplify_e2e_tests_pkg
Expand Down Expand Up @@ -12613,7 +12704,7 @@ workflows:
- schema-iterative-rollback-1-amplify_e2e_tests_pkg
- migration-api-key-migration3-amplify_e2e_tests_pkg
- schema-auth-6-amplify_e2e_tests_pkg
- schema-iterative-update-4-amplify_e2e_tests_pkg
- api_6-amplify_e2e_tests_pkg
- AuthV2Transformer-e2e-graphql_e2e_tests
- HttpTransformerV2-e2e-graphql_e2e_tests
- ModelConnectionTransformer-e2e-graphql_e2e_tests
Expand Down Expand Up @@ -12951,6 +13042,24 @@ workflows:
parameters:
os:
- linux
- schema-iterative-update-4-amplify_e2e_tests:
context:
- amplify-ecr-image-pull
- cleanup-resources
- e2e-auth-credentials
- e2e-test-context
filters:
branches:
only:
- master
- /tagged-release\/.*/
- /run-e2e\/.*/
requires:
- publish_to_local_registry
matrix:
parameters:
os:
- linux
- auth_6-amplify_e2e_tests:
context:
- amplify-ecr-image-pull
Expand Down Expand Up @@ -14571,7 +14680,7 @@ workflows:
parameters:
os:
- linux
- schema-iterative-update-4-amplify_e2e_tests:
- api_6-amplify_e2e_tests:
context:
- amplify-ecr-image-pull
- cleanup-resources
Expand Down Expand Up @@ -14844,6 +14953,24 @@ workflows:
parameters:
os:
- linux
- schema-iterative-update-4-amplify_e2e_tests_pkg:
context:
- amplify-ecr-image-pull
- cleanup-resources
- e2e-auth-credentials
- e2e-test-context
filters:
branches:
only:
- master
- /tagged-release\/.*/
- /run-e2e\/.*/
requires:
- build_pkg_binaries
matrix:
parameters:
os:
- linux
- auth_6-amplify_e2e_tests_pkg:
context:
- amplify-ecr-image-pull
Expand Down Expand Up @@ -16512,7 +16639,7 @@ workflows:
os:
- linux
- windows
- schema-iterative-update-4-amplify_e2e_tests_pkg:
- api_6-amplify_e2e_tests_pkg:
context:
- amplify-ecr-image-pull
- cleanup-resources
Expand Down
25 changes: 8 additions & 17 deletions packages/amplify-category-api/amplify-plugin.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
{
"name": "api",
"type": "category",
"commands": [
"add-graphql-datasource",
"add",
"console",
"gql-compile",
"push",
"remove",
"update",
"help"
],
"commandAliases":{
"configure": "update"
},
"eventHandlers": []
}
"name": "api",
"type": "category",
"commands": ["add-graphql-datasource", "add", "console", "gql-compile", "push", "rebuild", "remove", "update", "help"],
"commandAliases": {
"configure": "update"
},
"eventHandlers": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { $TSContext, FeatureFlags, stateManager } from 'amplify-cli-core';
import { printer, prompter } from 'amplify-prompts';
import { mocked } from 'ts-jest/utils';
import { run } from '../../../commands/api/rebuild';

jest.mock('amplify-cli-core');
jest.mock('amplify-prompts');

const FeatureFlags_mock = mocked(FeatureFlags);
const stateManager_mock = mocked(stateManager);
const printer_mock = mocked(printer);
const prompter_mock = mocked(prompter);

FeatureFlags_mock.getBoolean.mockReturnValue(true);

beforeEach(jest.clearAllMocks);

const pushResourcesMock = jest.fn();

const context_stub = {
amplify: {
constructExeInfo: jest.fn(),
pushResources: pushResourcesMock,
},
parameters: {
first: 'resourceName',
},
} as unknown as $TSContext;

it('prints error if iterative updates not enabled', async () => {
FeatureFlags_mock.getBoolean.mockReturnValueOnce(false);

await run(context_stub);

expect(printer_mock.error.mock.calls.length).toBe(1);
expect(pushResourcesMock.mock.calls.length).toBe(0);
});

it('exits early if no api in project', async () => {
stateManager_mock.getMeta.mockReturnValueOnce({
api: {},
});

await run(context_stub);

expect(printer_mock.info.mock.calls.length).toBe(1);
expect(pushResourcesMock.mock.calls.length).toBe(0);
});

it('asks for strong confirmation before continuing', async () => {
stateManager_mock.getMeta.mockReturnValueOnce({
api: {
testapiname: {
service: 'AppSync',
},
},
});

await run(context_stub);

expect(prompter_mock.input.mock.calls.length).toBe(1);
expect(pushResourcesMock.mock.calls.length).toBe(1);
expect(pushResourcesMock.mock.calls[0][4]).toBe(true); // rebuild flag is set
});
5 changes: 5 additions & 0 deletions packages/amplify-category-api/src/commands/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ module.exports = {
name: 'console',
description: 'Opens the web console for the selected api service',
},
{
name: 'rebuild',
description:
'Removes and recreates all DynamoDB tables backing a GraphQL API. Useful for resetting test data during the development phase of an app',
},
];

context.amplify.showHelp(header, commands);
Expand Down
Loading

0 comments on commit 18de856

Please sign in to comment.