safe-migrate 0.4.0

Lint PostgreSQL migrations against live database statistics to prevent blocking locks
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
# Constraints AST Reference for safe-migrate

## Status

Verified against squawk_syntax 2.58.0 — July 2026

This document is derived from direct inspection of src/ast/generated/nodes.rs
and src/ast/node_ext.rs in squawk-syntax-2.58.0 and should be treated as the
current source of truth for safe-migrate constraint handling.

This document records only behavior that has been AST-verified via grep and
line-range inspection.

Where information is incomplete it is explicitly marked as unresolved rather
than inferred.

---

## Documentation Contract

This document follows four rules:

1. Only document AST behavior that has been directly verified.
2. Do not infer PostgreSQL semantics from missing AST accessors.
3. Distinguish verified facts from unresolved areas.
4. Assume additional nodes, helpers, or grammar constructs may exist outside the inspected surface.

Accordingly:

- findings in this document are AST-verified
- unresolved areas remain unresolved
- future AST archaeology may discover additional helpers or nodes
- this document may be extended but should not be contradicted without new AST evidence

---

## Handwritten Extension Policy

Only one handwritten extension exists for constraint types:

```
impl ast::ForeignKeyConstraint  (line 38440)
```

Verified by exhaustive grep documented in `columns.md`.
All other constraint types expose only generated accessors.

---

# High-Level Constraint Model

The verified AST surface exposes:

**Enums:**
- `Constraint`
- `ColumnConstraint`
- `TableConstraint`

**Identity:**
- `ConstraintName`

**Lifecycle operations:**
- `AddConstraint`
- `DropConstraint`
- `RenameConstraint`
- `ValidateConstraint`
- `AlterConstraint`

**Concrete constraint nodes:**
- `CheckConstraint`
- `PrimaryKeyConstraint`
- `UniqueConstraint`
- `ForeignKeyConstraint`
- `ReferencesConstraint`
- `ExcludeConstraint`
- `DefaultConstraint`
- `GeneratedConstraint`
- `NotNullConstraint`
- `NullConstraint`

**Supporting nodes:**
- `ConstraintExclusion`
- `ConstraintExclusionList`
- `ConstraintIndexMethod`
- `ConstraintIncludeClause`
- `ConstraintIndexTablespace`
- `ReferencesTable`
- `WhereConditionClause`

**Constraint-bearing structures:**
- `Column`
- `AddColumn`
- `DropColumn`

---

# Core Constraint Enums

## Constraint

### Verified Members

```rust
pub enum Constraint {
    CheckConstraint(CheckConstraint),
    DefaultConstraint(DefaultConstraint),
    ForeignKeyConstraint(ForeignKeyConstraint),
    GeneratedConstraint(GeneratedConstraint),
    NotNullConstraint(NotNullConstraint),
    NullConstraint(NullConstraint),
    PrimaryKeyConstraint(PrimaryKeyConstraint),
    ReferencesConstraint(ReferencesConstraint),
    UniqueConstraint(UniqueConstraint),
}
```

### Evidence

Verified via `From<X> for Constraint` impls in ast_accessors.txt.

### safe-migrate guidance

Normalize into an internal constraint model:

```rust
enum ConstraintKind {
    Check,
    Default,
    ForeignKey,
    Generated,
    NotNull,
    Null,
    PrimaryKey,
    References,
    Unique,
}
```

---

## ColumnConstraint

### Verified Members

```rust
pub enum ColumnConstraint {
    CheckConstraint(CheckConstraint),
    DefaultConstraint(DefaultConstraint),
    ExcludeConstraint(ExcludeConstraint),
    NotNullConstraint(NotNullConstraint),
    PrimaryKeyConstraint(PrimaryKeyConstraint),
    ReferencesConstraint(ReferencesConstraint),
    UniqueConstraint(UniqueConstraint),
}
```

### Evidence

Verified via grep line 19478 and `From<X> for ColumnConstraint` impls.

### Notes

- `ForeignKeyConstraint` is NOT a member of `ColumnConstraint`.
- `ExcludeConstraint` IS a member of both `ColumnConstraint` and `TableConstraint`.

### safe-migrate guidance

Column identity must not be discarded when extracting column constraints:

