API based Schema Migration behind experimental flag. - #10944
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the fdcapimigration experiment, allowing SQL schema migrations to be delegated to the FDC Backend instead of executing them locally via IAM. Key changes include adding the executeSchemaMigration client function, updating handleIncompatibleSchemaError to support this delegation, and adding corresponding unit tests. Feedback on the changes highlights a logic bug where superuser commands are incorrectly sent to the backend alongside owner commands, a style guide violation regarding the use of any types in the new client function, and a corresponding need to update the client unit tests to match the corrected types.
5c33791 to
84118d6
Compare
5eb7c73 to
0b52a03
Compare
|
/joe-review |
joehan
left a comment
There was a problem hiding this comment.
Code Review Summary: API-based Schema Migration (firebase/firebase-tools)
This PR introduces the fdcapimigration experimental flag to delegate SQL schema migrations to the FDC Backend. It also adds client-side preflight validation for new NOT NULL constraints.
🟢 Strengths & LGTM Aspects
Correctly gates the new schema migration path behind the fdcapimigration experimental flag.
Good test coverage for the new preflight validation logic and the conditional execution flow.
Standard cleanup of sinon stubs in afterEach hooks.
🔴 Overview of Findings & Action Items
AI/Agent Artifacts: A significant number of empty JSDoc comment blocks (/**\n *\n */) were added to functions in client.ts and schemaMigration.ts. These should be removed.
TypeScript Safety:
options in performClientSidePreflightValidation is typed as any and is unused.
Redundant as any cast on riskTags check in schemaMigration.ts.
Extensive use of any / as any in schemaMigration.spec.ts for mocking Schema, IncompatibleSqlSchemaError, and Options. Use proper type assertions or partial types instead.
API Design: performClientSidePreflightValidation has unused parameters (options, instanceId, databaseId) that should be removed.
🟡 Nits & Suggestions
The regex in performClientSidePreflightValidation assumes table names are always quoted. Consider making quotes optional for robustness.
| sinon.restore(); | ||
| }); | ||
|
|
||
| const schema: any = { |
There was a problem hiding this comment.
🔴 [TypeScript Safety] Avoid any in tests
Rationale: Using any reduces type safety even in tests. Use type assertions to Schema or Partial<Schema> instead.
Suggested Fix:
const schema = {
name: "projects/p/locations/l/services/s/schemas/main",
} as Schema;c917173 to
997b586
Compare
997b586 to
b8c0d73
Compare
### Description Updates a mocked `getIAMUser` return value in `schemaMigration.spec.ts` to use `"CLOUD_IAM_USER"` instead of `"IAM"` to satisfy the `UserType` interface and fix a TypeScript compilation error (TS2322). ### Scenarios Tested - `npm run test:compile` - `npx mocha src/dataconnect/schemaMigration.spec.ts` ### Sample Commands N/A
838cebc to
01127ae
Compare
This adds the
fdcapimigrationexperimental flag tosrc/experiments.tsand conditionally executes schema migration commands via the Firebase Data Connect (FDC) API Backend when enabled.