generated from ViBiOh/goweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ddl.sql
80 lines (65 loc) · 3.06 KB
/
ddl.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
-- clean
DROP TABLE IF EXISTS ketchup.ketchup;
DROP TABLE IF EXISTS ketchup.repository_version;
DROP TABLE IF EXISTS ketchup.repository;
DROP TABLE IF EXISTS ketchup.user;
DROP TYPE IF EXISTS ketchup.repository_kind;
DROP TYPE IF EXISTS ketchup.ketchup_frequency;
DROP INDEX IF EXISTS ketchup_id;
DROP INDEX IF EXISTS repository_version_id;
DROP INDEX IF EXISTS repository_repository;
DROP INDEX IF EXISTS repository_id;
DROP INDEX IF EXISTS user_email;
DROP INDEX IF EXISTS user_login_id;
DROP INDEX IF EXISTS user_id;
DROP SEQUENCE IF EXISTS ketchup.repository_seq;
DROP SEQUENCE IF EXISTS ketchup.user_seq;
DROP SCHEMA IF EXISTS ketchup CASCADE;
-- schema
CREATE SCHEMA ketchup;
-- user
CREATE SEQUENCE ketchup.user_seq;
CREATE TABLE ketchup.user (
id BIGINT NOT NULL DEFAULT nextval('ketchup.user_seq'),
email TEXT NOT NULL,
login_id BIGINT NOT NULL REFERENCES auth.login(id) ON DELETE CASCADE,
creation_date TIMESTAMP WITH TIME ZONE DEFAULT now()
);
ALTER SEQUENCE ketchup.user_seq OWNED BY ketchup.user.id;
CREATE UNIQUE INDEX user_id ON ketchup.user(id);
CREATE UNIQUE INDEX user_login_id ON ketchup.user(login_id);
CREATE UNIQUE INDEX user_email ON ketchup.user(email);
-- repository_kind
CREATE TYPE ketchup.repository_kind AS ENUM ('github', 'helm', 'docker', 'npm', 'pypi');
-- repository
CREATE SEQUENCE ketchup.repository_seq;
CREATE TABLE ketchup.repository (
id BIGINT NOT NULL DEFAULT nextval('ketchup.repository_seq'),
kind ketchup.repository_kind NOT NULL,
name TEXT NOT NULL,
part TEXT NOT NULL DEFAULT '',
creation_date TIMESTAMP WITH TIME ZONE DEFAULT now()
);
ALTER SEQUENCE ketchup.repository_seq OWNED BY ketchup.repository.id;
CREATE UNIQUE INDEX repository_id ON ketchup.repository(id);
CREATE UNIQUE INDEX repository_repository ON ketchup.repository(kind, name, part);
-- repository_version
CREATE TABLE ketchup.repository_version (
repository_id BIGINT NOT NULL REFERENCES ketchup.repository(id) ON DELETE CASCADE,
pattern TEXT NOT NULL DEFAULT 'stable',
version TEXT NOT NULL
);
CREATE UNIQUE INDEX repository_version_id ON ketchup.repository_version(repository_id, pattern);
-- repository_kind
CREATE TYPE ketchup.ketchup_frequency AS ENUM ('none', 'daily', 'weekly');
-- ketchup
CREATE TABLE ketchup.ketchup (
user_id BIGINT NOT NULL REFERENCES ketchup.user(id) ON DELETE CASCADE,
repository_id BIGINT NOT NULL REFERENCES ketchup.repository(id) ON DELETE CASCADE,
pattern TEXT NOT NULL DEFAULT 'stable',
version TEXT NOT NULL,
frequency ketchup.ketchup_frequency NOT NULL DEFAULT 'daily',
update_when_notify BOOL NOT NULL DEFAULT FALSE,
creation_date TIMESTAMP WITH TIME ZONE DEFAULT now()
);
CREATE UNIQUE INDEX ketchup_id ON ketchup.ketchup(user_id, repository_id, pattern);