```rust
ColumnConstraintFact {
    column: String,
    constraint_kind: ConstraintKind,
    constraint_name: Option<String>,
    payload: ConstraintPayload,
}
```

---

## TableConstraint

### Verified Members

```rust
pub enum TableConstraint {
    CheckConstraint(CheckConstraint),
    ExcludeConstraint(ExcludeConstraint),
    ForeignKeyConstraint(ForeignKeyConstraint),
    PrimaryKeyConstraint(PrimaryKeyConstraint),
    UniqueConstraint(UniqueConstraint),
}
```

### Evidence

Verified via grep lines 19939 and 37578 and `From<X> for TableConstraint` impls.

### safe-migrate guidance

Primary extraction point for:

- multi-column primary keys
- multi-column unique constraints
- table-level check constraints
- table-level foreign keys
- exclusion constraints

---

# Constraint Identity

## ConstraintName

### Verified Accessors

```rust
// line 3961
pub fn name(&self) -> Option<Name>
pub fn constraint_token(&self) -> Option<SyntaxToken>
```

### safe-migrate guidance

Constraint names must be preserved as first-class identifiers:

```rust
struct ConstraintIdentity {
    name: Option<String>,
    kind: ConstraintKind,
}
```

Required for: DROP CONSTRAINT, RENAME CONSTRAINT, VALIDATE CONSTRAINT, ALTER CONSTRAINT.

---

# Constraint Lifecycle Operations

## AddConstraint

### Verified Accessors

```rust
pub fn constraint(&self) -> Option<Constraint>
pub fn deferrable_constraint_option(&self) -> Option<DeferrableConstraintOption>
pub fn enforced(&self) -> Option<Enforced>
pub fn initially_deferred_constraint_option(&self) -> Option<InitiallyDeferredConstraintOption>
pub fn initially_immediate_constraint_option(&self) -> Option<InitiallyImmediateConstraintOption>
pub fn no_inherit(&self) -> Option<NoInherit>
pub fn not_deferrable_constraint_option(&self) -> Option<NotDeferrableConstraintOption>
pub fn not_enforced(&self) -> Option<NotEnforced>
pub fn not_valid(&self) -> Option<NotValid>
pub fn add_token(&self) -> Option<SyntaxToken>
```

### Meaning

Represents:

```sql
ALTER TABLE t ADD CONSTRAINT name ...
```

### safe-migrate guidance

Resolve into:

```rust
Mutation::AddConstraint {
    constraint_identity: ConstraintIdentity,
    not_valid: bool,
    enforced: bool,
    deferrable: DeferrableState,
    no_inherit: bool,
}
```

---

## DropConstraint

### Verified Accessors

```rust
pub fn if_exists(&self) -> Option<IfExists>
pub fn name_ref(&self) -> Option<NameRef>
pub fn cascade_token(&self) -> Option<SyntaxToken>
pub fn constraint_token(&self) -> Option<SyntaxToken>
pub fn drop_token(&self) -> Option<SyntaxToken>
pub fn restrict_token(&self) -> Option<SyntaxToken>
```

### Meaning

Represents:

```sql
ALTER TABLE t DROP CONSTRAINT name [CASCADE | RESTRICT]
```

### safe-migrate guidance

```rust
Mutation::DropConstraint {
    name: String,
    if_exists: bool,
    cascade: bool,
}
```

Produce tombstones. Cascading drops must propagate through the dependency graph.

---

## RenameConstraint

### Verified Accessors

```rust
pub fn name(&self) -> Option<Name>       // new name
pub fn name_ref(&self) -> Option<NameRef> // old name
pub fn constraint_token(&self) -> Option<SyntaxToken>
pub fn rename_token(&self) -> Option<SyntaxToken>
pub fn to_token(&self) -> Option<SyntaxToken>
```

### Meaning

Represents:

```sql
ALTER TABLE t RENAME CONSTRAINT old TO new
```

### safe-migrate guidance

Treat as identity preservation. Do not model as drop + create.

---

## ValidateConstraint

### Verified Accessors

```rust
pub fn name_ref(&self) -> Option<NameRef>
pub fn constraint_token(&self) -> Option<SyntaxToken>
pub fn validate_token(&self) -> Option<SyntaxToken>
```

