Skip to content

Storage.objects table should not use fk constraint with owners column on auth.users id column #276

@GaryAustin1

Description

@GaryAustin1

Bug report

Describe the bug

Currently there is a foreign key relation on objects owner column to auth.users id column that is not needed and causes constant problems for users and questions in Discord and Github.

I'm classifying this as a bug, not just an improvement, as it is a feature that seems to serve no useful purpose and causes users to try and implement delete cascade on storage.objects, just delete rows in storage.objects, and/or waste time before reaching out for help when deleting a user with an error (violating fk relation on storage objects) that they know nothing about.

The crux of the issue is that you can't just add a cascade delete to the objects table as then files are orphaned in storage.
You can't delete a user if there are files associated with that user in objects.

It is better to allow the user be deleted without error, than to have a customer not understand deleting the objects row does not remove the file and ( forever?) orphans the file in s3 storage. When the customer realizes there are orphaned rows in the objects table (no owner in auth.users) they can address the issue. Worst case is they have extra object table rows, versus orphaned s3 storage.

I believe currently the only way to deal with this is to have a delete trigger function on any table associated with a file and use the http extension to make a storage API delete call. This does NOT depend on the fk relation as a trigger is involved.

Not having the fk relation would also allow users to run a cron task to clean up orphaned files in the object table.

Another option is for Supabase to put cascade delete on the constraint AND make sure if an object row is deleted the appropriate trigger function is applied to delete the file from s3 storage.

To Reproduce

Add a file with a signed in user.
Then delete the user.

Expected behavior

Do not have an fk constraint.

Screenshots

System information

Additional context

Sorry for classifying as bug, but this has caused many issues that are unnecessary for users, IMO.
Here is a long time issue on this: #65
But this comes up weekly in support forums.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions