feat(supabase): sheet asset Storage bucket + read policy through the sheet, shim storage tables, seeds in the PGlite harness, upload script

This commit is contained in:
bchanot committed 2026-10-09 00:28:34 +02:00
1 parent 12f0b21fdf
commit f4682cdba5
10 files changed
+294 -7

No files matched your search

+14 -1
View File
@@ -1,6 +1,8 @@
/**
* PGlite harness: a real PostgreSQL (WASM) that applies the Supabase shim,
* then every migration under supabase/migrations, in filename order.
* then every migration under supabase/migrations, in filename order, then
* the versioned seeds under supabase/seed (same files `supabase db reset`
* applies through config.toml sql_paths).
* Lets the pgTAP suite and the schema checks run without Docker. The same
* SQL runs unchanged under `supabase test db` on the real stack.
*/
@@ -15,6 +17,8 @@ export const repoRoot = resolve(here, '../../../..')
export const supabaseDir = join(repoRoot, 'supabase')
export const migrationsDir = join(supabaseDir, 'migrations')
export const pgTapTestsDir = join(supabaseDir, 'tests')
/** Versioned seeds (reference data such as the official sheets); seed.sql itself needs the real auth schema and stays out. */
export const seedDir = join(supabaseDir, 'seed')
async function listSqlFiles(dir: string): Promise<string[]> {
const entries = await readdir(dir)
@@ -29,6 +33,12 @@ export async function listPgTapTests(): Promise<string[]> {
return listSqlFiles(pgTapTestsDir)
}
/** Every .sql under supabase/seed, recursively, in path order. */
export async function listSeeds(): Promise<string[]> {
const entries = await readdir(seedDir, { recursive: true }).catch(() => [])
return entries.filter((f) => f.endsWith('.sql')).sort()
}
/** Boots PGlite, installs the shim and applies all migrations. */
export async function createMigratedDatabase(): Promise<PGlite> {
const db = await PGlite.create({ extensions: { pgtap } })
@@ -39,6 +49,9 @@ export async function createMigratedDatabase(): Promise<PGlite> {
for (const file of await listMigrations()) {
await db.exec(await readFile(join(migrationsDir, file), 'utf8'))
}
for (const file of await listSeeds()) {
await db.exec(await readFile(join(seedDir, file), 'utf8'))
}
return db
}
@@ -73,3 +73,35 @@ grant usage on schema extensions to anon, authenticated, service_role;
alter default privileges in schema public grant all on tables to anon, authenticated, service_role;
alter default privileges in schema public grant all on functions to anon, authenticated, service_role;
alter default privileges in schema public grant all on sequences to anon, authenticated, service_role;
-- Storage schema stand-in (buckets + objects only, the columns the
-- migrations and tests touch). The real stack ships the full schema owned by
-- supabase_storage_admin; policies declared on storage.objects apply there.
create schema storage;
grant usage on schema storage to anon, authenticated, service_role;
create table storage.buckets (
id text primary key,
name text not null,
owner uuid,
public boolean default false,
file_size_limit bigint,
allowed_mime_types text[],
created_at timestamptz default now(),
updated_at timestamptz default now()
);
create table storage.objects (
id uuid primary key default gen_random_uuid(),
bucket_id text references storage.buckets (id),
name text,
owner uuid,
metadata jsonb,
created_at timestamptz default now(),
updated_at timestamptz default now(),
last_accessed_at timestamptz default now()
);
alter table storage.objects enable row level security;
grant select on storage.buckets to anon, authenticated, service_role;
grant select, insert, update, delete on storage.objects to anon, authenticated, service_role;