### Meaning

Represents:

```sql
ALTER TABLE t VALIDATE CONSTRAINT name
```

### safe-migrate guidance

Track validation as explicit state transition:

```
NotValid -> Validated
```

---

## AlterConstraint

### Verified Accessors

```rust
// line 615-638
pub fn option(&self) -> Option<AlterColumnOption>
pub fn alter_token(&self) -> Option<SyntaxToken>
pub fn constraint_token(&self) -> Option<SyntaxToken>
```

### Findings

- Node exists and is a member of `AlterTableAction` (line 19419, 33170).
- Exposes `AlterColumnOption` via `option()`. No direct accessor for constraint
  name, deferrability, validation state, or enforcement state on this node itself.

### Grammar Confirmation — FULLY RESOLVED

postgresql.ungram confirms:

```
AlterConstraint =
  'alter' 'constraint' option:AlterColumnOption

AlterTableAction =
  ...
| RenameTo
| RenameConstraint
| RenameColumn
| AlterConstraint
  ...
```

This is structurally identical to `AlterColumn`'s dispatch pattern (see columns.md) —
both route through the same `AlterColumnOption` enum. The grammar confirms there
is genuinely no constraint-name field on this node. Additionally, `AlterConstraint`
sits as a flat, unwrapped alternative directly inside `AlterTableAction`'s own
alternation — the same structural pattern already confirmed to definitively rule
out a sibling-node workaround for the trigger enable/disable gap (see triggers.md).
There is no wrapping node anywhere in the grammar that could carry the constraint
name alongside `AlterConstraint`.

**This means PostgreSQL's `ALTER TABLE t ALTER CONSTRAINT constraint_name
option` cannot have its target constraint name extracted from this AST in
any form.** The operation (deferrability/enforcement change) can be detected
as occurring against table `t`, but which specific constraint is targeted
cannot be determined. This is now considered a final, confirmed grammar
limitation — not an open question requiring further squawk.rs inspection.

### Status

```
Grammar verified — FULLY RESOLVED
Constraint name confirmed absent from AlterConstraint and from every
grammar position reachable around it (including the parent AlterTableAction
alternation, which provides no wrapping node). This is a genuine, final
limitation analogous to the trigger enable/disable name gap in triggers.md.
```

---

# Concrete Constraint Nodes

## CheckConstraint

### Verified Accessors

```rust
pub fn constraint_name(&self) -> Option<ConstraintName>
pub fn expr(&self) -> Option<Expr>
pub fn no_inherit(&self) -> Option<NoInherit>
pub fn l_paren_token(&self) -> Option<SyntaxToken>
pub fn r_paren_token(&self) -> Option<SyntaxToken>
pub fn check_token(&self) -> Option<SyntaxToken>
```

### safe-migrate guidance

```rust
CheckConstraintFact {
    name: Option<String>,
    expression: ExprIr,
    no_inherit: bool,
}
```

Expression must flow into ExprIr for rule evaluation.

---

## NotNullConstraint

### Verified Accessors

```rust
pub fn name_ref(&self) -> Option<NameRef>
pub fn no_inherit(&self) -> Option<NoInherit>
pub fn constraint_token(&self) -> Option<SyntaxToken>
pub fn not_token(&self) -> Option<SyntaxToken>
pub fn null_token(&self) -> Option<SyntaxToken>
```

Verified against the original `ast_accessors.txt` reference document (this
session's project knowledge source). This node was a documentation gap in
earlier drafts — listed as an enum member but never given its own section.

### Grammar Confirmation

postgresql.ungram confirms:

```
NotNullConstraint =
  ('constraint' NameRef)
  'not' 'null'
  NoInherit
