forked from peterldowns/pgmigrate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
80 lines (68 loc) · 2.11 KB
/
schema.sql
File metadata and controls
80 lines (68 loc) · 2.11 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
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
CREATE TABLE public.blob_type_enum (
value text PRIMARY KEY NOT NULL
);
CREATE TABLE public.blobs (
id bigint PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY,
created_at timestamp with time zone NOT NULL DEFAULT now(),
company_id bigint NOT NULL,
owner_id bigint,
name text NOT NULL,
data jsonb NOT NULL DEFAULT '{}'::jsonb,
status text NOT NULL DEFAULT 'pending_review'::text
);
CREATE TABLE public.companies (
id bigint PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY,
created_at timestamp with time zone NOT NULL DEFAULT now(),
domain text UNIQUE NOT NULL,
name text NOT NULL
);
ALTER TABLE public.blobs
ADD CONSTRAINT blobs_company_id_fkey
FOREIGN KEY (company_id) REFERENCES companies(id);
CREATE TABLE public.users (
id bigint PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY,
created_at timestamp with time zone NOT NULL DEFAULT now(),
name text NOT NULL,
email text UNIQUE NOT NULL,
company_id bigint
);
ALTER TABLE public.blobs
ADD CONSTRAINT blobs_owner_id_fkey
FOREIGN KEY (owner_id) REFERENCES users(id);
ALTER TABLE public.blobs
ADD CONSTRAINT blobs_status_fkey
FOREIGN KEY (status) REFERENCES blob_type_enum(value);
CREATE TABLE public.cats (
id bigint PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY,
name text UNIQUE NOT NULL,
so_pretty_and_elegant boolean NOT NULL DEFAULT true
);
CREATE TABLE public.dogs (
id bigint PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY,
name text UNIQUE NOT NULL,
very_good boolean NOT NULL DEFAULT true
);
CREATE TABLE public.pgmigrate_migrations (
id text PRIMARY KEY NOT NULL,
checksum text NOT NULL,
execution_time_in_millis bigint NOT NULL,
applied_at timestamp with time zone NOT NULL
);
CREATE VIEW public.reviewable_blobs AS
SELECT blobs.id,
blobs.created_at,
blobs.company_id,
blobs.owner_id,
blobs.name,
blobs.data,
blobs.status
FROM blobs
WHERE (blobs.status = 'pending_review'::text);
ALTER TABLE public.users
ADD CONSTRAINT users_company_id_fkey
FOREIGN KEY (company_id) REFERENCES companies(id);
INSERT INTO public.blob_type_enum (value) VALUES
('pending_review'),
('approved'),
('rejected')
;