Skip to content

fix(bb-distributed-data): reject ALTER TABLE DROP [COLUMN] for DSQL#200

Merged
adrianjoshua-strutt merged 4 commits into
aws-devtools-labs:mainfrom
fossamagna:fix/dsql-alter-table-drop-validation
Jul 20, 2026
Merged

fix(bb-distributed-data): reject ALTER TABLE DROP [COLUMN] for DSQL#200
adrianjoshua-strutt merged 4 commits into
aws-devtools-labs:mainfrom
fossamagna:fix/dsql-alter-table-drop-validation

Conversation

@fossamagna

@fossamagna fossamagna commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Problem

Aurora DSQL does not support ALTER TABLE DROP COLUMN — it is not in the supported ALTER TABLE subset. Deploying such a migration fails inside the migration Lambda with unsupported 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

  • Validation rule (packages/bb-distributed-data/src/validation.ts): an entry in the existing RULES array rejecting ALTER 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. Because validateStatement runs 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 ... SELECTDROPRENAME TO).
  • Docs (README.md, DESIGN.md): a row in the DSQL limitations / statement-validation tables.
  • Changeset: patch bump for @aws-blocks/bb-distributed-data.

The rule matches within a single statement ([^;]*) and does not fire on the ALTER TABLE ... DROP forms DSQL does support: DROP CONSTRAINT [IF EXISTS], and ALTER COLUMN ... DROP DEFAULT / DROP NOT NULL / DROP EXPRESSION / DROP IDENTITY — nor on RENAME TO or DROP 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 supported ALTER TABLE grammar (see the doc link above).

Validation

  • Unit tests (validation.test.ts): reject DROP COLUMN and the keyword-less shorthand spellings; regression cases confirm DROP CONSTRAINT, the ALTER COLUMN ... DROP actions, RENAME TO, and DROP TABLE still pass.
  • End-to-end mock test (e2e-mock.test.ts): the DsqlMockEngine rejects ALTER TABLE legacy DROP COLUMN obsolete — proving the original reproduction is now caught locally before any deploy.
  • Full bb-distributed-data suite: 152/152 passing.

Checklist

  • PR description included
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@fossamagna
fossamagna requested a review from a team as a code owner July 15, 2026 09:03
@fossamagna
fossamagna marked this pull request as draft July 15, 2026 12:31
@fossamagna fossamagna changed the title fix(bb-distributed-data): reject ALTER TABLE DROP COLUMN / DROP CONSTRAINT for DSQL fix(bb-distributed-data): reject ALTER TABLE DROP [COLUMN] for DSQL Jul 15, 2026
@fossamagna
fossamagna marked this pull request as ready for review July 15, 2026 14:10
@adrianjoshua-strutt

Copy link
Copy Markdown
Contributor

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!

@fossamagna

Copy link
Copy Markdown
Contributor Author

@adrianjoshua-strutt Thanks for the thorough review — especially for
throwing all those regex variants at the rule.

Added the batch test in validation.test.ts: a supported
ALTER COLUMN ... DROP DEFAULT followed by an unrelated DROP TABLE
in one semicolon-separated string, asserting no throw. Verified it
actually locks the behavior in: replacing [^;]* with .* in the rule
makes this test fail. Suite is now 153/153.

@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a17bf38

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@aws-blocks/bb-distributed-data Patch
@aws-blocks/blocks Patch

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.
@adrianjoshua-strutt
adrianjoshua-strutt force-pushed the fix/dsql-alter-table-drop-validation branch from 5311a6e to 30adf96 Compare July 20, 2026 11:36
…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.
@fossamagna

Copy link
Copy Markdown
Contributor Author

@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?

@adrianjoshua-strutt

Copy link
Copy Markdown
Contributor

Sure!

@adrianjoshua-strutt
adrianjoshua-strutt merged commit 0f3c73c into aws-devtools-labs:main Jul 20, 2026
24 checks passed
@fossamagna
fossamagna deleted the fix/dsql-alter-table-drop-validation branch July 21, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants