fix(media): prevent attaching an asset to a target twice
Drop `position` from the `asset_usages` unique constraint so the same asset can't be attached to one target/slot more than once, and update the insert's onConflict target + lookup to match the narrower key. Guard it at the service layer too: attachAssetService now rejects an attach when the asset already has a usage for that target with a new ASSET_ALREADY_ATTACHED (409) error, backed by an assetUsageExistsForTarget query.
This commit is contained in:
@@ -71,6 +71,7 @@ export const ErrorCodes = {
|
||||
ASSET_UPDATE_FAILED: 'ASSET_UPDATE_FAILED',
|
||||
ASSET_DELETE_FAILED: 'ASSET_DELETE_FAILED',
|
||||
ASSET_ATTACH_FAILED: 'ASSET_ATTACH_FAILED',
|
||||
ASSET_ALREADY_ATTACHED: 'ASSET_ALREADY_ATTACHED',
|
||||
ASSET_DETACH_FAILED: 'ASSET_DETACH_FAILED',
|
||||
ASSET_USAGE_FETCH_FAILED: 'ASSET_USAGE_FETCH_FAILED',
|
||||
ASSET_EXPORT_FAILED: 'ASSET_EXPORT_FAILED',
|
||||
|
||||
Reference in New Issue
Block a user