```

### Cardinality Note

The grammar shows `NoInherit` without a `?`, suggesting it is unconditionally
present in the parse tree for this rule. The Rust accessor nonetheless returns
`Option<NoInherit>` — this is standard for this AST style (rowan-pattern
accessors are `Option<T>` regardless of grammar-level required/optional
status, since the tree node may still be absent due to parse errors or
partial trees). This is not treated as a discrepancy requiring further
investigation; it is the normal pattern observed throughout this AST.

### Meaning

Represents:

```sql
col_name type NOT NULL [NO INHERIT]
[CONSTRAINT name] NOT NULL ... NO INHERIT  -- with explicit constraint name
```

`NO INHERIT` prevents the NOT NULL constraint from being inherited by child
tables in traditional table inheritance (not partitioning).

### safe-migrate guidance

```rust
NotNullConstraintFact {
    name: Option<String>,    // from name_ref()
    no_inherit: bool,        // from no_inherit().is_some()
}
```

---

## PrimaryKeyConstraint

### Verified Accessors

```rust
pub fn column_list(&self) -> Option<ColumnList>
pub fn constraint_name(&self) -> Option<ConstraintName>
pub fn partition_item_list(&self) -> Option<PartitionItemList>
pub fn using_index(&self) -> Option<UsingIndex>
pub fn key_token(&self) -> Option<SyntaxToken>
pub fn primary_token(&self) -> Option<SyntaxToken>
```

### safe-migrate guidance

```rust
PrimaryKeyFact {
    name: Option<String>,
    columns: Vec<String>,
    using_index: Option<String>,
}
```

---

## UniqueConstraint

### Verified Accessors

```rust
pub fn column_list(&self) -> Option<ColumnList>
pub fn constraint_name(&self) -> Option<ConstraintName>
pub fn nulls_distinct(&self) -> Option<NullsDistinct>
pub fn nulls_not_distinct(&self) -> Option<NullsNotDistinct>
pub fn using_index(&self) -> Option<UsingIndex>
pub fn unique_token(&self) -> Option<SyntaxToken>
```

### safe-migrate guidance

```rust
UniqueConstraintFact {
    name: Option<String>,
    columns: Vec<String>,
    nulls_distinct: NullsDistinctState,
    using_index: Option<String>,
}
```

`NullsDistinctState` should be a three-way enum: `Distinct`, `NotDistinct`, `Unspecified`.

---

# Foreign Key Constraints

## ForeignKeyConstraint

### Verified Accessors — Generated (line 9573)

```rust
pub fn constraint_name(&self) -> Option<ConstraintName>
pub fn match_type(&self) -> Option<MatchType>
pub fn on_delete_action(&self) -> Option<OnDeleteAction>
pub fn on_update_action(&self) -> Option<OnUpdateAction>
pub fn path(&self) -> Option<Path>           // referenced table
pub fn foreign_token(&self) -> Option<SyntaxToken>
pub fn key_token(&self) -> Option<SyntaxToken>
pub fn references_token(&self) -> Option<SyntaxToken>
```

### Verified Accessors — Handwritten (line 38440)

```rust
pub fn from_columns(&self) -> Option<ast::ColumnList>  // local columns, nth(0)
pub fn to_columns(&self) -> Option<ast::ColumnList>    // referenced columns, nth(1)
```

### Findings

Complete FK mapping is available:

- local table: from the containing `AlterTable` or `CreateTable` context
- local columns: `from_columns()`
- referenced table: `path()`
- referenced columns: `to_columns()`
- match type: `match_type()`
- on delete: `on_delete_action()`
- on update: `on_update_action()`

### safe-migrate guidance

```rust
ForeignKeyFact {
    name: Option<String>,
    local_columns: Vec<String>,
    referenced_table: QualifiedName,
    referenced_columns: Vec<String>,
    match_type: MatchType,
    on_delete: ReferentialAction,
    on_update: ReferentialAction,
}
```

---

## ReferencesConstraint

### Verified Accessors (line 14729)

```rust
pub fn column(&self) -> Option<NameRef>              // single referenced column
pub fn constraint_name(&self) -> Option<ConstraintName>
pub fn match_type(&self) -> Option<MatchType>
pub fn on_delete_action(&self) -> Option<OnDeleteAction>
pub fn on_update_action(&self) -> Option<OnUpdateAction>
pub fn table(&self) -> Option<Path>                  // referenced table
pub fn l_paren_token(&self) -> Option<SyntaxToken>
pub fn r_paren_token(&self) -> Option<SyntaxToken>
pub fn references_token(&self) -> Option<SyntaxToken>
```

### Meaning

Column-level inline references form:

```sql
user_id bigint REFERENCES users(id) ON DELETE CASCADE
```

### Important Distinction

`column()` returns a single `NameRef`, not a list.
This is the inline column-level form only.
Table-level multi-column FKs use `ForeignKeyConstraint`.

### safe-migrate guidance

Normalize into the same `ForeignKeyFact` representation used by `ForeignKeyConstraint`.
Local column comes from the containing `Column` node.
Referenced column comes from `column()`.

---

## ReferencesTable

### Verified Accessors (line 14765)

```rust
pub fn column_list(&self) -> Option<ColumnList>
pub fn name_ref(&self) -> Option<NameRef>
pub fn l_paren_token(&self) -> Option<SyntaxToken>
pub fn r_paren_token(&self) -> Option<SyntaxToken>
pub fn references_token(&self) -> Option<SyntaxToken>
```

### Meaning

Standalone references-to-table node appearing in edge table definitions
(property graph context).

### Grammar Confirmation — RESOLVED

postgresql.ungram confirms:

```
ReferencesTable =
  'references' NameRef '(' ColumnList ')'

