Skip to content

feat(databases-on-aws): add VALIDATE CONSTRAINT ASYNC guidance for DSQL - #238

Open
agarwal-govind wants to merge 2 commits into
awslabs:mainfrom
agarwal-govind:enable-validate-constraint-async
Open

feat(databases-on-aws): add VALIDATE CONSTRAINT ASYNC guidance for DSQL#238
agarwal-govind wants to merge 2 commits into
awslabs:mainfrom
agarwal-govind:enable-validate-constraint-async

Conversation

@agarwal-govind

@agarwal-govind agarwal-govind commented Jul 21, 2026

Copy link
Copy Markdown

Summary

DSQL now supports adding CHECK constraints with NOT VALID and validating them asynchronously via ALTER TABLE ASYNC ... VALIDATE CONSTRAINT. This adds that as the preferred approach for CHECK constraints (avoids full table recreation), following the same async DDL pattern as CREATE INDEX ASYNC.

This is the canonical steering home; the mirror in awslabs/mcp is updated in a sibling PR (see below).

Changes

  • constraint-operations.md: add "ADD CHECK CONSTRAINT (Preferred)" section — NOT VALIDVALIDATE CONSTRAINT ASYNC → monitor via sys.jobs / sys.wait_for_job. Split the old ADD CONSTRAINT section so UNIQUE/PK keep the table recreation pattern (only CHECK supports NOT VALID).
  • development-guide.md: add the ASYNC validate-constraint DDL rule and a Quick Reference example alongside CREATE INDEX ASYNC.
  • SKILL.md: add VALIDATE CONSTRAINT to the constraint-operations load trigger.
  • Bump databases-on-aws plugin (.claude-plugin + .codex-plugin) and marketplace.json to 1.7.0.

Part of the VALIDATE CONSTRAINT ASYNC rollout across the DSQL ecosystem:


Contributor Statement:

"By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license."

@agarwal-govind
agarwal-govind requested review from a team as code owners July 21, 2026 22:55
@anwesham-lab anwesham-lab changed the title databases-on-aws: add VALIDATE CONSTRAINT ASYNC guidance for DSQL fix(databases-on-aws): add VALIDATE CONSTRAINT ASYNC guidance for DSQL Jul 22, 2026
anwesham-lab
anwesham-lab previously approved these changes Jul 22, 2026

@anwesham-lab anwesham-lab left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@anwesham-lab

Copy link
Copy Markdown
Member

Looks like the formatter failed, can you run

npx dprint fmt

and/or

mise run fmt

and amend the commit?

anwesham-lab pushed a commit to awslabs/aurora-dsql-tools that referenced this pull request Jul 22, 2026
…#112)

## Summary

DSQL now supports `ALTER TABLE ASYNC ... VALIDATE CONSTRAINT` (the
`ASYNC` keyword is required), following the same async DDL pattern as
`CREATE INDEX ASYNC`. This updates `dsql-lint` so the `VALIDATE
CONSTRAINT` diagnostic guides users to the correct ASYNC form instead of
rejecting the operation as unsupported.

See the [Aurora DSQL ALTER TABLE
docs](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/working-with-postgresql-compatibility.html)
for the newly announced support.

## Changes

