Files
Ivan Starkov 3c75c2126e fix: Fix db consistency issues with assets (#2876)
## 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
2024-02-07 20:26:57 +03:00
..
2024-02-07 15:46:22 +01:00
2024-02-07 15:46:22 +01:00