bug: DBML Ref delete/update actions ignored — all FKs emitted as ON DELETE NO ACTION #2
Closed
opened 2026-04-04 14:06:47 +00:00 by sgcommand
·
1 comment
No Branch/Tag Specified
master
issue-6-external-file-embedding
fix/bun-extra-fields-issue-4
v1.0.65
v1.0.64
v1.0.63
v1.0.62
v1.0.61
v1.0.60
v1.0.59
v1.0.58
v1.0.57
v1.0.56
v1.0.55
v1.0.54
v1.0.53
v1.0.52
v1.0.51
v1.0.50
v1.0.49
v1.0.48
v1.0.47
v1.0.46
v1.0.45
v1.0.44
v1.0.43
v1.0.42
v1.0.41-1-gf4b8fc5
v1.0.41
v1.0.40
v1.0.38-2-gee88c07-1-gdc9172c-dirty
v1.0.38-2-gee88c07
v1.0.39
v1.0.38
v1.0.37-1-g480038d
v1.0.37
v1.0.36
v1.0.35
v1.0.34
v1.0.33
v1.0.32
v1.0.31
v1.0.30
v1.0.29
v1.0.28
v1.0.27
v1.0.26
v1.0.25
v1.0.24
v1.0.22
v1.0.21
v1.0.20
v1.0.19
v1.0.18
v1.0.17
v1.0.16
v1.0.15
v1.0.14
v1.0.13
v1.0.12
v1.0.11
v1.0.10
v1.0.9
v1.0.8
v1.0.7
v1.0.6
v1.0.5
v1.0.4
v1.0.3
v1.0.2
v1.0.1
v1.0.0
Labels
Clear labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Breaking change that won't be backward compatible
Something is not working
Documentation changes
Improve existing functionality
New functionality
This is security issue
Issue or pull request related to testing
Priority
Critical
The priority is critical
Priority
High
The priority is high
Priority
Low
The priority is low
Priority
Medium
The priority is medium
Reviewed
Confirmed
Issue has been confirmed
Reviewed
Duplicate
This issue or pull request already exists
Reviewed
Invalid
Invalid issue
Reviewed
Won't Fix
This issue won't be fixed
Status
Abandoned
Somebody has started to work on this but abandoned work
Status
Blocked
Something is blocking this issue or pull request
Status
Need More Info
Feedback is required to reproduce issue or to continue work
Breaking change that won't be backward compatible
Something is not working
Documentation changes
Improve existing functionality
New functionality
This is security issue
Issue or pull request related to testing
Priority
Critical
1
The priority is critical
Priority
High
2
The priority is high
Priority
Low
4
The priority is low
Priority
Medium
3
The priority is medium
Reviewed
Confirmed
1
Issue has been confirmed
Reviewed
Duplicate
2
This issue or pull request already exists
Reviewed
Invalid
3
Invalid issue
Reviewed
Won't Fix
3
This issue won't be fixed
Status
Abandoned
3
Somebody has started to work on this but abandoned work
Status
Blocked
1
Something is blocking this issue or pull request
Status
Need More Info
2
Feedback is required to reproduce issue or to continue work
No labels
Milestone
No items
No Milestone
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: wdevs/relspecgo#2
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Summary
When converting a multi-file DBML schema to PostgreSQL DDL, relspecgo ignores the
[delete: ...]and[update: ...]action modifiers onRef:declarations. Every generated foreign key constraint is emitted asON DELETE NO ACTION ON UPDATE NO ACTIONregardless of what is specified in the source DBML.Environment
relspec(relspecgo)dbmlpgsqlReproduction
Input — cross-file
Ref:declarations (bottom ofschema/files.dbml)Input — inline column
[ref: ...]with delete action (same-file,schema/core.dbml)Original migration had
ON DELETE CASCADEforthought_links.from_idandthought_links.to_id.Top-level
Ref:declarations with explicit delete actions (fromschema/skills.dbml):And from
schema/meta.dbml:Generated output (from
migrations/020_generated_schema.sql)Every single FK in the output is:
No FK in the entire 4400-line generated file has anything other than
NO ACTION, regardless of whether the Ref specifiescascade,set null, orrestrict.Expected Behaviour
The pgsql writer should honour the
[delete: ...]/[update: ...]action modifiers from DBMLRef:declarations and emit the appropriateON DELETE/ON UPDATEclauses:[delete: cascade]ON DELETE CASCADE[delete: set null]ON DELETE SET NULL[delete: restrict]ON DELETE RESTRICT[delete: no action]ON DELETE NO ACTION[update: cascade]ON UPDATE CASCADEActual Behaviour
All FKs are emitted as
ON DELETE NO ACTION ON UPDATE NO ACTIONunconditionally.Areas to Investigate
pkg/readers/dbml/) — is the[delete: ...]modifier being parsed and stored on theRelationstruct, or silently dropped?Relation/ForeignKeystruct have a field for delete/update actions? If not, it needs one.pkg/writers/pgsql/) — even if the action is parsed and stored, is the writer reading it and emitting the correctON DELETEclause, or always defaulting toNO ACTION?[ref: > ...]on a column vs a top-levelRef:block) both carry delete actions through to the writer, or only one of them.Workaround
None currently. The generated SQL must be manually edited after generation to add correct
ON DELETE/ON UPDATEclauses, which defeats the purpose of schema-as-code.Related
Summary: The DBML parser only recognized ondelete: / onupdate: prefixes, but the standard DBML spec uses delete: and update:. Fixed by adding delete: / update: as the primary recognized prefixes (while retaining ondelete: / onupdate:
for backward compatibility). Updated the test data (complex.dbml) to use standard DBML syntax so the existing tests now verify the correct behavior.