Skip to content

Commit

Permalink
fix: supabase/supabase#2497 prevent empty results when selecting fold…
Browse files Browse the repository at this point in the history
…er(s) in one bucket that match an object name in another bucket (#23)
  • Loading branch information
thebengeu committed Oct 11, 2021
1 parent f650e1a commit 72c8bf1
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions infra/postgres/storage-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,20 @@ CREATE OR REPLACE FUNCTION storage.search(prefix text, bucketname text, limits i
)
LANGUAGE plpgsql
AS $function$
DECLARE
_bucketId text;
BEGIN
select buckets."id" from buckets where buckets.name=bucketname limit 1 into _bucketId;
return query
with files_folders as (
select ((string_to_array(objects.name, '/'))[levels]) as folder
from objects
where objects.name ilike prefix || '%'
and bucket_id = _bucketId
and bucket_id = bucketname
GROUP by folder
limit limits
offset offsets
)
select files_folders.folder as name, objects.id, objects.updated_at, objects.created_at, objects.last_accessed_at, objects.metadata from files_folders
left join objects
on prefix || files_folders.folder = objects.name
where objects.id is null or objects.bucket_id=_bucketId;
on prefix || files_folders.folder = objects.name and objects.bucket_id=bucketname;
END
$function$;

Expand Down

0 comments on commit 72c8bf1

Please sign in to comment.