SourceVertexTable =
  'source' NameRef
| 'source' 'key' '(' ColumnList ')' ReferencesTable

DestVertexTable =
  'destination' NameRef
| 'destination' 'key' '(' ColumnList ')' ReferencesTable
```

`ReferencesTable` is exclusively used by `SourceVertexTable` and `DestVertexTable`
in the SQL/PGQ property graph grammar (`CREATE PROPERTY GRAPH`). It has no
relationship to `ForeignKeyConstraint` or `ReferencesConstraint` whatsoever —
these are entirely separate grammar features that happen to share similar
naming. Property graphs are out of scope for safe-migrate's table/column/index
safety analysis.

### Status

```
Grammar verified — RESOLVED
Confirmed unrelated to ForeignKeyConstraint/ReferencesConstraint.
Used exclusively in CREATE PROPERTY GRAPH vertex/edge table definitions.
```

---

# ExcludeConstraint

## ExcludeConstraint

### Verified Accessors (line 9112)

```rust
pub fn constraint_exclusion_list(&self) -> Option<ConstraintExclusionList>
pub fn constraint_index_method(&self) -> Option<ConstraintIndexMethod>
pub fn constraint_name(&self) -> Option<ConstraintName>
pub fn where_condition_clause(&self) -> Option<WhereConditionClause>
pub fn exclude_token(&self) -> Option<SyntaxToken>
```

### Membership

- Member of `ColumnConstraint` (line 19478)
- Member of `TableConstraint` (line 19939)

### Child: ConstraintExclusionList

```rust
// line 3897
pub fn constraint_exclusions(&self) -> AstChildren<ConstraintExclusion>
pub fn l_paren_token(&self) -> Option<SyntaxToken>
pub fn r_paren_token(&self) -> Option<SyntaxToken>
```

### Child: ConstraintExclusion (individual element, line 3878)

```rust
pub fn expr(&self) -> Option<Expr>    // the excluded expression
pub fn op(&self) -> Option<Op>        // the WITH operator
pub fn with_token(&self) -> Option<SyntaxToken>
```

### Child: ConstraintIndexMethod (line 3927)

```rust
pub fn using_token(&self) -> Option<SyntaxToken>
```

### Grammar Confirmation — RESOLVED

postgresql.ungram confirms:

```
ConstraintIndexMethod =
  'using'
```

This is the complete grammar rule — only the `USING` keyword token exists.
The index method name (e.g. `gist`, `btree`) genuinely is not part of this
node's grammar at all. This is not an accessor gap; it is confirmed that
`EXCLUDE USING method (...)` does not capture `method` as structured content
on `ConstraintIndexMethod` in this grammar version.

### Child: WhereConditionClause (line 18507)

```rust
pub fn expr(&self) -> Option<Expr>
pub fn l_paren_token(&self) -> Option<SyntaxToken>
pub fn r_paren_token(&self) -> Option<SyntaxToken>
pub fn where_token(&self) -> Option<SyntaxToken>
```

WHERE predicate expression is fully accessible.

### safe-migrate guidance

```rust
ExcludeConstraintFact {
    name: Option<String>,
    exclusions: Vec<ExclusionElement>,
    index_method: Option<String>,   // NOT extractable — ConstraintIndexMethod is grammar-confirmed empty
    where_expr: Option<ExprIr>,
}