- Rename `LintRule::AtUnsupportedValidateConstraint` →
`ValidateConstraintAsync`
- Change the diagnostic from "not supported in DSQL" to "requires the
ASYNC keyword in DSQL", suggesting `ALTER TABLE ASYNC ... VALIDATE
CONSTRAINT` (monitor via `sys.jobs`)
- Update `fixture_for_rule()` for the renamed variant

## Note on scope

Kept as `Unfixable` for now: `sqlparser-dsql` 0.62.1 cannot yet parse
the `ALTER TABLE ASYNC` form, so auto-fix and clean-pass of the valid
ASYNC syntax will follow once the parser supports it.

## Testing

`cargo test` in `dsql-lint/` — all tests pass.
---

**Part of the `VALIDATE CONSTRAINT ASYNC` rollout across the DSQL
ecosystem:**
- dsql-lint: #112
- agent-plugins (canonical steering):
awslabs/agent-plugins#238
- mcp (mirror steering): awslabs/mcp#4300
@agarwal-govind agarwal-govind changed the title fix(databases-on-aws): add VALIDATE CONSTRAINT ASYNC guidance for DSQL feat(databases-on-aws): add VALIDATE CONSTRAINT ASYNC guidance for DSQL Jul 22, 2026
@agarwal-govind
agarwal-govind force-pushed the enable-validate-constraint-async branch from 9bcfe41 to 13e0877 Compare July 22, 2026 21:39
DSQL now supports adding CHECK constraints with NOT VALID and validating
them asynchronously via ALTER TABLE ASYNC ... VALIDATE CONSTRAINT. Add
this as the preferred approach for CHECK constraints (avoids full table
recreation), following the same async DDL pattern as CREATE INDEX ASYNC.

- constraint-operations.md: add 'ADD CHECK CONSTRAINT (Preferred)' section
  (NOT VALID -> VALIDATE CONSTRAINT ASYNC -> monitor via sys.jobs); split
  the old ADD CONSTRAINT section so UNIQUE/PK keep table recreation
- development-guide.md: add the ASYNC validate-constraint DDL rule and
  Quick Reference example alongside CREATE INDEX ASYNC
- SKILL.md: add VALIDATE CONSTRAINT to the constraint-operations load
  trigger; align DDL Migrations table column widths
- Bump databases-on-aws plugin + marketplace to 1.7.0
@agarwal-govind
agarwal-govind force-pushed the enable-validate-constraint-async branch from 59c2446 to 051fd7f Compare July 22, 2026 23:46
@amaksimo
amaksimo enabled auto-merge August 3, 2026 23:34
amaksimo added a commit to awslabs/aurora-dsql-orms that referenced this pull request Aug 3, 2026
… Django, SQLAlchemy, Hibernate (#528)

## Summary

DSQL now supports adding `CHECK` constraints to existing tables via
`ALTER TABLE ... ADD CONSTRAINT ... NOT VALID` followed by an
asynchronous `ALTER TABLE ASYNC ... VALIDATE CONSTRAINT`, and supports
inline `CHECK` constraints at `CREATE TABLE`. This PR enables real
`CHECK` constraint support across the Django, SQLAlchemy, and Hibernate
adapters, which previously skipped or disabled it.

## Changes

### Django (`python/django`)
- `features.py`: `supports_table_check_constraints = True`.
- `schema.py`: `sql_create_check` emits `ADD CONSTRAINT ... CHECK (...)
NOT VALID`; `add_constraint` issues `ALTER TABLE ASYNC ... VALIDATE
CONSTRAINT` as a follow-up so existing rows are validated. Removed the
old skip logic (inline CREATE TABLE checks and `DROP CONSTRAINT` are
supported).
- `reference/ADAPTER_BEHAVIOR.md`: replaced the "check constraints
skipped" section with async-validation behavior and the `NOT VALID`
caveat.

### SQLAlchemy (`python/sqlalchemy`)
- `base.py`: override `visit_add_constraint` to append `NOT VALID` for
`CheckConstraint` (non-CHECK unaffected). `supports_alter` stays `False`
(it also gates FK/PK-via-ALTER auto-ordering, still unsupported). The
async `VALIDATE CONSTRAINT` step is run separately (e.g.
`op.execute(...)` in Alembic), documented in the README.
- Inline `CHECK` at `CREATE TABLE` already worked and is unchanged.

### Hibernate (`java/hibernate`)
- `AuroraDSQLDialect.java`: `supportsColumnCheck()` returns `true`
(inline column CHECK at CREATE TABLE).

## Behavior caveat

`VALIDATE CONSTRAINT ASYNC` returns immediately; validation of existing
rows runs as an async DDL job. The constraint is enforced on new writes
right away. If existing rows violate it, the async job fails and the
constraint stays `NOT VALID` (track via `sys.jobs`).

## Testing

- Unit tests pass: Django (`pytest` schema + features), SQLAlchemy
compiler assertions, Hibernate (`gradlew test`).
- **Verified end-to-end against a gamma DSQL cluster** for all three:
inline CREATE TABLE checks; post-creation `ADD CONSTRAINT ... NOT VALID`
+ `VALIDATE CONSTRAINT ASYNC` (job `submitted` → `completed`, constraint
enforced); async failure on dirty data (`sys.jobs` status `failed`,
constraint stays `NOT VALID`); and confirmed a plain `ADD CONSTRAINT ...
CHECK` without `NOT VALID` is rejected by DSQL.

---

**Part of the `VALIDATE CONSTRAINT ASYNC` rollout across the DSQL
ecosystem:**
- dsql-lint: awslabs/aurora-dsql-tools#112
- agent-plugins (canonical steering):
awslabs/agent-plugins#238
- mcp (mirror steering): awslabs/mcp#4300
- aurora-dsql-orms (this PR)

---

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of the
[project
license](https://github.com/awslabs/aurora-dsql-orms/blob/main/LICENSE).

---------

Co-authored-by: Aleksandar Maksimovic <amaksimovic3@hotmail.com>

@pkale pkale left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm! Once this change goes in, we should add some eval tests to the agent to confirm that the agents behave in the expected manner as per the "preferred guidelines" provided in this ski update.

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.

6 participants