fix(bb-distributed-data): reject ALTER TABLE DROP [COLUMN] for DSQL#200
Conversation
|
Thanks for raising this. Overall this looks great. I pulled the branch down and ran the touched suites locally. I also threw a bunch of variants at the regex (keyword-less shorthand, IF EXISTS, quoted and schema qualified names, multi-clause, newlines between DROP and COLUMN) and it catches all of them, while correctly leaving the supported stuff alone (DROP CONSTRAINT, ALTER COLUMN ... DROP DEFAULT/NOT NULL/EXPRESSION/IDENTITY, RENAME TO, DROP TABLE, and DROP inside strings or comments). One small ask: Could you add a direct unit test for a semicolon separated batch? Something like a supported DROP DEFAULT in one statement followed by an unrelated statement, asserting it does not throw. The behavior is already correct, I'd just like to lock it in. Thanks again! |
|
@adrianjoshua-strutt Thanks for the thorough review — especially for Added the batch test in validation.test.ts: a supported |
🦋 Changeset detectedLatest commit: a17bf38 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
… CONSTRAINT rule Postgres allows omitting the COLUMN keyword (ALTER TABLE t DROP col), which bypassed the new rule. Extend the pattern to match the shorthand (including IF EXISTS and quoted identifiers) while still allowing the supported ALTER COLUMN ... DROP DEFAULT/NOT NULL/EXPRESSION/IDENTITY forms. Remove the DROP CONSTRAINT rule: per the DSQL ALTER TABLE grammar, DROP CONSTRAINT [IF EXISTS] ... [RESTRICT|CASCADE] is supported. https://docs.aws.amazon.com/aurora-dsql/latest/userguide/alter-table-syntax-support.html
…OLUMN rule Add a unit test for a semicolon-separated batch: a supported ALTER COLUMN ... DROP DEFAULT followed by an unrelated DROP TABLE must not trip the DROP COLUMN rule across the statement boundary.
5311a6e to
30adf96
Compare
…a docs The README rows added for the DROP COLUMN limitation sync into the @aws-blocks/blocks published docs/, so the Blocks Package Integrity check requires a patch bump for the umbrella package.
|
@adrianjoshua-strutt Sorry for the extra round — your approval got dismissed by a follow-up push. The only change since your review is a CI fix: the Blocks Package Integrity check flagged that the README rows added here sync into the published @aws-blocks/blocks docs/, so the existing changeset now also bumps "@aws-blocks/blocks": patch (same pattern as #220). No code changes. Could you re-approve when you get a chance? |
|
Sure! |
Problem
Aurora DSQL does not support
ALTER TABLE DROP COLUMN— it is not in the supportedALTER TABLEsubset. Deploying such a migration fails inside the migration Lambda withunsupported ALTER TABLE DROP COLUMN statement(0A000).The local mock runs on PGlite (full PostgreSQL), which accepts it, so the migration passes local development and only fails on the first real deploy — exactly the class of divergence the mock's DSQL validation layer is meant to close (same as #148 for index key sort order).
Issue #, if available: #199
Changes
packages/bb-distributed-data/src/validation.ts): an entry in the existingRULESarray rejectingALTER TABLE ... DROP [COLUMN]— including the keyword-less Postgres shorthand (DROP col,DROP IF EXISTS col, quoted identifiers), since Postgres parses it to the same DROP COLUMN action. BecausevalidateStatementruns from both the migration validator and the mock engine's query path, the failure now surfaces at dev time instead of on deploy. The error message includes the practical alternatives (leave the column in place, or rebuild the table: create new →INSERT INTO ... SELECT→DROP→RENAME TO).README.md,DESIGN.md): a row in the DSQL limitations / statement-validation tables.@aws-blocks/bb-distributed-data.The rule matches within a single statement (
[^;]*) and does not fire on theALTER TABLE ... DROPforms DSQL does support:DROP CONSTRAINT [IF EXISTS], andALTER COLUMN ... DROP DEFAULT/DROP NOT NULL/DROP EXPRESSION/DROP IDENTITY— nor onRENAME TOorDROP TABLE(all covered by tests). String literals and comments are stripped before matching.Note
An earlier revision of this PR also rejected
ALTER TABLE DROP CONSTRAINT. That rule was removed:DROP CONSTRAINT [IF EXISTS] ... [RESTRICT | CASCADE]is in DSQL's supportedALTER TABLEgrammar (see the doc link above).Validation
validation.test.ts): rejectDROP COLUMNand the keyword-less shorthand spellings; regression cases confirmDROP CONSTRAINT, theALTER COLUMN ... DROPactions,RENAME TO, andDROP TABLEstill pass.e2e-mock.test.ts): theDsqlMockEnginerejectsALTER TABLE legacy DROP COLUMN obsolete— proving the original reproduction is now caught locally before any deploy.bb-distributed-datasuite: 152/152 passing.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.