summaryrefslogtreecommitdiff
path: root/initialize.sql
blob: 0f43af510b8c58abc9be57bfd0a0a73e052c9891 (plain)
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
CREATE TABLE IF NOT EXISTS image(
	sha1     TEXT NOT NULL,  -- SHA-1 hash of file in lowercase hexadecimal
	thumbw   INTEGER,        -- cached thumbnail width, if known
	thumbh   INTEGER,        -- cached thumbnail height, if known
	dhash    INTEGER,        -- uint64 perceptual hash as a signed integer
	PRIMARY KEY (sha1)
) STRICT;

CREATE INDEX IF NOT EXISTS image_dhash ON image(dhash, sha1);

--

CREATE TABLE IF NOT EXISTS directory(
	id       INTEGER NOT NULL,                  -- unique ID
	name     TEXT NOT NULL,                     -- basename
	parent   INTEGER REFERENCES directory(id),  -- root if NULL
	PRIMARY KEY (id)
) STRICT;

CREATE UNIQUE INDEX IF NOT EXISTS directory_parent ON directory(parent, name);

CREATE TABLE IF NOT EXISTS entry(
	parent   INTEGER REFERENCES directory(id),
	name     TEXT NOT NULL,     -- last FS path component
	mtime    INTEGER NOT NULL,  -- Unix time of last modification in seconds
	sha1     TEXT NOT NULL REFERENCES image(sha1),
	PRIMARY KEY (parent, name)
) STRICT;

CREATE INDEX IF NOT EXISTS entry_sha1 ON entry(sha1, parent, name);

--

CREATE TABLE IF NOT EXISTS image_tag(
	sha1     TEXT NOT NULL REFERENCES image(sha1),
	tag      TEXT NOT NULL,
	PRIMARY KEY (sha1)
) STRICT;

-- XXX: Perhaps this should be more like namespaces.
CREATE TABLE IF NOT EXISTS image_autotag(
	sha1     TEXT NOT NULL REFERENCES image(sha1),
	tag      TEXT NOT NULL,
	weight   REAL NOT NULL,     -- 0..1 normalized weight assigned to tag
	PRIMARY KEY (sha1, tag)
) STRICT;

CREATE INDEX IF NOT EXISTS image_autotag_tag ON image_autotag(tag, sha1);