-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathV5__files.surql
More file actions
31 lines (26 loc) · 1.63 KB
/
Copy pathV5__files.surql
File metadata and controls
31 lines (26 loc) · 1.63 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
DEFINE TABLE OVERWRITE file SCHEMAFULL
PERMISSIONS
FOR select, create, update, delete
WHERE owner = $auth.id OR owner IS NONE OR $auth.role = "admin";
DEFINE FIELD OVERWRITE owner ON TABLE file TYPE record<user> | NONE DEFAULT $auth.id;
DEFINE FIELD OVERWRITE filename ON TABLE file TYPE string;
DEFINE FIELD OVERWRITE parent ON file TYPE option<record<file>> DEFAULT NONE;
DEFINE FIELD OVERWRITE content_type ON TABLE file TYPE string;
DEFINE FIELD OVERWRITE chunking_metadata ON TABLE file TYPE option<object> FLEXIBLE DEFAULT NONE;
DEFINE FIELD OVERWRITE flow_chunked ON TABLE file TYPE option<string> DEFAULT NONE;
DEFINE FIELD OVERWRITE flow_keywords ON TABLE file TYPE option<string> DEFAULT NONE;
-- <string> is to avoid error when $this.filename is NONE. This happens when deleting a file.
DEFINE FIELD OVERWRITE path ON file COMPUTED (
($this.parent.path || '') + '/' + <string>$this.filename
) TYPE string;
-- DEFINE FIELD OVERWRITE is_folder ON TABLE file COMPUTED (
-- $this.file IS NONE AND $this.content IS NONE AND $this.symlink IS NONE
-- );
-- File content (folders are defined by leaving all of these empty)
DEFINE FIELD OVERWRITE file ON TABLE file TYPE option<bytes> DEFAULT NONE;
DEFINE FIELD OVERWRITE content ON TABLE file TYPE option<string> DEFAULT NONE;
DEFINE FIELD OVERWRITE symlink ON TABLE file TYPE option<file> DEFAULT NONE;
-- Timestamps
DEFINE FIELD OVERWRITE created_at ON TABLE file TYPE datetime VALUE time::now() READONLY;
DEFINE FIELD OVERWRITE updated_at ON TABLE file TYPE datetime VALUE time::now();
DEFINE FIELD OVERWRITE deleted_at ON TABLE file TYPE option<datetime> DEFAULT NONE;