Skip to content

Commit d0a0e4f

Browse files
committed
adjust constraints for expenses and records for deletion
1 parent 7a57d52 commit d0a0e4f

File tree

4 files changed

+122
-58
lines changed

4 files changed

+122
-58
lines changed

Justfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,14 @@ get:
1414
[working-directory: "web"]
1515
watch:
1616
npm run watch
17+
18+
db:
19+
psql postgresql://conartist:conartist@localhost:5432/conartist
20+
21+
[working-directory: "database"]
22+
migration name:
23+
diesel migration generate {{name}}
24+
25+
[working-directory: "database"]
26+
migrate:
27+
diesel migration run
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-- Not undoing these ones, they're kinda harmless.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
ALTER TABLE expenses
2+
DROP CONSTRAINT expenses_user_id_fkey;
3+
4+
ALTER TABLE records
5+
DROP CONSTRAINT records_user_id_fkey;
6+
7+
ALTER TABLE expenses
8+
ADD FOREIGN KEY (user_id, con_id) REFERENCES user_conventions (user_id, con_id)
9+
ON DELETE CASCADE;
10+
11+
ALTER TABLE records
12+
ADD FOREIGN KEY (user_id, con_id) REFERENCES user_conventions (user_id, con_id)
13+
ON DELETE CASCADE;
14+
15+
ALTER TABLE records
16+
ADD FOREIGN KEY (user_id) REFERENCES users (user_id)
17+
ON DELETE CASCADE

database/src/schema.rs

