-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Flag to allow schema changes that require table replacement (#8144
) * 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
- Loading branch information
1 parent
cf2a56d
commit 2d4e65a
Showing
32 changed files
with
1,298 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/amplify-category-api/src/__tests__/commands/api/rebuild.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { $TSContext, FeatureFlags, stateManager } from 'amplify-cli-core'; | ||
import { printer, prompter, exact } from 'amplify-prompts'; | ||
|
||
const subcommand = 'rebuild'; | ||
const category = 'api'; | ||
|
||
export const name = subcommand; | ||
|
||
const rebuild = true; | ||
|
||
export const run = async (context: $TSContext) => { | ||
if (!FeatureFlags.getBoolean('graphqlTransformer.enableIterativeGSIUpdates')) { | ||
printer.error('Iterative GSI Updates must be enabled to rebuild an API. See https://docs.amplify.aws/cli/reference/feature-flags/'); | ||
return; | ||
} | ||
const apiNames = Object.entries(stateManager.getMeta()?.api || {}) | ||
.filter(([_, meta]) => (meta as any).service === 'AppSync') | ||
.map(([name]) => name); | ||
if (apiNames.length === 0) { | ||
printer.info('No GraphQL API configured in the project. Only GraphQL APIs can be rebuilt. To add a GraphQL API run `amplify add api`.'); | ||
return; | ||
} | ||
if (apiNames.length > 1) { | ||
// this condition should never hit as we have upstream defensive logic to prevent multiple GraphQL APIs. But just to cover all the bases | ||
printer.error( | ||
'You have multiple GraphQL APIs in the project. Only one GraphQL API is allowed per project. Run `amplify remove api` to remove an API.', | ||
); | ||
return; | ||
} | ||
const apiName = apiNames[0]; | ||
printer.warn(`This will recreate all tables backing models in your GraphQL API ${apiName}.`); | ||
printer.warn('ALL EXISTING DATA IN THESE TABLES WILL BE LOST.'); | ||
await prompter.input('Type the name of the API to confirm you want to continue', { | ||
validate: exact(apiName, 'Input does not match the GraphQL API name'), | ||
}); | ||
const { amplify, parameters } = context; | ||
const resourceName = parameters.first; | ||
amplify.constructExeInfo(context); | ||
return amplify.pushResources(context, category, resourceName, undefined, rebuild); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.