-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
tutorial.json
5424 lines (5424 loc) · 197 KB
/
tutorial.json
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"id": "freeCodeCamp/learn-bash-and-sql-by-building-a-bike-rental-shop:v1.0.0",
"version": "2.0.0",
"summary": {
"title": "Learn Bash and SQL by Building a Bike Rental Shop",
"description": "> Welcome to the Bash and SQL lessons!"
},
"config": {
"setup": {
"commands": [
"./.freeCodeCamp/setup.sh",
"cd .freeCodeCamp && npm install"
],
"commits": [
"4b08d6515a54c1fb28be33d1eeae8d2f3e7361cc"
]
},
"testRunner": {
"command": "npm run programmatic-test",
"args": {
"tap": "--reporter=mocha-tap-reporter"
},
"directory": ".freeCodeCamp"
},
"repo": {
"uri": "https://github.com/freeCodeCamp/learn-bash-and-sql-by-building-a-bike-rental-shop",
"branch": "v2.0.0"
},
"continue": {
"commands": [
"./.freeCodeCamp/setup.sh",
"./.freeCodeCamp/reset.sh"
]
},
"reset": {
"commands": [
"./.freeCodeCamp/setup.sh",
"./.freeCodeCamp/reset.sh"
]
},
"dependencies": [
{
"name": "node",
"version": ">=10"
}
],
"webhook": {
"url": "https://api.freecodecamp.org/coderoad-challenge-completed",
"events": {
"init": false,
"reset": false,
"step_complete": false,
"level_complete": false,
"tutorial_complete": true
}
}
},
"levels": [
{
"id": "10",
"title": "Start the Terminal",
"summary": "",
"content": "",
"steps": [
{
"id": "10.1",
"setup": {
"watchers": [
"../.bash_history"
],
"commits": [
"d62d31edaf6d69565f67e9ed7943aa46b28482c7"
]
},
"content": "**The first thing you need to do is start the terminal.** Do that by clicking the \"hamburger\" menu at the top left of the screen, going to the \"terminal\" section, and clicking \"new terminal\". Once you open a new one, type `echo hello terminal` into the terminal and press enter.",
"hints": [
"Capitalization matters",
"If the tests don't run automatically, try typing `exit` into the terminal and redoing the instructions"
]
}
]
},
{
"id": "20",
"title": "Log in to Psql",
"summary": "",
"content": "",
"steps": [
{
"id": "20.1",
"setup": {
"watchers": [
"../pg.log"
],
"commits": [
"9830cd06d0e462b8b578a4969cd75af6666fac38"
]
},
"content": "You are going to build a bike rental shop. It will have a database, and a bash script to interact with the database. Use the terminal to connect to PostgreSQL by entering `psql --username=freecodecamp --dbname=postgres`.",
"hints": [
"Type the above command into the terminal and press enter",
"Type `psql --username=freecodecamp --dbname=postgres` into the terminal and press enter"
]
}
]
},
{
"id": "30",
"title": "List Databases",
"summary": "",
"content": "",
"steps": [
{
"id": "30.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"5bdf02abc59ffe99638af1664c91e6a98ce38c51"
]
},
"content": "List the databases with `\\l` to see what databases are here.",
"hints": [
"Type `\\l` into the psql prompt and press enter",
"Type `psql --username=freecodecamp --dbname=postgres` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "40",
"title": "Create Database `bikes`",
"summary": "",
"content": "",
"steps": [
{
"id": "40.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"b3c920a800bf4b62480581f2065e9ad8ea5222b0"
]
},
"content": "You need your own database for the bike shop. Create a new database named `bikes`.",
"hints": [
"Use the `CREATE DATABASE` keywords",
"Here's an example: `CREATE DATABASE database_name;`",
"Type `CREATE DATABASE bikes;` into the psql prompt and press enter",
"Type `psql --username=freecodecamp --dbname=postgres` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "50",
"title": "List Databases",
"summary": "",
"content": "",
"steps": [
{
"id": "50.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"0d557f4fb1477da6eec9610649b3f519df1a7ebb"
]
},
"content": "List databases again to make sure your database got created.",
"hints": [
"Use the **l**ist shortcut command",
"Type `\\l` into the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "60",
"title": "Connect to `bikes`",
"summary": "",
"content": "",
"steps": [
{
"id": "60.1",
"setup": {
"watchers": [
"../pg.log"
],
"commits": [
"804cadc3ab6866b3bbb11a79d6fef6e5f6ca4cb9"
]
},
"content": "There it is. **C**onnect to it so you can start building the structure of your bike shop database.",
"hints": [
"Use the **c**onnect shortcut command",
"Add the database name to the command",
"It's the `\\c` command",
"Here's an example: `\\c database_name`",
"Try entering `\\c bikes` into the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "70",
"title": "Create table `bikes`",
"summary": "",
"content": "",
"steps": [
{
"id": "70.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"806519191c296cbe9b950d417b5f29124b7465df"
]
},
"content": "Your database needs three tables. One for your bike inventory, one for your customers, and one for the bikes that are rented out. Create a table named `bikes` in your database for the inventory.",
"hints": [
"Use the `CREATE TABLE` keywords",
"Don't forget the parenthesis",
"Here's an example: `CREATE TABLE table_name();`",
"Try entering `CREATE TABLE bikes();` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "80",
"title": "Display the tables",
"summary": "",
"content": "",
"steps": [
{
"id": "80.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"4c675e83042a9b1211649d2160a4027b9072a5c8"
]
},
"content": "**D**isplay the tables to make sure your table got created.",
"hints": [
"Use the **d**isplay shortcut command",
"It's the `\\d` command",
"Type `\\d` into the psql prompt and press enter",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "90",
"title": "Add column `bike_id`",
"summary": "",
"content": "",
"steps": [
{
"id": "90.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"80e6f0226a42759f7101aa95c8a241be433507fa"
]
},
"content": "The table will have a few columns for bike information. First, is a unique ID column. Add a column to the `bikes` table named `bike_id`. Give it a type of `SERIAL` and make it a `PRIMARY KEY`.",
"hints": [
"Use the `ALTER TABLE`, `ADD COLUMN`, `SERIAL`, and `PRIMARY KEY` keywords",
"Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS;`",
"Try entering `ALTER TABLE bikes ADD COLUMN bike_id SERIAL PRIMARY KEY;` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "100",
"title": "Display `bikes` Details",
"summary": "",
"content": "",
"steps": [
{
"id": "100.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"1766f2604ae15802da3f6569267bdd0379e36ac7"
]
},
"content": "Use the **d**isplay command to view the details of the `bikes` table.",
"hints": [
"It's the `\\d` command",
"Add the table name to the command",
"Try entering `\\d bikes` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "110",
"title": "Add `type` column",
"summary": "",
"content": "",
"steps": [
{
"id": "110.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"7782e36acb0f1ece4079eeb3bde1a9626ef3d9cb"
]
},
"content": "The first column is set. Add a column named `type` for the type of bike. Make it a `VARCHAR(50)` and give it a constraint of `NOT NULL`.",
"hints": [
"Use the `ALTER TABLE`, `ADD COLUMN`, `VARCHAR(50)`, and `PRIMARY KEY` keywords",
"Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS;`",
"Try entering `ALTER TABLE bikes ADD COLUMN type VARCHAR(50) NOT NULL;` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "120",
"title": "Display `bikes` details",
"summary": "",
"content": "",
"steps": [
{
"id": "120.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"b5013ab84369cd7644471ffe85d66c1c5e13fc6a"
]
},
"content": "Display the details of the `bikes` table again.",
"hints": [
"Use the **d**isplay shortcut command",
"Add the table name to the command",
"Here's an example: `\\d table_name`",
"Try entering `\\d bikes` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in"
]
}
]
},
{
"id": "130",
"title": "Add Column `size`",
"summary": "",
"content": "",
"steps": [
{
"id": "130.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"409564d068666998413a6636eccdaa02114e3197"
]
},
"content": "The first two columns look good. Add a column named `size` to the `bikes` table that is an `INT` and has the `NOT NULL` constraint. This will be for the size of each bike.",
"hints": [
"Use the `ALTER TABLE`, `ADD COLUMN`, `INT`, and `NOT NULL` keywords",
"Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS;`",
"Try entering `ALTER TABLE bikes ADD COLUMN size INT NOT NULL;` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in"
]
}
]
},
{
"id": "140",
"title": "Add Column `available`",
"summary": "",
"content": "",
"steps": [
{
"id": "140.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"cf7f8fb3b6e6f8877be2b7e7b5ce14f2047af21f"
]
},
"content": "Add another column to the table named `available`. Make it a `boolean` and has a constraint of `NOT NULL`. Also give it a default value of `TRUE`. This will be set to `false` when someone rents out a bike.",
"hints": [
"Use the `ALTER TABLE`, `ADD COLUMN`, `BOOLEAN`, `NOT NULL` and `DEFAULT TRUE` keywords",
"Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS DEFAULT;`",
"Try entering `ALTER TABLE bikes ADD COLUMN available BOOLEAN NOT NULL DEFAULT TRUE;` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in"
]
}
]
},
{
"id": "150",
"title": "Display `bikes` details",
"summary": "",
"content": "",
"steps": [
{
"id": "150.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"6fcd9fb666adf2ac11efd2c77d6ba1440c089419"
]
},
"content": "Display the details of the `bikes` table again so you can make sure it's how you want it.",
"hints": [
"Use the **d**isplay shortcut command",
"Add the table name to the command",
"Here's an example: `\\d table_name`",
"Try entering `\\d bikes` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "160",
"title": "Create Table `customers`",
"summary": "",
"content": "",
"steps": [
{
"id": "160.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"c3193f4e8ea22785f9af35fb2ec5e607b9c6b121"
]
},
"content": "That table is done for now. Create another table named `customers`. It will store a name and phone number for each customer that rents a bike.",
"hints": [
"Use the `CREATE TABLE` keywords",
"Don't forget the parenthesis",
"Here's an example: `CREATE TABLE table_name();`",
"Try entering `CREATE TABLE customers();` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "170",
"title": "Add Column `customer_id`",
"summary": "",
"content": "",
"steps": [
{
"id": "170.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"a9f3f9439953c32ddd4e89c98719640b634515ab"
]
},
"content": "Add a `customer_id` column to your new table that is a type of `SERIAL` and make it a `PRIMARY KEY`.",
"hints": [
"Use the `ALTER TABLE`, `ADD COLUMN`, `SERIAL`, and `PRIMARY KEY` keywords",
"Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS;`",
"Try entering `ALTER TABLE customers ADD COLUMN customer_id SERIAL PRIMARY KEY;` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "180",
"title": "Display `customers` Details",
"summary": "",
"content": "",
"steps": [
{
"id": "180.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"a41e139cd6232efb8c4209e4e176864dbf62a682"
]
},
"content": "Display the details of the `customers` table so you can make sure your new column is there.",
"hints": [
"Use the **d**isplay shortcut command",
"Add the table name to the command",
"Here's an example: `\\d table_name`",
"Try entering `\\d customers` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "190",
"title": "Add Column `phone`",
"summary": "",
"content": "",
"steps": [
{
"id": "190.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"5167886358297b88912088f1b6ff725b0b624db0"
]
},
"content": "There it is. Add a column named `phone` for customers phone numbers. Make it a varying character that has a maximum length of `15` characters. Also make sure it can't be null, and that it has to be unique.",
"hints": [
"Use the `ALTER TABLE`, `ADD COLUMN`, `VARCHAR()`, `NOT NULL`, and `UNIQUE` keywords",
"Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS;`",
"Try entering `ALTER TABLE customers ADD COLUMN phone VARCHAR(15) NOT NULL UNIQUE;` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "200",
"title": "Add Column `name`",
"summary": "",
"content": "",
"steps": [
{
"id": "200.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"1f1c7f671f80d4ce89cef407128c8a1a354ba9aa"
]
},
"content": "Add the last column. Call it `name` and make it a `VARCHAR(40)` that can't be null.",
"hints": [
"Use the `ALTER TABLE`, `ADD COLUMN`, `VARCHAR()`, and `NOT NULL` keywords",
"Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS;`",
"Try entering `ALTER TABLE customers ADD COLUMN name VARCHAR(40) NOT NULL;` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "210",
"title": "Display `customers` Details",
"summary": "",
"content": "",
"steps": [
{
"id": "210.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"eb572362a32d8a5dc7b8dbaf38de7d1b046fb2b4"
]
},
"content": "Display the details of the `customers` table.",
"hints": [
"Use the **d**isplay shortcut command",
"Add the table name to the command",
"Here's an example: `\\d table_name`",
"Try entering `\\d customers` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "220",
"title": "Create Table `rentals`",
"summary": "",
"content": "",
"steps": [
{
"id": "220.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"1d57bf3a5bb7597d0e81f5c68152ed0cfdd6f447"
]
},
"content": "That table is finished. Lastly, you need a table to store which bikes are rented and who has rented them. Create a new table named `rentals`.",
"hints": [
"Use the `CREATE TABLE` keywords",
"Don't forget the parenthesis",
"Here's an example: `CREATE TABLE table_name();`",
"Try entering `CREATE TABLE rentals();` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "230",
"title": "Add Column `rental_id`",
"summary": "",
"content": "",
"steps": [
{
"id": "230.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"56d91299d51e399cf3e764cef7c3ebd91e290e57"
]
},
"content": "Add a `rental_id` column to your new table. Make it automatically increment with `SERIAL` and make it the primary key for this table.",
"hints": [
"The other two properties are `SERIAL` and `PRIMARY KEY`",
"Use the `ALTER TABLE`, `ADD COLUMN`, `SERIAL`, and `PRIMARY KEY` keywords",
"Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS;`",
"Try entering `ALTER TABLE rentals ADD COLUMN rental_id SERIAL PRIMARY KEY;` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "240",
"title": "Display `rentals` Details",
"summary": "",
"content": "",
"steps": [
{
"id": "240.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"4b254af70c8974cdb630729117162ada2f3b7dd8"
]
},
"content": "Display the details of the `rentals` table.",
"hints": [
"Use the **d**isplay shortcut command",
"Add the table name to the command",
"Here's an example: `\\d table_name`",
"Try entering `\\d rentals` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "250",
"title": "Add Column `customer_id`",
"summary": "",
"content": "",
"steps": [
{
"id": "250.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"1bf3a00dec97f1219a18cce088fdd42a6a62b9e2"
]
},
"content": "Next, you need a column for the customer who is renting a bike. Add column named `customer_id`. This will have an id of a customer from the customers table. Make the column an `INT` and `NOT NULL` to start.",
"hints": [
"Add the column to the `rentals` table",
"Use the `ALTER TABLE`, `ADD COLUMN`, `INT`, and `NOT NULL` keywords",
"Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS;`",
"Try entering `ALTER TABLE rentals ADD COLUMN customer_id INT NOT NULL;` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "260",
"title": "Set `customer_id` Foreign Key",
"summary": "",
"content": "",
"steps": [
{
"id": "260.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"b84640be2b65aa2af8589acb21c58863991f47f9"
]
},
"content": "Make the column you just added a foreign key that references the `customer_id` column from the `customers` table. Here's an example of how you can do that:\n\n```sql\nALTER TABLE table_name ADD FOREIGN KEY(column_name) REFERENCES referenced_table(referenced_column);\n```",
"hints": [
"Without the keywords, it looks like tihs: `rentals customer_id customers(customer_id)`",
"Try entering `ALTER TABLE rentals ADD FOREIGN KEY(customer_id) REFERENCES customers(customer_id);` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "270",
"title": "Display `rentals` Details",
"summary": "",
"content": "",
"steps": [
{
"id": "270.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"6cafe6900af9dde93435262b02ba59791560b8c1"
]
},
"content": "Display the details of the `rentals` table to make sure your key is set.",
"hints": [
"Use the **d**isplay shortcut command",
"Add the table name to the command",
"Here's an example: `\\d table_name`",
"Try entering `\\d rentals` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "280",
"title": "Add Column `bike_id`",
"summary": "",
"content": "",
"steps": [
{
"id": "280.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"813351fe30a62648e3ece0439a7d63306d7bf957"
]
},
"content": "That foreign key is set. You need another column so you know what bike a customer is renting. Add a column named `bike_id` and make it an `INT` and `NOT NULL`.",
"hints": [
"Add the column to the `rentals` table",
"Use the `ALTER TABLE`, `ADD COLUMN`, `INT`, and `NOT NULL` keywords",
"Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS;`",
"Try entering `ALTER TABLE rentals ADD COLUMN bike_id INT NOT NULL;` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "290",
"title": "Add `bike_id` Foreign Key",
"summary": "",
"content": "",
"steps": [
{
"id": "290.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"3249fb6a154ffbf43e089c5547296476ee53e95e"
]
},
"content": "Make that column a foreign key that references the `bike_id` column from the `bikes` table so you know what bike the id is for.",
"hints": [
"Here's the example again: `ALTER TABLE table_name ADD FOREIGN KEY(column_name) REFERENCES referenced_table(referenced_column);`",
"Without the keywords, it looks like tihs: `rentals bike_id bikes(bike_id)`",
"Try entering `ALTER TABLE rentals ADD FOREIGN KEY(bike_id) REFERENCES bikes(bike_id);` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "300",
"title": "Display `rentals` Details",
"summary": "",
"content": "",
"steps": [
{
"id": "300.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"2a57acab8380041b732496c7bbaad34c9c118c08"
]
},
"content": "Display the details of the `rentals` table so you can make sure the key is correct.",
"hints": [
"Use the **d**isplay shortcut command",
"Add the table name to the command",
"Here's an example: `\\d table_name`",
"Try entering `\\d rentals` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "310",
"title": "Add `date_rented` Column",
"summary": "",
"content": "",
"steps": [
{
"id": "310.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"edec8d112d980c04be6b1f54f4ac5d002436da01"
]
},
"content": "Moving along. You want to know when a customer rents a bike, and when it gets returned. Add a column to your `rentals` table named `date_rented` that's a type of `DATE`. Make sure the entry can't be null, and give it a default value of `NOW()`.",
"hints": [
"Add the column to the `rentals` table",
"Use the `ALTER TABLE`, `ADD COLUMN`, `DATE`, `NOT NULL`, and `DEFAULT NOW()` keywords",
"Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS;`",
"Try entering `ALTER TABLE rentals ADD COLUMN date_rented DATE NOT NULL DEFAULT NOW();` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "320",
"title": "Display `rentals` Details",
"summary": "",
"content": "",
"steps": [
{
"id": "320.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"b4d7eb147bf8049c260de24c26f2c61d14014fb0"
]
},
"content": "Display the details of the `rentals` table again.",
"hints": [
"Use the **d**isplay shortcut command",
"Add the table name to the command",
"Here's an example: `\\d table_name`",
"Try entering `\\d rentals` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "330",
"title": "Add Column `date_returned`",
"summary": "",
"content": "",
"steps": [
{
"id": "330.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"7ae551f37dd4e617b13e11627ac2cdc563adc27b"
]
},
"content": "It looks good. Lastly, you need a column for when a customer returns a bike. Add a column named `date_returned` that's a type of `DATE`.",
"hints": [
"Use the `ALTER TABLE`, `ADD COLUMN`, `DATE` keywords",
"Add the column to the `rentals` table",
"Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE;`",
"Try entering `ALTER TABLE rentals ADD COLUMN date_returned DATE;` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "340",
"title": "Display `rentals` Details",
"summary": "",
"content": "",
"steps": [
{
"id": "340.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"bb637a0426cb8fba1608ac0743d826466667b261"
]
},
"content": "View the details of the table again.",
"hints": [
"It's the `rentals` table",
"Use the **d**isplay shortcut command",
"Add the table name to the command",
"Here's an example: `\\d table_name`",
"Try entering `\\d rentals` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "350",
"title": "Display Tables",
"summary": "",
"content": "",
"steps": [
{
"id": "350.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"c154aac0808429ac37a2eddec46c5be92b9b39cb"
]
},
"content": "The tables are all finished. Display all the tables so you can see what you ended up with.",
"hints": [
"Use the **d**isplay shortcut command",
"It's the `\\d` command",
"Enter `\\d` in the psql prompt",
"Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first"
]
}
]
},
{
"id": "360",
"title": "Insert 27 inch Mountain Bike",
"summary": "",
"content": "",
"steps": [
{
"id": "360.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"aece2f81cc21923bd5995f0461326615fda3ac65"
]
},
"content": "You have nine bikes in your inventory. Add the first one to your `bikes` table. It has a `type` of `Mountain` and a `size` of `27`. Make sure to put your `VARCHAR` values in single quotes. The `bike_id` and `available` columns should be filled in automatically, so you don't need to worry about those.",
"hints": [
"Use the `INSERT INTO` and `VALUES` keywords",
"Here's an example: `INSERT INTO table_name(column_name, column_name) VALUES(value, value);`",