Lines changed: 93 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,48 @@
1-
table! {
1+
// @generated automatically by Diesel CLI.
2+
3+
pub mod sql_types {
4+
#[derive(diesel::sql_types::SqlType)]
5+
#[diesel(postgres_type(name = "event_type"))]
6+
pub struct EventType;
7+
}
8+
9+
diesel::table! {
210
admins (user_id) {
311
user_id -> Int4,
412
clearance -> Int4,
513
}
614
}
715

8-
table! {
16+
diesel::table! {
917
conventionextrainfo (con_id, title) {
1018
con_id -> Int4,
19+
#[max_length = 64]
1120
title -> Varchar,
1221
info -> Nullable<Json>,
1322
action -> Nullable<Text>,
1423
action_text -> Nullable<Text>,
1524
}
1625
}
1726

18-
table! {
27+
diesel::table! {
1928
conventionimages (image_id) {
2029
image_id -> Int4,
2130
con_id -> Int4,
31+
#[max_length = 36]
2232
image_uuid -> Bpchar,
2333
create_date -> Timestamp,
2434
}
2535
}
2636

27-
table! {
37+
diesel::table! {
2838
conventioninforatings (con_info_id, user_id) {
2939
con_info_id -> Int4,
3040
user_id -> Int4,
3141
rating -> Bool,
3242
}
3343
}
3444

35-
table! {
45+
diesel::table! {
3646
conventionratings (con_id, user_id) {
3747
con_id -> Int4,
3848
user_id -> Int4,
@@ -41,17 +51,18 @@ table! {
4151
}
4252
}
4353

44-
table! {
54+
diesel::table! {
4555
conventions (con_id) {
4656
con_id -> Int4,
57+
#[max_length = 512]
4758
title -> Varchar,
4859
start_date -> Date,
4960
end_date -> Date,
5061
predecessor -> Nullable<Int4>,
5162
}
5263
}
5364

54-
table! {
65+
diesel::table! {
5566
conventionuserinfo (con_info_id) {
5667
con_info_id -> Int4,
5768
con_id -> Int4,
@@ -60,30 +71,34 @@ table! {
6071
}
6172
}
6273

63-
table! {
74+
diesel::table! {
6475
emailverifications (verification_code) {
76+
#[max_length = 32]
6577
verification_code -> Bpchar,
6678
user_id -> Int4,
79+
#[max_length = 512]
6780
email -> Varchar,
6881
created -> Timestamp,
6982
expires -> Timestamp,
7083
}
7184
}
7285

73-
table! {
86+
diesel::table! {
7487
expenses (expense_id) {
7588
expense_id -> Int4,
7689
user_id -> Int4,
7790
con_id -> Int4,
91+
#[max_length = 23]
7892
price -> Bpchar,
93+
#[max_length = 32]
7994
category -> Varchar,
8095
description -> Text,
8196
spend_time -> Text,
8297
gen_id -> Nullable<Uuid>,
8398
}
8499
}
85100

86-
table! {
101+
diesel::table! {
87102
inventory (inventory_id) {
88103
inventory_id -> Int4,
89104
product_id -> Int4,
@@ -92,8 +107,9 @@ table! {
92107
}
93108
}
94109

95-
table! {
110+
diesel::table! {
96111
passwordresets (verification_code) {
112+
#[max_length = 32]
97113
verification_code -> Bpchar,
98114
user_id -> Int4,
99115
used -> Bool,
@@ -102,81 +118,92 @@ table! {
102118
}
103119
}
104120

105-
table! {
121+
diesel::table! {
106122
prices (price_id) {
107123
price_id -> Int4,
108124
user_id -> Int4,
109125
type_id -> Int4,
110126
product_id -> Nullable<Int4>,
111127
quantity -> Int4,
128+
#[max_length = 23]
112129
price -> Nullable<Bpchar>,
113130
mod_date -> Timestamp,
114131
}
115132
}
116133

117-
table! {
134+
diesel::table! {
135+
use diesel::sql_types::*;
136+
use super::sql_types::EventType;
137+
118138
productevents (event_id) {
119139
event_id -> Int4,
120140
product_id -> Int4,
121-
event_type -> Event_type,
141+
event_type -> EventType,
122142
event_time -> Timestamp,
123143
}
124144
}
125145

126-
table! {
146+
diesel::table! {
127147
products (product_id) {
128148
product_id -> Int4,
129149
type_id -> Int4,
130150
user_id -> Int4,
151+
#[max_length = 512]
131152
name -> Varchar,
132153
sort -> Int4,
133154
deleted -> Bool,
155+
#[max_length = 255]
134156
sku -> Nullable<Varchar>,
135157
}
136158
}
137159

138-
table! {
160+
diesel::table! {
161+
use diesel::sql_types::*;
162+
use super::sql_types::EventType;
163+
139164
producttypeevents (event_id) {
140165
event_id -> Int4,
141166
type_id -> Int4,
142-
event_type -> Event_type,
167+
event_type -> EventType,
143168
event_time -> Timestamp,
144169
}
145170
}
146171

147-
table! {
172+
diesel::table! {
148173
producttypes (type_id) {
149174
type_id -> Int4,
150175
user_id -> Int4,
176+
#[max_length = 512]
151177
name -> Varchar,
152178
color -> Nullable<Int4>,
153179
sort -> Int4,
154180
deleted -> Bool,
155181
}
156182
}
157183

158-
table! {
184+
diesel::table! {
159185
records (record_id) {
160186
record_id -> Int4,
161187
user_id -> Int4,
162188
con_id -> Nullable<Int4>,
189+
#[max_length = 23]
163190
price -> Bpchar,
164-
products -> Array<Int4>,
191+
products -> Array<Nullable<Int4>>,
165192
info -> Text,
166193
sale_time -> Text,
167194
gen_id -> Nullable<Uuid>,
168195
}
169196
}
170197

171-
table! {
198+
diesel::table! {
172199
signinattempts (user_id, attempt_time) {
173200
user_id -> Int4,
174201
successful -> Bool,
175202
attempt_time -> Timestamp,
176203
}
177204
}
178205

179-
table! {
206+
diesel::table! {
180207
suggestions (suggestion_id) {
181208
suggestion_id -> Int4,
182209
user_id -> Int4,
@@ -186,87 +213,95 @@ table! {
186213
}
187214
}
188215

189-
table! {
216+
diesel::table! {
190217
suggestionvotes (suggestion_id, user_id) {
191218
suggestion_id -> Int4,
192219
user_id -> Int4,
193220
}
194221
}
195222

196-
table! {
223+
diesel::table! {
197224
user_conventions (user_con_id) {
198225
user_con_id -> Int4,
199226
user_id -> Int4,
200227
con_id -> Int4,
201228
}
202229
}
203230

204-
table! {
231+
diesel::table! {
205232
users (user_id) {
206233
user_id -> Int4,
234+
#[max_length = 512]
207235
email -> Nullable<Varchar>,
236+
#[max_length = 512]
208237
name -> Varchar,
238+
#[max_length = 512]
209239
password -> Varchar,
210240
keys -> Int4,
211241
join_date -> Timestamp,
212242
}
213243
}
214244

215-
table! {
245+
diesel::table! {
216246
usersettings (user_id) {
217247
user_id -> Int4,
248+
#[max_length = 3]
218249
currency -> Bpchar,
250+
#[max_length = 16]
219251
language -> Bpchar,
220252
}
221253
}
222254

223-
table! {
255+
diesel::table! {
224256
webhookdeletedrecord (webhook_id) {
225257
webhook_id -> Int4,
226258
user_id -> Int4,
259+
#[max_length = 1024]
227260
url -> Varchar,
228261
}
229262
}
230263

231-
table! {
264+
diesel::table! {
232265
webhooknewrecord (webhook_id) {
233266
webhook_id -> Int4,
234267
user_id -> Int4,
268+
#[max_length = 1024]
235269
url -> Varchar,
236270
}
237271
}
238272

239-
joinable!(admins -> users (user_id));
240-
joinable!(conventionextrainfo -> conventions (con_id));
241-
joinable!(conventionimages -> conventions (con_id));
242-
joinable!(conventioninforatings -> conventionuserinfo (con_info_id));
243-
joinable!(conventioninforatings -> users (user_id));
244-
joinable!(conventionratings -> conventions (con_id));
245-
joinable!(conventionratings -> users (user_id));
246-
joinable!(conventionuserinfo -> conventions (con_id));
247-
joinable!(conventionuserinfo -> users (user_id));
248-
joinable!(emailverifications -> users (user_id));
249-
joinable!(inventory -> products (product_id));
250-
joinable!(passwordresets -> users (user_id));
251-
joinable!(prices -> products (product_id));
252-
joinable!(prices -> producttypes (type_id));
253-
joinable!(prices -> users (user_id));
254-
joinable!(productevents -> products (product_id));
255-
joinable!(products -> producttypes (type_id));
256-
joinable!(products -> users (user_id));
257-
joinable!(producttypeevents -> producttypes (type_id));
258-
joinable!(producttypes -> users (user_id));
259-
joinable!(signinattempts -> users (user_id));
260-
joinable!(suggestions -> users (user_id));
261-
joinable!(suggestionvotes -> suggestions (suggestion_id));
262-
joinable!(suggestionvotes -> users (user_id));
263-
joinable!(user_conventions -> conventions (con_id));
264-
joinable!(user_conventions -> users (user_id));
265-
joinable!(usersettings -> users (user_id));
266-
joinable!(webhookdeletedrecord -> users (user_id));
267-
joinable!(webhooknewrecord -> users (user_id));
273+
diesel::joinable!(admins -> users (user_id));
274+
diesel::joinable!(conventionextrainfo -> conventions (con_id));
275+
diesel::joinable!(conventionimages -> conventions (con_id));
276+
diesel::joinable!(conventioninforatings -> conventionuserinfo (con_info_id));
277+
diesel::joinable!(conventioninforatings -> users (user_id));
278+
diesel::joinable!(conventionratings -> conventions (con_id));
279+
diesel::joinable!(conventionratings -> users (user_id));
280+
diesel::joinable!(conventionuserinfo -> conventions (con_id));
281+
diesel::joinable!(conventionuserinfo -> users (user_id));
282+
diesel::joinable!(emailverifications -> users (user_id));
283+
diesel::joinable!(inventory -> products (product_id));
284+
diesel::joinable!(passwordresets -> users (user_id));
285+
diesel::joinable!(prices -> products (product_id));
286+
diesel::joinable!(prices -> producttypes (type_id));
287+
diesel::joinable!(prices -> users (user_id));
288+
diesel::joinable!(productevents -> products (product_id));
289+
diesel::joinable!(products -> producttypes (type_id));
290+
diesel::joinable!(products -> users (user_id));
291+
diesel::joinable!(producttypeevents -> producttypes (type_id));
292+
diesel::joinable!(producttypes -> users (user_id));
293+
diesel::joinable!(records -> users (user_id));
294+
diesel::joinable!(signinattempts -> users (user_id));
295+
diesel::joinable!(suggestions -> users (user_id));
296+
diesel::joinable!(suggestionvotes -> suggestions (suggestion_id));
297+
diesel::joinable!(suggestionvotes -> users (user_id));
298+
diesel::joinable!(user_conventions -> conventions (con_id));
299+
diesel::joinable!(user_conventions -> users (user_id));
300+
diesel::joinable!(usersettings -> users (user_id));
301+
diesel::joinable!(webhookdeletedrecord -> users (user_id));
302+
diesel::joinable!(webhooknewrecord -> users (user_id));
268303

269-
allow_tables_to_appear_in_same_query!(
304+
diesel::allow_tables_to_appear_in_same_query!(
270305
admins,
271306
conventionextrainfo,
272307
conventionimages,

0 commit comments

Comments
 (0)