struct ExclusionElement {
    expr: ExprIr,
    operator: OpIr,
}
```

---

# Additional Constraint Supporting Nodes

## ConstraintIncludeClause

### Verified Accessors (line 3916)

```rust
pub fn include_token(&self) -> Option<SyntaxToken>
```

### Grammar Confirmation — RESOLVED

postgresql.ungram confirms:

```
ConstraintIncludeClause =
  'include'
```

This is the complete grammar rule — only the `INCLUDE` keyword token exists.
The included column list genuinely is not part of this node's grammar.
This is not an accessor gap; `INCLUDE (col1, col2)` does not capture the
column list as structured content on `ConstraintIncludeClause` in this
grammar version. If the column list is captured anywhere, it would need to
be a sibling node, not a child of `ConstraintIncludeClause` itself — not
confirmed in this pass.

### Status

```
Grammar verified — FULLY RESOLVED
INCLUDE column list confirmed absent from the grammar entirely.
CreateIndex grammar: 'create' ... PartitionItemList ConstraintIncludeClause? ...
No sibling column-list node exists adjacent to ConstraintIncludeClause in
CreateIndex either. The INCLUDE column list in CREATE INDEX ... INCLUDE (cols)
is not captured anywhere in this AST grammar.
```
```

---

## ConstraintIndexTablespace

### Verified Accessors (line 3938)

```rust
pub fn name_ref(&self) -> Option<NameRef>
pub fn index_token(&self) -> Option<SyntaxToken>
pub fn tablespace_token(&self) -> Option<SyntaxToken>
pub fn using_token(&self) -> Option<SyntaxToken>
```

---

# DefaultConstraint

### Verified Membership

- Member of `Constraint` enum
- Member of `ColumnConstraint` enum

### Verified Accessors (line 6292)

```rust
pub fn expr(&self) -> Option<Expr>
pub fn name_ref(&self) -> Option<NameRef>
pub fn constraint_token(&self) -> Option<SyntaxToken>
pub fn default_token(&self) -> Option<SyntaxToken>
```

### safe-migrate guidance

```rust
DefaultConstraintFact {
    name: Option<String>,   // from name_ref()
    expression: ExprIr,     // from expr()
}
```

Expression must flow into ExprIr for rule evaluation.

---

# GeneratedConstraint

### Verified Membership

- Member of `Constraint` enum only

### Verified Accessors (line 9785)

```rust
pub fn expr(&self) -> Option<Expr>
pub fn name_ref(&self) -> Option<NameRef>
pub fn sequence_option_list(&self) -> Option<SequenceOptionList>
pub fn l_paren_token(&self) -> Option<SyntaxToken>
pub fn r_paren_token(&self) -> Option<SyntaxToken>
pub fn always_token(&self) -> Option<SyntaxToken>
pub fn as_token(&self) -> Option<SyntaxToken>
pub fn by_token(&self) -> Option<SyntaxToken>
pub fn constraint_token(&self) -> Option<SyntaxToken>
pub fn default_token(&self) -> Option<SyntaxToken>
pub fn generated_token(&self) -> Option<SyntaxToken>
pub fn identity_token(&self) -> Option<SyntaxToken>
pub fn stored_token(&self) -> Option<SyntaxToken>
```

### Meaning

Covers two PostgreSQL forms:

```sql
-- computed column
col type GENERATED ALWAYS AS (expr) STORED

-- identity column
col type GENERATED ALWAYS AS IDENTITY (sequence_options)
col type GENERATED BY DEFAULT AS IDENTITY (sequence_options)
```

Distinguishing between these two forms requires checking:
- `stored_token()` present → computed column form
- `identity_token()` present → identity column form
- `always_token()` vs `default_token()` → ALWAYS vs BY DEFAULT

### safe-migrate guidance

```rust
GeneratedConstraintFact {
    name: Option<String>,
    kind: GeneratedKind,    // Computed | IdentityAlways | IdentityByDefault
    expr: Option<ExprIr>,   // present for computed form
    sequence_options: Option<SequenceOptionsFact>, // present for identity form
}
```

---

# Column Constraint Sources

