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