fix: return user_metadata in list/search responses#952
fix: return user_metadata in list/search responses#952oniani1 wants to merge 4 commits intosupabase:masterfrom
Conversation
34d186b to
880d4ac
Compare
|
Hey, just wanted to bump this one -- the underlying issue has a good amount of user interest and the current workaround (calling .info() per file) adds unnecessary round trips. Happy to adjust anything if needed. |
Proves that storage.list() does not return user_metadata even though the data exists on the objects table. See supabase#759.
All four search functions (list_objects_with_delimiter, search, search_v2, search_by_timestamp) now include user_metadata in their return types and queries. Folders return NULL for user_metadata. Fixes supabase#759
PostgreSQL's CREATE OR REPLACE cannot change a function's return type. Added DROP FUNCTION IF EXISTS before each CREATE OR REPLACE, matching the pattern used in migration 0050.
f237727 to
f5199b7
Compare
Coverage Report for CI Build 24613523692Coverage remained the same at 68.127%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
|
Dug into why CI stays red after the rebase. The tests themselves pass (635/635), but the Verify migration idempotency step fails because 0059 drops and recreates search, list_objects_with_delimiter, search_v2, and search_by_timestamp with user_metadata added to the return type. Once 0059 has run, the idempotency test can't re-apply migration 10 (search-files-search-function), since that migration tries to CREATE OR REPLACE the same 8-param signature with the old return type and PG rejects the return type change. Two ways I can see to reshape this:
Happy to go whichever direction fits the codebase conventions better, or if there's a third preferred pattern, let me know. |
What kind of change does this PR introduce?
Bug fix - resolves #759
What is the current behavior?
storage.list()andlist-v2only return system metadata (size,mimetype,eTag) for each object. Customuser_metadataset during upload is omitted, forcing users to make N additional.info()calls to retrieve it.What is the new behavior?
All list/search endpoints now include
user_metadatain their response. Files return their storeduser_metadata; folders returnnull.Changes
SQL migration (
0059-search-functions-user-metadata.sql):user_metadata jsonbadded to theirRETURNS TABLEandSELECTqueries:storage.list_objects_with_delimiter(used by v2 name-sorted listing)storage.search(used by v1 listing, both name and non-name sorting paths)storage.search_v2(router that delegates to the above)storage.search_by_timestamp(used by v2 timestamp-sorted listing)DROP FUNCTION IF EXISTSis required before eachCREATE OR REPLACEbecause PostgreSQL cannot change a function's return type in-placeNULLforuser_metadatain all code pathsTypeScript (
knex.ts):'user_metadata'to the select array inlistObjectsV2for the non-delimiter direct query path (line 383)Test (
object.test.ts):user_metadatais present on files andnullon foldersVerification
user_metadatavia direct SQL queriesAdditional context
Objschema and route handlers already supporteduser_metadata-- the data just never left the database layeruser_metadatacolumn has existed onstorage.objectssince migration 0025.info()correctly returns it; only the search/list functions were missing itnormalizeColumnsalready stripsuser_metadatafor tenants below migration 25, and migrations run sequentially so the column always exists before this migration