## Column

### Verified Accessors

```rust
pub fn constraints(&self) -> AstChildren<ColumnConstraint>
pub fn name(&self) -> Option<Name>
pub fn name_ref(&self) -> Option<NameRef>
pub fn ty(&self) -> Option<Type>
pub fn field_expr(&self) -> Option<FieldExpr>
pub fn index_expr(&self) -> Option<IndexExpr>
pub fn collate(&self) -> Option<Collate>
pub fn compression_method(&self) -> Option<CompressionMethod>
pub fn storage(&self) -> Option<Storage>
pub fn with_options(&self) -> Option<WithOptions>
pub fn period_token(&self) -> Option<SyntaxToken>
```

### safe-migrate guidance

```rust
ColumnFact {
    name: String,
    type_name: TypeIr,
    constraints: Vec<ColumnConstraintFact>,
}
```

Column identity must be preserved when extracting inline constraints.

---

## AddColumn

### Verified Accessors

```rust
pub fn constraints(&self) -> AstChildren<Constraint>
pub fn if_not_exists(&self) -> Option<IfNotExists>
pub fn name(&self) -> Option<Name>
pub fn ty(&self) -> Option<Type>
pub fn add_token(&self) -> Option<SyntaxToken>
pub fn column_token(&self) -> Option<SyntaxToken>
```

### Note

`AddColumn.constraints()` returns `AstChildren<Constraint>` not `AstChildren<ColumnConstraint>`.
This is a verified difference from `Column.constraints()`.

---

## DropColumn

### Verified Accessors

```rust
pub fn if_exists(&self) -> Option<IfExists>
pub fn name_ref(&self) -> Option<NameRef>
pub fn cascade_token(&self) -> Option<SyntaxToken>
pub fn column_token(&self) -> Option<SyntaxToken>
pub fn drop_token(&self) -> Option<SyntaxToken>
pub fn restrict_token(&self) -> Option<SyntaxToken>
```

### safe-migrate guidance

Dependency-aware column removal. CASCADE must propagate through the dependency graph
to all constraints referencing the dropped column.

---

# Verified Findings Summary

## Confirmed Complete

- `Constraint` enum: all 9 members verified
- `ColumnConstraint` enum: all 7 members verified
- `TableConstraint` enum: all 5 members verified
- `ForeignKeyConstraint`: fully resolved including handwritten `from_columns()` / `to_columns()`
- `ReferencesConstraint`: fully resolved
- `ExcludeConstraint`: fully resolved including child nodes
- `PrimaryKeyConstraint`: fully resolved
- `UniqueConstraint`: fully resolved
- `CheckConstraint`: fully resolved
- `DefaultConstraint`: fully resolved
- `GeneratedConstraint`: fully resolved
- `AddConstraint`: fully resolved
- `DropConstraint`: fully resolved
- `RenameConstraint`: fully resolved
- `ValidateConstraint`: fully resolved
- `Column`: fully resolved
- `AddColumn`: fully resolved
- `DropColumn`: fully resolved

## Confirmed Partial

- `AlterConstraint`: grammar-confirmed dispatch through AlterColumnOption, constraint name not on this node
- `ConstraintIncludeClause`: node verified, column list inaccessible through verified accessors
- `ConstraintIndexMethod`: node verified, method name string inaccessible through verified accessors
- `ReferencesTable`: grammar-confirmed, unrelated to FK nodes — property graph only

---

# Remaining Open Questions

None remaining. All four previously listed questions have been resolved:

1. The `AlterConstraint` constraint-name location has been confirmed as a
   final grammar limitation (no sibling node anywhere carries it) — see the
   AlterConstraint section above.
2. `ConstraintIncludeClause`'s column list has been confirmed grammar-empty
   — see the ConstraintIncludeClause section above.
3. `ConstraintIndexMethod`'s method name has been confirmed grammar-empty
   — see the ConstraintIndexMethod section above.
4. The standing caveat about additional handwritten extensions is addressed
   by the exhaustive `impl ast::*` inventory established in columns.md
   (lines 38145-39260 of squawk.rs), which covers the full handwritten
   extension surface for every node type, including all constraint nodes.
   No additional handwritten extensions beyond that inventory were found
   for any constraint type.