File size: 1,720 Bytes
80a4a65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
-- 010_challenge_files_bucket.sql
-- Supabase Storage bucket for AI-generated challenge files
-- (the fileToGenerate payload some generators return). The Python backend
-- uploads the file and returns the public URL in the training payload,
-- so NOTHING is ever written to the backend's local filesystem.

BEGIN;

INSERT INTO storage.buckets (id, name, public, file_size_limit, allowed_mime_types)
VALUES (
  'challenge-files',
  'challenge-files',
  true,
  5242880,  -- 5 MB max
  ARRAY[
    'text/plain', 'text/x-log', 'text/csv', 'text/html', 'text/xml',
    'application/json', 'application/octet-stream',
    'image/png', 'image/jpeg', 'image/gif', 'image/svg+xml',
    'application/x-pem-file', 'application/x-sh', 'application/x-yaml'
  ]
)
ON CONFLICT (id) DO UPDATE SET
  public = EXCLUDED.public,
  file_size_limit = EXCLUDED.file_size_limit,
  allowed_mime_types = EXCLUDED.allowed_mime_types;

-- Public read for everyone (same posture as log-analysis-files)
DROP POLICY IF EXISTS "Public read challenge-files" ON storage.objects;
CREATE POLICY "Public read challenge-files"
  ON storage.objects
  FOR SELECT
  USING (bucket_id = 'challenge-files');

-- Backend can upload (service-role key bypasses RLS anyway, but we
-- allow anon INSERT for the SUPABASE_ANON_KEY path too).
DROP POLICY IF EXISTS "Service role upload challenge-files" ON storage.objects;
CREATE POLICY "Service role upload challenge-files"
  ON storage.objects
  FOR INSERT
  WITH CHECK (bucket_id = 'challenge-files');

DROP POLICY IF EXISTS "Service role delete challenge-files" ON storage.objects;
CREATE POLICY "Service role delete challenge-files"
  ON storage.objects
  FOR DELETE
  USING (bucket_id = 'challenge-files');

COMMIT;