forked from HOZ1997/paint-group-project
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatabase.sql
More file actions
411 lines (346 loc) · 13.6 KB
/
database.sql
File metadata and controls
411 lines (346 loc) · 13.6 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
-- USER is a reserved keyword with Postgres
-- You must use double quotes in every query that user is in:
-- ex. SELECT * FROM "user";
-- Otherwise you will have errors!
CREATE TABLE "user" (
"id" SERIAL PRIMARY KEY,
"username" VARCHAR (80) UNIQUE NOT NULL,
"password" VARCHAR (1000) NOT NULL,
"role" INT DEFAULT 1
);
SELECT * FROM "user";
CREATE TABLE "paintproject_input" (
"id" serial primary key,
"client_type_id" INT,
"client_firstlast_name" VARCHAR (255),
"decision_firstlast_name" VARCHAR (255),
"decision_emailaddress" VARCHAR (255),
"decision_phonenumber" VARCHAR (14),
"project_address_1" VARCHAR (255),
"project_address_2" VARCHAR (255),
"project_address_city" VARCHAR (255),
"project_address_state" VARCHAR (255),
"project_address_zip" INT,
"project_house_year" INT,
"project_address_notes" VARCHAR (255),
"project_job_number" SERIAL,
"project_propertytype_id" INT,
"project_buildingtype_id" INT,
"isproject_typeinterior" BOOLEAN,
"isproject_typeexterior" BOOLEAN,
"isproject_typecabinetry" BOOLEAN,
"isproject_typespecialfeature" BOOLEAN,
"project_startdate" DATE,
"project_complete_specificdate" DATE,
"language_preference_id" INT,
"user_id" INT,
"specialfeatureexterior_type_id" INT,
"specialfeature_paintproduct" VARCHAR (255),
"isspecialfeaturestatus_needprimer" BOOLEAN,
"isspecialfeaturestatus_patchedrepair" BOOLEAN,
"isspecialfeaturestatus_extensivescraping" BOOLEAN,
"specailfeature_notes" VARCHAR (255),
"exteriorestimate_laborcost" INT,
"exteriorestimate_materialcost" INT,
"exteriorestimate_totalcost" INT,
"isexteriorprep_powerwash" BOOLEAN,
"isexteriorprep_scrape" BOOLEAN,
"isexteriorprep_mildew" BOOLEAN,
"isexteriorwarranty_oneyear" BOOLEAN,
"isexteriorwarranty_threeyear" BOOLEAN,
"isexteriorwarranty_fiveyear" BOOLEAN,
"photo_upload_id" INT);
alter sequence paintproject_input_project_job_number_seq restart with 00475;
SELECT * FROM "paintproject_input";
CREATE TABLE "client_type" (
"id" serial primary key,
"client_type_name" varchar(255) NOT NULL);
INSERT INTO "client_type" ("client_type_name") VALUES ('Homeowner');
INSERT INTO "client_type" ("client_type_name") VALUES ('Busines Owner');
INSERT INTO "client_type" ("client_type_name") VALUES ('Contractor/Developer');
INSERT INTO "client_type" ("client_type_name") VALUES ('Realtor/Designer');
INSERT INTO "client_type" ("client_type_name") VALUES ('Landlord/Property Owner');
SELECT * FROM "client_type";
CREATE TABLE "project_propertytype" (
"id" serial primary key,
"project_propertytype_name" varchar(255) NOT NULL);
INSERT INTO "project_propertytype" ("project_propertytype_name") VALUES ('Residential');
INSERT INTO "project_propertytype" ("project_propertytype_name") VALUES ('Commercial');
INSERT INTO "project_propertytype" ("project_propertytype_name") VALUES ('New construction');
SELECT * FROM "project_propertytype";
CREATE TABLE "project_buildingtype" (
"id" serial primary key,
"project_buildingtype_name" varchar(255) NOT NULL);
INSERT INTO "project_buildingtype" ("project_buildingtype_name") VALUES ('Single Family Home');
INSERT INTO "project_buildingtype" ("project_buildingtype_name") VALUES ('Commercial Building');
INSERT INTO "project_buildingtype" ("project_buildingtype_name") VALUES ('Apartment');
INSERT INTO "project_buildingtype" ("project_buildingtype_name") VALUES ('Condo');
INSERT INTO "project_buildingtype" ("project_buildingtype_name") VALUES ('Duplex');
INSERT INTO "project_buildingtype" ("project_buildingtype_name") VALUES ('Loft');
INSERT INTO "project_buildingtype" ("project_buildingtype_name") VALUES ('Multi-tenant');
SELECT * FROM "project_buildingtype";
CREATE TABLE "specialfeatureexterior_type" (
"id" serial primary key,
"specialfeatureexterior_type_name" varchar(255) NOT NULL);
INSERT INTO "specialfeatureexterior_type" ("specialfeatureexterior_type_name") VALUES ('Soffits');
INSERT INTO "specialfeatureexterior_type" ("specialfeatureexterior_type_name") VALUES ('Fascia');
INSERT INTO "specialfeatureexterior_type" ("specialfeatureexterior_type_name") VALUES ('Gate');
INSERT INTO "specialfeatureexterior_type" ("specialfeatureexterior_type_name") VALUES ('Gutters');
INSERT INTO "specialfeatureexterior_type" ("specialfeatureexterior_type_name") VALUES ('Columns');
INSERT INTO "specialfeatureexterior_type" ("specialfeatureexterior_type_name") VALUES ('Dormers');
INSERT INTO "specialfeatureexterior_type" ("specialfeatureexterior_type_name") VALUES ('Handrails');
INSERT INTO "specialfeatureexterior_type" ("specialfeatureexterior_type_name") VALUES ('Deck');
INSERT INTO "specialfeatureexterior_type" ("specialfeatureexterior_type_name") VALUES ('Porch');
INSERT INTO "specialfeatureexterior_type" ("specialfeatureexterior_type_name") VALUES ('Fence');
SELECT * FROM "specialfeatureexterior_type";
CREATE TABLE "photo_upload" (
"id" SERIAL PRIMARY KEY,
"photo_upload_path" text NOT NULL,
"photo_upload_description" text NOT NULL);
INSERT INTO "photo_upload" ( "photo_upload_path", "photo_upload_description" ) VALUES ('photopathhere', 'photodescriptionhere');
SELECT * FROM "photo_upload";
CREATE TABLE "language_preference" (
"id" serial primary key,
"language_preference_name" varchar(255) NOT NULL);
INSERT INTO "language_preference" ("language_preference_name") VALUES ('English');
INSERT INTO "language_preference" ("language_preference_name") VALUES ('Spanish');
SELECT * FROM "language_preference";
INSERT INTO "paintproject_input" (
"client_type_id",
"client_firstlast_name",
"decision_firstlast_name",
"decision_emailaddress",
"decision_phonenumber",
"project_address_1",
"project_address_2",
"project_address_city",
"project_address_state",
"project_address_zip",
"project_house_year",
"project_address_notes",
"project_job_number" ,
"project_propertytype_id",
"project_buildingtype_id",
"isproject_typeinterior",
"isproject_typeexterior",
"isproject_typecabinetry",
"isproject_typespecialfeature",
"project_startdate",
"project_complete_specificdate",
"language_preference_id",
"user_id" ,
"specialfeatureexterior_type_id",
"specialfeature_paintproduct",
"isspecialfeaturestatus_needprimer",
"isspecialfeaturestatus_patchedrepair",
"isspecialfeaturestatus_extensivescraping",
"specialfeature_notes" ,
"exteriorestimate_laborcost",
"exteriorestimate_materialcost" ,
"exteriorestimate_totalcost" ,
"isexteriorprep_powerwash",
"isexteriorprep_scrape",
"isexteriorprep_mildew",
"isexteriorwarranty_oneyear",
"isexteriorwarranty_threeyear",
"isexteriorwarranty_fiveyear",
"photo_upload_id" )
VALUES
(1,
'Heather Osborne2',
'Heather Osborne2',
'theoz308@comcast.net',
'5555555555',
'2121 Prime Ave',
'Suite 210',
'Chaska',
'MN',
'55318',
'2006',
'end unit',
1,
1,
1,
false,
false,
false,
true,
'2022-07-26',
'2022-07-26',
1,
1,
1,
'brown',
true,
false,
false,
'needs help',
10,
10,
20,
true,
true,
true,
true,
false,
false,
1);
-- GET for most information in Paint Project DB
SELECT
paintproject_input.id,
client_type_name,
client_firstlast_name,
decision_firstlast_name,
decision_emailaddress,
decision_phonenumber,
project_address_1,
project_address_2,
project_address_city,
project_address_state,
project_address_zip,
project_house_year,
project_address_notes,
project_job_number ,
project_propertytype_name,
project_buildingtype_name,
isproject_typeinterior,
isproject_typeexterior,
isproject_typecabinetry,
isproject_typespecialfeature,
project_startdate,
project_complete_specificdate,
language_preference_name,
user_id ,
specialfeatureexterior_type_name,
specialfeature_paintproduct,
isspecialfeaturestatus_needprimer,
isspecialfeaturestatus_patchedrepair,
isspecialfeaturestatus_extensivescraping,
specailfeature_notes ,
exteriorestimate_laborcost,
exteriorestimate_materialcost,
exteriorestimate_totalcost,
isexteriorprep_powerwash,
isexteriorprep_scrape,
isexteriorprep_mildew,
isexteriorwarranty_oneyear,
isexteriorwarranty_threeyear,
isexteriorwarranty_fiveyear,
photo_upload_id
FROM
paintproject_input
JOIN client_type ON client_type_id = client_type.id
JOIN project_propertytype ON project_propertytype_id = project_propertytype.id
JOIN project_buildingtype ON project_buildingtype_id = project_buildingtype.id
JOIN language_preference ON language_preference_id = language_preference.id
JOIN specialfeatureexterior_type ON specialfeatureexterior_type_id = specialfeatureexterior_type.id
JOIN photo_upload ON photo_upload_id = photo_upload.id;
-- GET information for Client component
SELECT
paintproject_input.id,
client_type_name,
client_firstlast_name,
decision_firstlast_name,
decision_emailaddress,
decision_phonenumber,
project_address_1,
project_address_2,
project_address_city,
project_address_state,
project_address_zip,
project_house_year,
project_address_notes
FROM
paintproject_input
JOIN client_type ON client_type_id = client_type.id;
-- GET information for Project component
SELECT
paintproject_input.id,
project_job_number ,
project_propertytype_name,
project_buildingtype_name,
isproject_typeinterior,
isproject_typeexterior,
isproject_typecabinetry,
isproject_typespecialfeature,
project_startdate,
project_complete_specificdate
FROM
paintproject_input
JOIN project_propertytype ON project_propertytype_id = project_propertytype.id
JOIN project_buildingtype ON project_buildingtype_id = project_buildingtype.id;
-- GET information for Special Feature component
SELECT
paintproject_input.id,
specialfeatureexterior_type_name,
specialfeature_paintproduct,
isspecialfeaturestatus_needprimer,
isspecialfeaturestatus_patchedrepair,
isspecialfeaturestatus_extensivescraping,
specailfeature_notes
FROM
paintproject_input
JOIN specialfeatureexterior_type ON specialfeatureexterior_type_id = specialfeatureexterior_type.id;
-- GET information for Estimate - exterior special feature
SELECT
paintproject_input.id,
exteriorestimate_laborcost,
exteriorestimate_materialcost,
exteriorestimate_totalcost
FROM
paintproject_input;
-- GET information for Exterior special feature scope of checkboxes
SELECT
paintproject_input.id,
isexteriorprep_powerwash,
isexteriorprep_scrape,
isexteriorprep_mildew,
isexteriorwarranty_oneyear,
isexteriorwarranty_threeyear,
isexteriorwarranty_fiveyear
FROM
paintproject_input
JOIN client_type ON client_type_id = client_type.id
JOIN project_propertytype ON project_propertytype_id = project_propertytype.id
JOIN project_buildingtype ON project_buildingtype_id = project_buildingtype.id
JOIN language_preference ON language_preference_id = language_preference.id
JOIN specialfeatureexterior_type ON specialfeatureexterior_type_id = specialfeatureexterior_type.id;
-- GET information for photo_upload
SELECT
paintproject_input.id,
photo_upload_id,
photo_upload_path,
photo_upload_description
FROM paintproject_input
JOIN photo_upload ON photo_upload_id = photo_upload.id
alter table photo_upload add column project_id int;
alter table photo_upload add column user_id int;
alter table photo_upload add constraint photo_upload_fk1 foreign key (“user_id”) references “user”(“id”);
alter table photo_upload add constraint photo_upload_fk0 foreign key (project_id) references paintproject_input(id);
SELECT paintproject_input.id,client_type_name,client_firstlast_name, decision_firstlast_name, decision_emailaddress, decision_phonenumber,project_address_1,project_address_2, project_address_city, project_address_state, project_address_zip, project_house_year, project_address_notes, project_propertytype_id, project_buildingtype_id, isproject_typeinterior, isproject_typecabinetry, isproject_typespecialfeature, project_startdate, project_complete_specificdate, specialfeatureexterior_type_id,
specialfeature_paintproduct,
isspecialfeaturestatus_needprimer,
isspecialfeaturestatus_patchedrepair,
isspecialfeaturestatus_extensivescraping,
specialfeature_notes,
exteriorestimate_laborcost,
exteriorestimate_materialcost,
exteriorestimate_totalcost,
isexteriorprep_powerwash,
isexteriorprep_scrape,
isexteriorprep_mildew,
isexteriorprep_scrape,
isexteriorprep_mildew,
isexteriorwarranty_oneyear,
isexteriorwarranty_threeyear,
isexteriorwarranty_fiveyear
FROM paintproject_input JOIN client_type ON client_type_id = client_type.id
JOIN project_propertytype ON project_propertytype_id = project_propertytype.id
JOIN project_buildingtype ON project_buildingtype_id = project_buildingtype.id
ORDER BY paintproject_input.id DESC;
UPDATE paintproject_input SET “client_type_id” = 1, “client_firstlast_name” = ‘Ozzy Osborne’, “decision_firstlast_name” = ‘Ozzy Osborne2’, “decision_emailaddress” = ‘2967’, “decision_phonenumber” = 555555,
“project_address_1” = ‘email@comcast.net’, “project_address_2" = ‘2121 Prime Ave’, “project_address_city” = ‘Chaska’, “project_address_state” = ‘MN’, “project_address_zip” = ‘55318’, “project_house_year” =‘2006’, “project_address_notes” = ‘end unit’, “project_propertytype_id” = 1, “project_buildingtype_id” = 1, “isproject_typeinterior” = true, “isproject_typeexterior” = true,
“isproject_typecabinetry” = true, “isproject_typespecialfeature” = true, “project_startdate” = ‘2022-07-26’, “project_complete_specificdate” = ‘2022-07-26’, “specialfeatureexterior_type_id” =1,
“specialfeature_paintproduct” = ‘brown’, “isspecialfeaturestatus_needprimer” = true, “isspecialfeaturestatus_patchedrepair” = true, “isspecialfeaturestatus_extensivescraping” = true,
“specialfeature_notes” = ‘need help’, “exteriorestimate_laborcost” = 10, “exteriorestimate_materialcost” = 10, “exteriorestimate_totalcost” = 20, “isexteriorprep_powerwash” = true,
“isexteriorprep_scrape” = true, “isexteriorprep_mildew” = true, “isexteriorwarranty_oneyear” = true, “isexteriorwarranty_threeyear” = false, “isexteriorwarranty_fiveyear” = false, “user_id” = 1 WHERE paintproject_input.id = 128;