Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: flag to allow destructive schema changes #8273

Merged
merged 28 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9f21969
chore: dumping table changes
edwardfoyle Jul 29, 2021
8c774e8
chore: drop table POC
edwardfoyle Jul 30, 2021
e6b43f1
feat: plumb destructive-updates flag
edwardfoyle Sep 1, 2021
12e6c35
feat: plumb rebuild
edwardfoyle Sep 2, 2021
3da906f
chore: fix rebuild prompts
edwardfoyle Sep 2, 2021
6ae881c
test: adding unit and e2e tests
edwardfoyle Sep 3, 2021
bafa54f
feat: sweet jesus it works
edwardfoyle Sep 9, 2021
ef0524c
fix: iterative push lambda with updates
edwardfoyle Sep 9, 2021
bfb6b79
chore: organize code better
edwardfoyle Sep 9, 2021
a401594
test: add unit and e2e tests
edwardfoyle Sep 9, 2021
17f184d
chore: fit and finish
edwardfoyle Sep 10, 2021
99f7c1e
Merge remote-tracking branch 'upstream/master' into lil-bobby-tables
edwardfoyle Sep 10, 2021
673d0ba
chore: didn't save all the files
edwardfoyle Sep 10, 2021
79edbd5
test: fix some tests and add a couple more
edwardfoyle Sep 10, 2021
ea76931
chore: address PR comments
edwardfoyle Sep 22, 2021
a1bfc13
Merge remote-tracking branch 'upstream/master' into lil-bobby-tables
edwardfoyle Sep 22, 2021
7d6a130
Merge remote-tracking branch 'upstream/master' into lil-bobby-tables
edwardfoyle Sep 24, 2021
3bd02b1
test: fix e2e failures
edwardfoyle Sep 24, 2021
4e4d405
Merge remote-tracking branch 'upstream/master' into lil-bobby-tables
edwardfoyle Sep 30, 2021
2bfdacf
chore: fix prompts dep version
edwardfoyle Sep 30, 2021
c6f0769
test: exclude new api tests from windows
edwardfoyle Oct 1, 2021
56e95cf
Merge remote-tracking branch 'upstream/master' into lil-bobby-tables
edwardfoyle Oct 1, 2021
89d4d82
test: update test schema
edwardfoyle Oct 1, 2021
a7b7383
Merge remote-tracking branch 'upstream/master' into lil-bobby-tables
edwardfoyle Oct 5, 2021
4156fd2
Merge remote-tracking branch 'upstream/master' into lil-bobby-tables
edwardfoyle Oct 20, 2021
631cd8b
chore: address PR comments
edwardfoyle Oct 20, 2021
7779c5d
fix: messed up merge
edwardfoyle Oct 21, 2021
9acf7e3
test: fix e2e failures
edwardfoyle Oct 21, 2021
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
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 @@ -12134,6 +12221,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 @@ -12224,7 +12312,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 @@ -12239,6 +12327,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 @@ -12329,7 +12418,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 @@ -12388,6 +12477,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 @@ -12478,7 +12568,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 @@ -12493,6 +12583,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 @@ -12583,7 +12674,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
- IndexTransformer-e2e-graphql_e2e_tests
- ModelConnectionWithKeyTransformer-e2e-graphql_e2e_tests
Expand Down Expand Up @@ -12920,6 +13011,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 @@ -14540,7 +14649,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 @@ -14813,6 +14922,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 @@ -16481,7 +16608,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