-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sql
More file actions
172 lines (158 loc) · 9.48 KB
/
setup.sql
File metadata and controls
172 lines (158 loc) · 9.48 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
CREATE TABLE "regreso_destination_list" (
"id" serial PRIMARY KEY NOT NULL,
"destination_id" integer,
"list_id" integer,
CONSTRAINT "regreso_destination_list_destination_id_list_id_unique" UNIQUE("destination_id","list_id")
);
CREATE TABLE "regreso_destination_tag" (
"id" serial PRIMARY KEY NOT NULL,
"destination_id" integer,
"tag_id" integer,
CONSTRAINT "regreso_destination_tag_destination_id_tag_id_unique" UNIQUE("destination_id","tag_id")
);
CREATE TABLE "regreso_destination" (
"id" serial PRIMARY KEY NOT NULL,
"name" varchar(256),
"location" varchar(256),
"type" varchar(256) NOT NULL,
"body" text,
"user_id" integer NOT NULL,
"created_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
"updated_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
"workspace_id" integer NOT NULL,
"archived" boolean DEFAULT false NOT NULL,
CONSTRAINT "regreso_destination_user_id_location_unique" UNIQUE("user_id","location")
);
CREATE TABLE "regreso_email_verification_request" (
"id" text PRIMARY KEY NOT NULL,
"user_id" integer NOT NULL,
"code" text NOT NULL,
"email" text NOT NULL,
"expires_at" timestamp with time zone NOT NULL
);
CREATE TABLE "regreso_list_tag" (
"id" serial PRIMARY KEY NOT NULL,
"list_id" integer,
"tag_id" integer,
CONSTRAINT "regreso_list_tag_list_id_tag_id_unique" UNIQUE("list_id","tag_id")
);
CREATE TABLE "regreso_list" (
"id" serial PRIMARY KEY NOT NULL,
"name" varchar(256) NOT NULL,
"emoji" varchar(256),
"description" varchar(256),
"user_id" integer NOT NULL,
"created_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
"workspace_id" integer NOT NULL,
"archived" boolean DEFAULT false NOT NULL,
CONSTRAINT "regreso_list_user_id_name_unique" UNIQUE("user_id","name")
);
CREATE TABLE "regreso_passkey_credential" (
"id" text PRIMARY KEY NOT NULL,
"user_id" integer NOT NULL,
"name" text NOT NULL,
"algorithm" integer NOT NULL,
"public_key" text NOT NULL
);
CREATE TABLE "regreso_password_reset_session" (
"id" text PRIMARY KEY NOT NULL,
"user_id" integer NOT NULL,
"code" text NOT NULL,
"email" text NOT NULL,
"email_verified" boolean DEFAULT false NOT NULL,
"two_factor_verified" boolean DEFAULT false NOT NULL,
"expires_at" timestamp with time zone NOT NULL
);
CREATE TABLE "regreso_security_key_credential" (
"id" text PRIMARY KEY NOT NULL,
"user_id" integer NOT NULL,
"name" text NOT NULL,
"algorithm" integer NOT NULL,
"public_key" text NOT NULL
);
CREATE TABLE "regreso_session" (
"id" text PRIMARY KEY NOT NULL,
"user_id" integer NOT NULL,
"expires_at" timestamp with time zone NOT NULL,
"two_factor_verified" boolean DEFAULT false NOT NULL
);
CREATE TABLE "regreso_tag" (
"id" serial PRIMARY KEY NOT NULL,
"shortcut" varchar(256),
"name" varchar(256) NOT NULL,
"user_id" integer NOT NULL,
"workspace_id" integer NOT NULL,
"created_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
"updated_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
"description" varchar(256),
"color" varchar(256),
"archived" boolean DEFAULT false NOT NULL,
CONSTRAINT "regreso_tag_user_id_name_unique" UNIQUE("user_id","name"),
CONSTRAINT "regreso_tag_user_id_shortcut_unique" UNIQUE("user_id","shortcut")
);
CREATE TABLE "regreso_totp_credential" (
"id" serial PRIMARY KEY NOT NULL,
"user_id" integer NOT NULL,
"key" text NOT NULL,
CONSTRAINT "regreso_totp_credential_user_id_unique" UNIQUE("user_id")
);
CREATE TABLE "regreso_user" (
"id" serial PRIMARY KEY NOT NULL,
"google_id" text,
"github_id" integer,
"email" text NOT NULL,
"display_name" text DEFAULT 'Anonymous' NOT NULL,
"name" varchar(32) NOT NULL,
"password_hash" varchar(256),
"email_verified" boolean DEFAULT false NOT NULL,
"recovery_code" varchar NOT NULL,
"avatar_url" text,
"bio" text DEFAULT 'Pelicans are epic',
"ai_tagging_instance" varchar(256),
"workspace_id" integer DEFAULT 0,
CONSTRAINT "regreso_user_google_id_unique" UNIQUE("google_id"),
CONSTRAINT "regreso_user_github_id_unique" UNIQUE("github_id"),
CONSTRAINT "regreso_user_email_unique" UNIQUE("email"),
CONSTRAINT "regreso_user_name_unique" UNIQUE("name")
);
CREATE TABLE "regreso_workspace" (
"id" serial PRIMARY KEY NOT NULL,
"name" varchar(256) NOT NULL,
"description" varchar(256),
"emoji" varchar(256),
"created_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
"user_id" integer NOT NULL,
"archived" boolean DEFAULT false NOT NULL,
CONSTRAINT "regreso_workspace_user_id_name_unique" UNIQUE("user_id","name")
);
ALTER TABLE "regreso_destination_list" ADD CONSTRAINT "regreso_destination_list_destination_id_regreso_destination_id_fk" FOREIGN KEY ("destination_id") REFERENCES "public"."regreso_destination"("id") ON DELETE cascade ON UPDATE cascade;
ALTER TABLE "regreso_destination_list" ADD CONSTRAINT "regreso_destination_list_list_id_regreso_list_id_fk" FOREIGN KEY ("list_id") REFERENCES "public"."regreso_list"("id") ON DELETE cascade ON UPDATE cascade;
ALTER TABLE "regreso_destination_tag" ADD CONSTRAINT "regreso_destination_tag_destination_id_regreso_destination_id_fk" FOREIGN KEY ("destination_id") REFERENCES "public"."regreso_destination"("id") ON DELETE cascade ON UPDATE cascade;
ALTER TABLE "regreso_destination_tag" ADD CONSTRAINT "regreso_destination_tag_tag_id_regreso_tag_id_fk" FOREIGN KEY ("tag_id") REFERENCES "public"."regreso_tag"("id") ON DELETE cascade ON UPDATE cascade;
ALTER TABLE "regreso_destination" ADD CONSTRAINT "regreso_destination_user_id_regreso_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."regreso_user"("id") ON DELETE cascade ON UPDATE no action;
ALTER TABLE "regreso_destination" ADD CONSTRAINT "regreso_destination_workspace_id_regreso_workspace_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."regreso_workspace"("id") ON DELETE cascade ON UPDATE no action;
ALTER TABLE "regreso_email_verification_request" ADD CONSTRAINT "regreso_email_verification_request_user_id_regreso_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."regreso_user"("id") ON DELETE cascade ON UPDATE no action;
ALTER TABLE "regreso_list_tag" ADD CONSTRAINT "regreso_list_tag_list_id_regreso_list_id_fk" FOREIGN KEY ("list_id") REFERENCES "public"."regreso_list"("id") ON DELETE cascade ON UPDATE cascade;
ALTER TABLE "regreso_list_tag" ADD CONSTRAINT "regreso_list_tag_tag_id_regreso_tag_id_fk" FOREIGN KEY ("tag_id") REFERENCES "public"."regreso_tag"("id") ON DELETE cascade ON UPDATE cascade;
ALTER TABLE "regreso_list" ADD CONSTRAINT "regreso_list_user_id_regreso_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."regreso_user"("id") ON DELETE no action ON UPDATE no action;
ALTER TABLE "regreso_list" ADD CONSTRAINT "regreso_list_workspace_id_regreso_workspace_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."regreso_workspace"("id") ON DELETE cascade ON UPDATE no action;
ALTER TABLE "regreso_passkey_credential" ADD CONSTRAINT "regreso_passkey_credential_user_id_regreso_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."regreso_user"("id") ON DELETE cascade ON UPDATE no action;
ALTER TABLE "regreso_password_reset_session" ADD CONSTRAINT "regreso_password_reset_session_user_id_regreso_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."regreso_user"("id") ON DELETE cascade ON UPDATE no action;
ALTER TABLE "regreso_security_key_credential" ADD CONSTRAINT "regreso_security_key_credential_user_id_regreso_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."regreso_user"("id") ON DELETE cascade ON UPDATE no action;
ALTER TABLE "regreso_session" ADD CONSTRAINT "regreso_session_user_id_regreso_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."regreso_user"("id") ON DELETE no action ON UPDATE no action;
ALTER TABLE "regreso_tag" ADD CONSTRAINT "regreso_tag_user_id_regreso_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."regreso_user"("id") ON DELETE cascade ON UPDATE no action;
ALTER TABLE "regreso_tag" ADD CONSTRAINT "regreso_tag_workspace_id_regreso_workspace_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."regreso_workspace"("id") ON DELETE cascade ON UPDATE no action;
ALTER TABLE "regreso_totp_credential" ADD CONSTRAINT "regreso_totp_credential_user_id_regreso_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."regreso_user"("id") ON DELETE cascade ON UPDATE no action;
ALTER TABLE "regreso_user" ADD CONSTRAINT "regreso_user_workspace_id_regreso_workspace_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."regreso_workspace"("id") ON DELETE set default ON UPDATE cascade;
ALTER TABLE "regreso_workspace" ADD CONSTRAINT "regreso_workspace_user_id_regreso_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."regreso_user"("id") ON DELETE cascade ON UPDATE cascade;
CREATE INDEX "destination_search_index" ON "regreso_destination" USING gin (setweight(to_tsvector('english', "name"), 'A') ||
setweight(to_tsvector('english', "body"), 'B'));
CREATE INDEX "list_search_index" ON "regreso_list" USING gin (setweight(to_tsvector('english', "name"), 'A') ||
setweight(to_tsvector('english', "description"), 'B'));
CREATE INDEX "tag_search_index" ON "regreso_tag" USING gin (setweight(to_tsvector('english', "shortcut"), 'A') ||
setweight(to_tsvector('english', "name"), 'B'));
CREATE INDEX "email_index" ON "regreso_user" USING btree ("email");
CREATE INDEX "google_id_index" ON "regreso_user" USING btree ("google_id");
CREATE INDEX "github_id_index" ON "regreso_user" USING btree ("github_id");
CREATE INDEX "workspace_searc_index" ON "regreso_workspace" USING gin (setweight(to_tsvector('english', "name"), 'A') ||
setweight(to_tsvector('english', "description"), 'B'));