|
| 1 | +-- Schema creation for simple-seed-storage test scenario |
| 2 | +-- Creates the app schema with storage tables (buckets, files, upload_requests) |
| 3 | + |
| 4 | +-- Create app schemas |
| 5 | +CREATE SCHEMA IF NOT EXISTS "simple-storage-public"; |
| 6 | + |
| 7 | +-- Grant schema usage |
| 8 | +GRANT USAGE ON SCHEMA "simple-storage-public" TO administrator, authenticated, anonymous; |
| 9 | + |
| 10 | +-- Set default privileges |
| 11 | +ALTER DEFAULT PRIVILEGES IN SCHEMA "simple-storage-public" |
| 12 | + GRANT ALL ON TABLES TO administrator; |
| 13 | +ALTER DEFAULT PRIVILEGES IN SCHEMA "simple-storage-public" |
| 14 | + GRANT USAGE ON SEQUENCES TO administrator, authenticated; |
| 15 | +ALTER DEFAULT PRIVILEGES IN SCHEMA "simple-storage-public" |
| 16 | + GRANT ALL ON FUNCTIONS TO administrator, authenticated, anonymous; |
| 17 | + |
| 18 | +-- ===================================================== |
| 19 | +-- STORAGE TABLES (mirroring what the storage module generator creates) |
| 20 | +-- ===================================================== |
| 21 | + |
| 22 | +-- Buckets table |
| 23 | +CREATE TABLE IF NOT EXISTS "simple-storage-public".buckets ( |
| 24 | + id uuid PRIMARY KEY DEFAULT uuid_generate_v4(), |
| 25 | + key text NOT NULL, |
| 26 | + type text NOT NULL DEFAULT 'private', |
| 27 | + is_public boolean NOT NULL DEFAULT false, |
| 28 | + owner_id uuid, |
| 29 | + allowed_mime_types text[] NULL, |
| 30 | + max_file_size bigint NULL, |
| 31 | + created_at timestamptz DEFAULT now(), |
| 32 | + updated_at timestamptz DEFAULT now(), |
| 33 | + UNIQUE (key) |
| 34 | +); |
| 35 | + |
| 36 | +COMMENT ON TABLE "simple-storage-public".buckets IS E'@storageBuckets\nStorage buckets table'; |
| 37 | + |
| 38 | +-- Files table |
| 39 | +CREATE TABLE IF NOT EXISTS "simple-storage-public".files ( |
| 40 | + id uuid PRIMARY KEY DEFAULT uuid_generate_v4(), |
| 41 | + bucket_id uuid NOT NULL REFERENCES "simple-storage-public".buckets(id), |
| 42 | + key text NOT NULL, |
| 43 | + content_type text NOT NULL, |
| 44 | + content_hash text, |
| 45 | + size bigint, |
| 46 | + filename text, |
| 47 | + owner_id uuid, |
| 48 | + is_public boolean NOT NULL DEFAULT false, |
| 49 | + status text NOT NULL DEFAULT 'pending', |
| 50 | + created_at timestamptz DEFAULT now(), |
| 51 | + updated_at timestamptz DEFAULT now() |
| 52 | +); |
| 53 | + |
| 54 | +COMMENT ON TABLE "simple-storage-public".files IS E'@storageFiles\nStorage files table'; |
| 55 | + |
| 56 | +-- Upload requests table |
| 57 | +CREATE TABLE IF NOT EXISTS "simple-storage-public".upload_requests ( |
| 58 | + id uuid PRIMARY KEY DEFAULT uuid_generate_v4(), |
| 59 | + file_id uuid NOT NULL REFERENCES "simple-storage-public".files(id), |
| 60 | + bucket_id uuid NOT NULL REFERENCES "simple-storage-public".buckets(id), |
| 61 | + key text NOT NULL, |
| 62 | + content_type text NOT NULL, |
| 63 | + content_hash text, |
| 64 | + size bigint, |
| 65 | + status text NOT NULL DEFAULT 'issued', |
| 66 | + expires_at timestamptz, |
| 67 | + confirmed_at timestamptz, |
| 68 | + created_at timestamptz DEFAULT now(), |
| 69 | + updated_at timestamptz DEFAULT now() |
| 70 | +); |
| 71 | + |
| 72 | +-- Grant table permissions (allow anonymous to do CRUD for tests — no RLS) |
| 73 | +GRANT SELECT, INSERT, UPDATE, DELETE ON "simple-storage-public".buckets TO administrator, authenticated, anonymous; |
| 74 | +GRANT SELECT, INSERT, UPDATE, DELETE ON "simple-storage-public".files TO administrator, authenticated, anonymous; |
| 75 | +GRANT SELECT, INSERT, UPDATE, DELETE ON "simple-storage-public".upload_requests TO administrator, authenticated, anonymous; |
0 commit comments