Repository navigation
Expand file tree
/
Copy path0036_model_library.sql
More file actions
44 lines (42 loc) · 1.82 KB
/
Copy path0036_model_library.sql
File metadata and controls
44 lines (42 loc) · 1.82 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
-- The model library: STL, 3MF, OBJ and STEP files you uploaded or that
-- Rollcall found in the library folder, grouped into models.
CREATE TABLE models (
id UUID PRIMARY KEY DEFAULT uuidv7(),
owner_id UUID NOT NULL REFERENCES users (id) ON DELETE CASCADE,
name TEXT NOT NULL CHECK (length(btrim(name)) > 0),
designer TEXT,
source_url TEXT,
license TEXT,
notes TEXT,
-- Another model this one belongs to (a part, a remix). No foreign key,
-- so a backup restores in any order; a missing parent reads as none.
parent_id UUID,
-- A file in UPLOAD_DIR/models.
thumbnail TEXT,
-- Where it came from in the library folder, for models a scan added.
library_path TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX models_owner_idx ON models (owner_id);
CREATE TABLE model_tags (
model_id UUID NOT NULL REFERENCES models (id) ON DELETE CASCADE,
tag VARCHAR(60) NOT NULL,
PRIMARY KEY (model_id, tag)
);
CREATE INDEX model_tags_tag_idx ON model_tags (tag);
CREATE TABLE model_files (
id UUID PRIMARY KEY DEFAULT uuidv7(),
model_id UUID NOT NULL REFERENCES models (id) ON DELETE CASCADE,
-- source 'upload': a file name in UPLOAD_DIR/models; 'library': a path
-- inside the library folder.
source TEXT NOT NULL CHECK (source IN ('upload', 'library')),
file_name TEXT NOT NULL,
original_name TEXT NOT NULL,
format VARCHAR(10) NOT NULL,
size_bytes BIGINT NOT NULL,
sha256 VARCHAR(64) NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX model_files_model_idx ON model_files (model_id);
CREATE INDEX model_files_sha_idx ON model_files (sha256);