-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabase.sql
55 lines (45 loc) · 1.62 KB
/
database.sql
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
CREATE EXTENSION pg_trgm;
CREATE OR REPLACE FUNCTION basename(pathname text) RETURNS text
PARALLEL SAFE
IMMUTABLE
RETURNS NULL ON NULL INPUT
AS $basename$
BEGIN
return regexp_replace(trim(TRAILING FROM pathname, '/'), '^.+/', '');
END
$basename$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION count_estimate(query text) RETURNS integer
VOLATILE
RETURNS NULL ON NULL INPUT
AS $count_estimate$
DECLARE
rec record;
rows integer;
BEGIN
FOR rec IN EXECUTE 'EXPLAIN ' || query LOOP
rows := substring(rec."QUERY PLAN" FROM ' rows=([[:digit:]]+)');
EXIT WHEN rows IS NOT NULL;
END LOOP;
-- this useless comment can be removed, just here for to-do-highlighting to work
RETURN rows;
END
$count_estimate$ LANGUAGE plpgsql;
/*
Tables
*/
-- auto-generated definition
create table user_file_index
(
owner_id bigint not null,
filesystem varchar(512) not null,
file_path text not null,
is_directory boolean not null,
size_bytes bigint,
sha256 bytea,
last_modification timestamp with time zone not null,
last_validation timestamp with time zone default CURRENT_TIMESTAMP not null,
constraint user_file_index_pk
primary key (owner_id, filesystem, file_path)
);
create index on user_file_index using gin (file_path gin_trgm_ops);
create index on user_file_index using gin (basename(file_path) gin_trgm_ops);