mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-07 04:23:40 +09:00
## Description
The issue that postgres doesn't allow automatically set null on specific
field in multi-column FK contraints
i.e.following is not possible
```
FOREIGN KEY ("previewImageAssetId", "id") REFERENCES "Asset"("id", "projectId") ON DELETE SET previewImageAssetId=NULL
```
## Fix
1. Create assets before project created on clone (otherwise we need
magic like DEFERRABLE INITIALLY IMMEDIATE on constraints)
2. Drop project asset reference before asset delete (can be done with
trigger but too magical for the only edgecase)
## Steps for reproduction
Add asset to home page, delete it, no issues.
Duplicate project - no issues.
## Code Review
- [ ] hi @kof, I need you to do
- conceptual review (architecture, feature-correctness)
- detailed review (read every line)
- test it on preview
## Before requesting a review
- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")
## Before merging
- [ ] tested locally and on preview environment (preview dev login:
5de6)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env.example`
and the `builder/env-check.js` if mandatory