From c1916d96811d351617fa5425bd411d53fe387c96 Mon Sep 17 00:00:00 2001 From: Jamie Bort Date: Mon, 15 Dec 2025 09:40:41 -0500 Subject: [PATCH 1/7] Add the node-essentials.code-workspace VSCode config file. --- node-essentials.code-workspace | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 node-essentials.code-workspace diff --git a/node-essentials.code-workspace b/node-essentials.code-workspace new file mode 100644 index 0000000..876a149 --- /dev/null +++ b/node-essentials.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": {} +} \ No newline at end of file From 26436dfd8b2c14f19a969783811f7f1f99a253b3 Mon Sep 17 00:00:00 2001 From: Jamie Bort Date: Sat, 7 Feb 2026 16:04:43 -0500 Subject: [PATCH 2/7] Start making notes and suggesting changes. --- issue96-files/README.md | 23 ++ issue96-files/notes.md | 200 +++++++++++ issue96-files/semi-complete-output.txt | 473 +++++++++++++++++++++++++ 3 files changed, 696 insertions(+) create mode 100644 issue96-files/README.md create mode 100644 issue96-files/notes.md create mode 100644 issue96-files/semi-complete-output.txt diff --git a/issue96-files/README.md b/issue96-files/README.md new file mode 100644 index 0000000..5f30ab3 --- /dev/null +++ b/issue96-files/README.md @@ -0,0 +1,23 @@ +# issue96-files + +## Purpose of this directory + +This directory is strictly for organizing my notes and thoughts; which will be used for the [Review, test and evaluate Week 6](https://github.com/Code-the-Dream-School/node-essentials/issues/96) GitHub Issue. I created this directory + +1. ~~to keep track of where I had left off for the day~~ and + +2. to make any notes relevant to my completing the assignment and + +3. to make any notes to help me understand the content better. + +~~All that to say, this directory and its contents can be discarded.~~ + +## Explanation of files + + + +./issue96-files/semi-complete-output.txt - the Terminal output from using Git and from using the commands in the assignment. This was documented for my own sake in case I needed to revisit it. It can be discarded and/or ignored. + +./issue96-files/notes.md - The file I kept to document my thoughts as I worked on the Issue. Again, this file can be discarded and/or ignored. + +./issue96-files/README.md - Created to explain the reason for this issue96-files/ directory. This file can be discarded and/or ignored. diff --git a/issue96-files/notes.md b/issue96-files/notes.md new file mode 100644 index 0000000..ddf59a8 --- /dev/null +++ b/issue96-files/notes.md @@ -0,0 +1,200 @@ +# Notes for Lesson/Assignment 6 + +## About this file + +This is a file created to make note of things as they pertain to the https://github.com/Code-the-Dream-School/node-essentials/issues/96 Issue, which was created for the 6th lesson. More specifically it was created to "review, test, and evaluate Lesson/Assignment 6 for accuracy and clarity." + +## Specific instructions + +- Make sure all examples and instructions work as expected. +- If sample answers are not available, please create and submit them. +- If sample answers exist in the mentor guidebook, test them out to confirm everything runs correctly. +- Note any issues, confusing sections, or areas that may need improvement, and provide feedback or suggested fixes in the comments. + +## Scope of review + +## Resources used + +Two files are used for the 6th lesson/assignment. Meaning I'll be looking at + +- The lesson file: https://github.com/Code-the-Dream-School/node-essentials/blob/main/lessons/06-intro-to-prisma.md +- The assignment file: https://github.com/Code-the-Dream-School/node-essentials/blob/main/assignments/06-intro-to-prisma.md + +## Notes + +The lesson file is well written - upon first read I didn't notice anything that should change. It flowed and appeared to be comprehensive. + + + +## Proposed text changes + +Original +From this point on, if you make a schema change, you change the model, do an npx prisma migrate dev, and then, for the test database, do the corresponding npx prisma migrate deploy. + +Proposed +From this point on, if you make a schema change, first change the model, next do an npx prisma migrate dev, last, do the corresponding npx prisma migrate deploy for the test database. + +Original + +You do not change the schema with ordinary SQL. You'll use the deploy also with the production database you create for Internet deployment of your app in lesson 10. You never use a schema reset with the production database, for the obvious reason that it deletes all the data. + +TODO: make these suggestions in the node-homework repo. + +TODO: Use commands rather than "You" all the time. + +``` +..., it also does the following: + +await prisma.$disconnect(); + console.log("Prisma disconnected"); +``` + +It does what??? These are commands, not an explanation. + +--- + +For the register method in usercontroller: "b. Fix Register" + +Your schema: model users → Prisma client: prisma.users + +Current code: prisma.user → undefined → TypeError + +Fix: replace all prisma.user references with prisma.users + +and + +replace +res +.status(201) +.json({ name: result.rows[0].name, email: result.rows[0].email }); + +with +res.status(201).json({ name: user.name, email: user.email, id: user.id }); + +--- + +for "Fix the Task Index Method" + +`const tasks = await prisma.task.findMany({` should be `const tasks = await prisma.tasks.findMany({` instead + +--- + +for "Fix Task Update" + +rather than + +``` +try { + const task = await prisma.task.update({ + data: value, + where: { + id, + userId: global.user_id, + }, + select: { title: true, isCompleted: true, id: true } + }); +} catch (err) { + if (err.code === "P2025" ) { + return res.status(404).json({ message: "The task was not found."}) + } else { + return next(err); // pass other errors to the global error handler + } +} +``` + +--- + +For "Update the Show Method" + +prisma.task.findUnique() does not throw a P2025 error when no record is found. It simply returns null. The P2025 error only occurs with operations that modify data (update, delete, updateMany, etc.) when no matching record exists. + +Per https://www.prisma.io/docs/orm/reference/prisma-client-reference#findunique, "By default, both operations return null if the record is not found." + + + +### Actions I took, in order + +1. First command + +``` +node-homework % npm install prisma @prisma/client + +added 24 packages, removed 1 package, changed 8 packages, and audited 575 packages in 41s + +106 packages are looking for funding + run `npm fund` for details + +found 0 vulnerabilities +``` + +2. Second command + +``` +node-homework % npx prisma init +Fetching latest updates for this subcommand... + +Initialized Prisma in your project + + prisma/ + schema.prisma + prisma.config.ts + +warn Prisma would have added DATABASE_URL but it already exists in .env +warn You already have a .gitignore file. Don't forget to add .env in it to not commit any private information. + +Next, choose how you want to set up your database: +CONNECT EXISTING DATABASE: + 1. Configure your DATABASE_URL in prisma.config.ts + 2. Run prisma db pull to introspect your database. +CREATE NEW DATABASE: + Local: npx prisma dev (runs Postgres locally in your terminal) + Cloud: npx create-db (creates a free Prisma Postgres database) + +Then, define your models in prisma/schema.prisma and run prisma migrate dev to apply your schema. +Learn more: https://pris.ly/getting-started +``` + +3. Third command `rm prisma.config.ts ` + +4. Fourth command `npx prisma generate` + +5. Fifth command + +``` +node-homework % npx prisma generate +Environment variables loaded from .env +Prisma schema loaded from prisma/schema.prisma + +✔ Generated Prisma Client (v6.19.2) to ./node_modules/@prisma/client in 139ms + +Start by importing your Prisma Client (See: https://pris.ly/d/importing-client) + +Tip: Interested in query caching in just a few lines of code? Try Accelerate today! https://pris.ly/tip-3-accelerate +``` + +6. Sixth command + +`npx prisma db pull` + +``` +node-homework % npx prisma db pull +Environment variables loaded from .env +Prisma schema loaded from prisma/schema.prisma +Datasource "db": PostgreSQL database "tasklist", schema "public" at "localhost" + +✔ Introspected 2 models and wrote them into prisma/schema.prisma in 229ms + +Run prisma generate to generate Prisma Client. +┌─────────────────────────────────────────────────────────┐ +│ Update available 6.19.2 -> 7.3.0 │ +│ │ +│ This is a major update - please follow the guide at │ +│ https://pris.ly/d/major-version-upgrade │ +│ │ +│ Run the following to update │ +│ npm i --save-dev prisma@latest │ +│ npm i @prisma/client@latest │ +└─────────────────────────────────────────────────────────┘ + +zeus@MacBook-Air-de-Jamie node-homework % +``` diff --git a/issue96-files/semi-complete-output.txt b/issue96-files/semi-complete-output.txt new file mode 100644 index 0000000..dbcb676 --- /dev/null +++ b/issue96-files/semi-complete-output.txt @@ -0,0 +1,473 @@ +TODO: delete this file. + +zeus@MacBook-Air-de-Jamie node-homework % git status +On branch assignment5 +nothing to commit, working tree clean +zeus@MacBook-Air-de-Jamie node-homework % npm install pg dotenv + +added 34 packages, removed 2 packages, changed 6 packages, and audited 551 packages in 3s + +102 packages are looking for funding + run `npm fund` for details + +1 high severity vulnerability + +To address all issues, run: + npm audit fix + +Run `npm audit` for details. +zeus@MacBook-Air-de-Jamie node-homework % npm audit +# npm audit report + +qs <6.14.1 +Severity: high +qs's arrayLimit bypass in its bracket notation allows DoS via memory exhaustion - https://github.com/advisories/GHSA-6rw7-vpxm-498p +fix available via `npm audit fix` +node_modules/qs + +1 high severity vulnerability + +To address all issues, run: + npm audit fix +zeus@MacBook-Air-de-Jamie node-homework % npm audit fix + +changed 1 package, and audited 551 packages in 2s + +102 packages are looking for funding + run `npm fund` for details + +found 0 vulnerabilities +zeus@MacBook-Air-de-Jamie node-homework % git status +On branch assignment5 +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + modified: package-lock.json + modified: package.json + +no changes added to commit (use "git add" and/or "git commit -a") +zeus@MacBook-Air-de-Jamie node-homework % psql --version +psql (PostgreSQL) 14.20 (Homebrew) +zeus@MacBook-Air-de-Jamie node-homework % brew services list +✔︎ JSON API cask_tap_migrations.jws.json [Downloaded 2.4KB/ 2.4KB] +✔︎ JSON API cask.jws.json [Downloaded 15.3MB/ 15.3MB] +✔︎ JSON API formula.jws.json [Downloaded 32.0MB/ 32.0MB] +✔︎ JSON API formula_tap_migrations.jws.json [Downloaded 1.9KB/ 1.9KB] +Name Status User File +postgresql@14 started zeus ~/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist +zeus@MacBook-Air-de-Jamie node-homework % brew services start postgresql@14 +Service `postgresql@14` already started, use `brew services restart postgresql@14` to restart. +zeus@MacBook-Air-de-Jamie node-homework % brew services list +Name Status User File +postgresql@14 started zeus ~/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist +zeus@MacBook-Air-de-Jamie node-homework % ls -l +total 440 +-rw-r--r-- 1 zeus staff 1071 Dec 15 11:51 LICENSE +-rw-r--r--@ 1 zeus staff 14186 Dec 29 17:47 README.md +-rw-r--r--@ 1 zeus staff 2037 Jan 29 17:13 app.js +drwxr-xr-x 10 zeus staff 320 Dec 15 11:51 assignment1 +drwxr-xr-x 3 zeus staff 96 Dec 15 11:51 assignment2 +drwxr-xr-x 4 zeus staff 128 Jan 29 17:13 assignment5 +drwxr-xr-x 3 zeus staff 96 Dec 15 11:51 class-utils +drwxr-xr-x@ 4 zeus staff 128 Jan 29 17:13 controllers +drwxr-xr-x 7 zeus staff 224 Dec 15 11:51 csv +drwxr-xr-x@ 3 zeus staff 96 Jan 29 17:13 db +-rw-r--r-- 1 zeus staff 421 Dec 15 11:51 eslint.config.js +drwxr-xr-x 4 zeus staff 128 Dec 15 11:51 lesson9TDD +-rw-r--r-- 1 zeus staff 5015 Dec 15 11:51 load-db.js +drwxr-xr-x@ 5 zeus staff 160 Jan 29 17:13 middleware +-rw-r--r--@ 1 zeus staff 60 Jan 29 17:13 node-homework.code-workspace +drwxr-xr-x 393 zeus staff 12576 Jan 30 11:33 node_modules +-rw-r--r--@ 1 zeus staff 162994 Jan 30 11:33 package-lock.json +-rw-r--r--@ 1 zeus staff 1293 Jan 30 11:25 package.json +-rw-r--r-- 1 zeus staff 1 Dec 15 11:51 project-links.txt +drwxr-xr-x@ 4 zeus staff 128 Jan 29 17:13 routes +-rw-r--r--@ 1 zeus staff 682 Jan 29 17:13 schema.sql +-rw-r--r-- 1 zeus staff 2884 Dec 15 11:51 sqlcommand.js +drwxr-xr-x 14 zeus staff 448 Jan 29 17:13 tdd +-rwxr-xr-x@ 1 zeus staff 184 Jan 29 17:13 tdd.sh +drwxr-xr-x@ 11 zeus staff 352 Jan 29 17:13 validation +drwxr-xr-x 6 zeus staff 192 Dec 15 11:51 week-3-middleware +zeus@MacBook-Air-de-Jamie node-homework % psql "postgresql://node_homework_owner@localhost/tasklist?host=/tmp" -f schema.sql +psql:schema.sql:9: NOTICE: relation "users" already exists, skipping +CREATE TABLE +psql:schema.sql:19: NOTICE: relation "tasks" already exists, skipping +CREATE TABLE +zeus@MacBook-Air-de-Jamie node-homework % postgresql://node_homework_owner@localhost/testtasklist?host=/tmp +zeus@MacBook-Air-de-Jamie node-homework % psql "postgresql://node_homework_owner@localhost/testtasklist?host=/tmp" -f schema.sql +psql:schema.sql:9: NOTICE: relation "users" already exists, skipping +CREATE TABLE +psql:schema.sql:19: NOTICE: relation "tasks" already exists, skipping +CREATE TABLE +zeus@MacBook-Air-de-Jamie node-homework % git status +On branch assignment5 +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + modified: package-lock.json + modified: package.json + +no changes added to commit (use "git add" and/or "git commit -a") +zeus@MacBook-Air-de-Jamie node-homework % + * History restored + +zeus@MacBook-Air-de-Jamie node-homework % npm dev +Unknown command: "dev" + + +Did you mean this? + npm run dev # run the "dev" package script +To see a list of supported npm commands, run: + npm help +zeus@MacBook-Air-de-Jamie node-homework % npm run dev + +> node-homework@1.0.0 dev +> nodemon app.js + +[nodemon] 3.1.10 +[nodemon] to restart at any time, enter `rs` +[nodemon] watching path(s): *.* +[nodemon] watching extensions: js,mjs,cjs,json +[nodemon] starting `node app.js` +Server is listening on port 3000... +Internal server error: DatabaseError {"name":"error","message":"null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint","stack":"error: null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint\n at /Users/zeus/Documents/development/node-homework/node_modules/pg-pool/index.js:45:11\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async exports.create (/Users/zeus/Documents/development/node-homework/controllers/taskController.js:43:15)"} +Internal server error: DatabaseError {"name":"error","message":"null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint","stack":"error: null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint\n at /Users/zeus/Documents/development/node-homework/node_modules/pg-pool/index.js:45:11\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async exports.create (/Users/zeus/Documents/development/node-homework/controllers/taskController.js:43:15)"} +Internal server error: DatabaseError {"name":"error","message":"null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint","stack":"error: null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint\n at /Users/zeus/Documents/development/node-homework/node_modules/pg-pool/index.js:45:11\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async exports.create (/Users/zeus/Documents/development/node-homework/controllers/taskController.js:43:15)"} +[nodemon] restarting due to changes... +[nodemon] starting `node app.js` +Server is listening on port 3000... +[nodemon] restarting due to changes... +[nodemon] starting `node app.js` +Server is listening on port 3000... +Internal server error: DatabaseError {"name":"error","message":"null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint","stack":"error: null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint\n at /Users/zeus/Documents/development/node-homework/node_modules/pg-pool/index.js:45:11\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async exports.create (/Users/zeus/Documents/development/node-homework/controllers/taskController.js:45:15)"} +[nodemon] restarting due to changes... +[nodemon] starting `node app.js` +Server is listening on port 3000... +global.user_id = 1 +Internal server error: DatabaseError {"name":"error","message":"null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint","stack":"error: null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint\n at /Users/zeus/Documents/development/node-homework/node_modules/pg-pool/index.js:45:11\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async exports.create (/Users/zeus/Documents/development/node-homework/controllers/taskController.js:45:15)"} +[nodemon] restarting due to changes... +[nodemon] starting `node app.js` +Server is listening on port 3000... +[nodemon] restarting due to changes... +[nodemon] starting `node app.js` +Server is listening on port 3000... +[nodemon] restarting due to changes... +[nodemon] starting `node app.js` +Server is listening on port 3000... +auth middleware, global.user_id = undefined +auth middleware, global.user_id = 1 +auth middleware, global.user_id = 1 +global.user_id = 1 +auth middleware, global.user_id = 1 +global.user_id = 1 +Internal server error: DatabaseError {"name":"error","message":"null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint","stack":"error: null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint\n at /Users/zeus/Documents/development/node-homework/node_modules/pg-pool/index.js:45:11\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async exports.create (/Users/zeus/Documents/development/node-homework/controllers/taskController.js:45:15)"} +[nodemon] restarting due to changes... +[nodemon] starting `node app.js` +Server is listening on port 3000... +auth middleware, global.user_id = undefined +[nodemon] restarting due to changes... +[nodemon] starting `node app.js` +Server is listening on port 3000... +[nodemon] restarting due to changes... +[nodemon] starting `node app.js` +Server is listening on port 3000... +auth middleware, global.user_id = 1 +auth middleware, global.user_id = 1 +global.user_id = 1 +auth middleware, global.user_id = 1 +global.user_id = 1 +auth middleware, global.user_id = 1 +[nodemon] restarting due to changes... +[nodemon] starting `node app.js` +Server is listening on port 3000... +auth middleware, global.user_id = undefined +auth middleware, global.user_id = undefined +auth middleware, global.user_id = 1 +auth middleware, global.user_id = 1 +auth middleware, global.user_id = 1 +auth middleware, global.user_id = 1 +^CShutting down gracefully... +HTTP server closed. +Exiting process... + +zeus@MacBook-Air-de-Jamie node-homework % npm run tdd assignment5 + +> node-homework@1.0.0 tdd +> ./tdd.sh assignment5 + +[napi-postinstall@0.3.0] Trying to install package "@unrs/resolver-binding-darwin-arm64" using npm +● Validation Error: + + Module /Users/zeus/Documents/development/node-homework/node_modules/jest-circus/build/runner.js in the testRunner option was not found. + is: /Users/zeus/Documents/development/node-homework + + Configuration Documentation: + https://jestjs.io/docs/configuration + +zeus@MacBook-Air-de-Jamie node-homework % npm run tdd assignment5b + +> node-homework@1.0.0 tdd +> ./tdd.sh assignment5b + + console.log + global.user_id = 4 + + at log (controllers/taskController.js:33:10) + + PASS tdd/assignment5b.test.js + ✓ finds the user and task schemas (1 ms) + test that database and tables exist + ✓ connects to database (54 ms) + ✓ clears the tasks table (1 ms) + ✓ clears the users table (1 ms) + testing logon, register, and logoff + ✓ You can register a user. (68 ms) + ✓ The user can be logged on (51 ms) + ✓ returns the expected name. (1 ms) + ✓ A logon attempt with a bad password returns a 401 (54 ms) + ✓ You can't register again with the same email. (54 ms) + ✓ You can register an additional user. (54 ms) + ✓ You can logon as that new user. (51 ms) + ✓ You can now logoff. (1 ms) + testing task creation + ✓ Logon before testing tasks (51 ms) + ✓ If you have a valid user id, create() succeeds (res.statusCode should be 201). (19 ms) + ✓ The object returned from the create() call has the expected title. (1 ms) + ✓ The object has the right value for isCompleted. + getting created tasks + ✓ If you use user1's id, index returns a 200 statusCode. (3 ms) + ✓ The returned JSON array has length 1. + ✓ The title in the first array object is as expected. (1 ms) + ✓ If get the list of tasks using the userId from user2, you get a 404. (1 ms) + ✓ You can retrieve the first array object using the `show()` method of the controller. (2 ms) + testing the update and delete of tasks. + ✓ User1 can set the task to isCompleted: true. (2 ms) + ✓ User2 can't do this. (1 ms) + ✓ User2 can't delete this task. (1 ms) + ✓ User1 can delete this task. (2 ms) + ✓ Retrieving user1's tasks now returns a 404. (1 ms) + user object validation tests + ✓ doesn't permit a trivial password (1 ms) + ✓ The user schema requires that an email be specified. (1 ms) + ✓ The user schema does not accept an invalid email. (1 ms) + ✓ The user schema requires a password. (1 ms) + ✓ The user schema requires name. (1 ms) + ✓ The name must be valid (3 to 30 characters). (1 ms) + ✓ If validation is performed on a valid user object, error comes back falsy. + task object validation test + ✓ The task schema requires a title. + ✓ If an isCompleted value is specified, it must be valid. (1 ms) + ✓ If an isCompleted value is not specified but the rest of the object is valid, a default of false is provided by validation + ✓ If `isCompleted` in the provided object has the value `true`, it remains `true` after validation. (1 ms) + patchTask object validation test + ✓ Test that the title is not required in this case. + ✓ Test that if no value is provided for `isCompleted`, that this remains undefined in the returned value. (1 ms) + +Test Suites: 1 passed, 1 total +Tests: 39 passed, 39 total +Snapshots: 0 total +Time: 1.005 s +Ran all test suites matching ^tdd/.*assignment5b.*\.test\.js. +zeus@MacBook-Air-de-Jamie node-homework % git status +On branch assignment5 +Changes to be committed: + (use "git restore --staged ..." to unstage) + modified: controllers/taskController.js + modified: package-lock.json + modified: package.json + +zeus@MacBook-Air-de-Jamie node-homework % git add . && git commit -m "Prepare for assignment6 by completing assignment 5." +[assignment5 f46ca64] Prepare for assignment6 by completing assignment 5. + 3 files changed, 114 insertions(+), 100 deletions(-) +zeus@MacBook-Air-de-Jamie node-homework % git status +On branch assignment5 +nothing to commit, working tree clean +zeus@MacBook-Air-de-Jamie node-homework % git push +fatal: The current branch assignment5 has no upstream branch. +To push the current branch and set the remote as upstream, use + + git push --set-upstream origin assignment5 + +To have this happen automatically for branches without a tracking +upstream, see 'push.autoSetupRemote' in 'git help config'. + +zeus@MacBook-Air-de-Jamie node-homework % git push --set-upstream origin assignment5 +Enumerating objects: 22, done. +Counting objects: 100% (21/21), done. +Delta compression using up to 8 threads +Compressing objects: 100% (11/11), done. +Writing objects: 100% (11/11), 2.93 KiB | 2.93 MiB/s, done. +Total 11 (delta 7), reused 0 (delta 0), pack-reused 0 (from 0) +remote: Resolving deltas: 100% (7/7), completed with 4 local objects. +remote: +remote: Create a pull request for 'assignment5' on GitHub by visiting: +remote: https://github.com/JamieBort/node-homework/pull/new/assignment5 +remote: +remote: GitHub found 1 vulnerability on JamieBort/node-homework's default branch (1 high). To find out more, visit: +remote: https://github.com/JamieBort/node-homework/security/dependabot/7 +remote: +To github.com:JamieBort/node-homework.git + * [new branch] assignment5 -> assignment5 +branch 'assignment5' set up to track 'origin/assignment5'. +zeus@MacBook-Air-de-Jamie node-homework % git status +On branch assignment5 +Your branch is up to date with 'origin/assignment5'. + +nothing to commit, working tree clean +zeus@MacBook-Air-de-Jamie node-homework % git switch assignment6 +fatal: invalid reference: assignment6 +zeus@MacBook-Air-de-Jamie node-homework % git switch -c assignment6 +Switched to a new branch 'assignment6' +zeus@MacBook-Air-de-Jamie node-homework % git status +On branch assignment6 +nothing to commit, working tree clean +zeus@MacBook-Air-de-Jamie node-homework % npm install prisma @prisma/client + +added 24 packages, removed 1 package, changed 8 packages, and audited 575 packages in 41s + +106 packages are looking for funding + run `npm fund` for details + +found 0 vulnerabilities +zeus@MacBook-Air-de-Jamie node-homework % npx prisma init +Fetching latest updates for this subcommand... + +Initialized Prisma in your project + + prisma/ + schema.prisma + prisma.config.ts + +warn Prisma would have added DATABASE_URL but it already exists in .env +warn You already have a .gitignore file. Don't forget to add .env in it to not commit any private information. + +Next, choose how you want to set up your database: +CONNECT EXISTING DATABASE: + 1. Configure your DATABASE_URL in prisma.config.ts + 2. Run prisma db pull to introspect your database. +CREATE NEW DATABASE: + Local: npx prisma dev (runs Postgres locally in your terminal) + Cloud: npx create-db (creates a free Prisma Postgres database) + +Then, define your models in prisma/schema.prisma and run prisma migrate dev to apply your schema. +Learn more: https://pris.ly/getting-started + + +zeus@MacBook-Air-de-Jamie node-homework % rm prisma.config.ts +zeus@MacBook-Air-de-Jamie node-homework % npx prisma generate +Environment variables loaded from .env +Prisma schema loaded from prisma/schema.prisma + +✔ Generated Prisma Client (v6.19.2) to ./node_modules/@prisma/client in 139ms + +Start by importing your Prisma Client (See: https://pris.ly/d/importing-client) + +Tip: Interested in query caching in just a few lines of code? Try Accelerate today! https://pris.ly/tip-3-accelerate + +zeus@MacBook-Air-de-Jamie node-homework % npx prisma db pull +Environment variables loaded from .env +Prisma schema loaded from prisma/schema.prisma +Datasource "db": PostgreSQL database "tasklist", schema "public" at "localhost" + +✔ Introspected 2 models and wrote them into prisma/schema.prisma in 229ms + +Run prisma generate to generate Prisma Client. +┌─────────────────────────────────────────────────────────┐ +│ Update available 6.19.2 -> 7.3.0 │ +│ │ +│ This is a major update - please follow the guide at │ +│ https://pris.ly/d/major-version-upgrade │ +│ │ +│ Run the following to update │ +│ npm i --save-dev prisma@latest │ +│ npm i @prisma/client@latest │ +└─────────────────────────────────────────────────────────┘ + +node-homework % git status +On branch assignment6 +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + modified: .gitignore + modified: package-lock.json + modified: package.json + +Untracked files: + (use "git add ..." to include in what will be committed) + database-status.txt + prisma/ + +no changes added to commit (use "git add" and/or "git commit -a") +zeus@MacBook-Air-de-Jamie node-homework % mv lesson6-notes.txt lesson6-notes.md +zeus@MacBook-Air-de-Jamie node-homework % brew services list +✔︎ JSON API formula_tap_migrations.jws.json [Downloaded 1.9KB/ 1.9KB] +✔︎ JSON API cask_tap_migrations.jws.json [Downloaded 2.4KB/ 2.4KB] +✔︎ JSON API cask.jws.json [Downloaded 15.3MB/ 15.3MB] +✔︎ JSON API formula.jws.json [Downloaded 32.0MB/ 32.0MB] +Name Status User File +postgresql@14 started zeus ~/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist +zeus@MacBook-Air-de-Jamie node-homework % npx prisma migrate reset +Environment variables loaded from .env +Prisma schema loaded from prisma/schema.prisma +Datasource "db": PostgreSQL database "tasklist", schema "public" at "localhost" + +✔ Are you sure you want to reset your database? All data will be lost. … yes + +Database reset successful + + +✔ Generated Prisma Client (v6.19.2) to ./node_modules/@prisma/client in 88ms + +npm notice +npm notice New major version of npm available! 10.8.2 -> 11.9.0 +npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.9.0 +npm notice To update run: npm install -g npm@11.9.0 +npm notice +zeus@MacBook-Air-de-Jamie node-homework % npx prisma migrate dev --name firstMigration +Environment variables loaded from .env +Prisma schema loaded from prisma/schema.prisma +Datasource "db": PostgreSQL database "tasklist", schema "public" at "localhost" + +Applying migration `20260206214630_first_migration` + +The following migration(s) have been created and applied from new schema changes: + +prisma/migrations/ + └─ 20260206214630_first_migration/ + └─ migration.sql + +Your database is now in sync with your schema. + +✔ Generated Prisma Client (v6.19.2) to ./node_modules/@prisma/client in 90ms + +┌─────────────────────────────────────────────────────────┐ +│ Update available 6.19.2 -> 7.3.0 │ +│ │ +│ This is a major update - please follow the guide at │ +│ https://pris.ly/d/major-version-upgrade │ +│ │ +│ Run the following to update │ +│ npm i --save-dev prisma@latest │ +│ npm i @prisma/client@latest │ +└─────────────────────────────────────────────────────────┘ + +zeus@MacBook-Air-de-Jamie node-homework % DATABASE_URL=postgresql://node_homework_owner@localhost/testtasklist?host=/tmp npx prisma migrate reset +Environment variables loaded from .env +Prisma schema loaded from prisma/schema.prisma +Datasource "db": PostgreSQL database "testtasklist", schema "public" at "localhost" + +✔ Are you sure you want to reset your database? All data will be lost. … yes + +Applying migration `20260206214630_first_migration` + +Database reset successful + +The following migration(s) have been applied: + +migrations/ + └─ 20260206214630_first_migration/ + └─ migration.sql + +✔ Generated Prisma Client (v6.19.2) to ./node_modules/@prisma/client in 80ms + +zeus@MacBook-Air-de-Jamie node-homework % \ No newline at end of file From 066e7be0d84deee5bc49fefca4fea7413577a26b Mon Sep 17 00:00:00 2001 From: Jamie Bort Date: Thu, 12 Feb 2026 16:52:33 -0500 Subject: [PATCH 3/7] Finish comments and updates to lesson/assingment 6. --- .prettierignore | 3 + assignments/06-intro-to-prisma.md | 52 ++++----- issue96-files/notes.md | 187 +++++------------------------- lessons/06-intro-to-prisma.md | 102 ++++++++-------- 4 files changed, 109 insertions(+), 235 deletions(-) create mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..5aa5997 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +* +!issue96-files/ +!issue96-files/** \ No newline at end of file diff --git a/assignments/06-intro-to-prisma.md b/assignments/06-intro-to-prisma.md index b3cbbb8..29383a4 100644 --- a/assignments/06-intro-to-prisma.md +++ b/assignments/06-intro-to-prisma.md @@ -10,14 +10,15 @@ ## Assignment Overview In this assignment, you will transform your existing PostgreSQL application (from Assignment 5) to use Prisma ORM instead of raw SQL queries. You'll gain better type safety, autocomplete, and maintainability while keeping the same functionality. -Be sure to create an assignment6 branch before you make any new changes. This branch should build on top of assignment5, so you create the assignment6 branch when assignment5 is the active branch. +Be sure to create an `assignment6` branch before you make any new changes. This branch should build on top of Assignment 5, so you create the `assignment6` branch when `assignment5` is the active branch. **Prologue:** -Right now you are using raw SQL queries with the `pg` library to interact with your PostgreSQL database. For this assignment, you want to replace all raw SQL queries with Prisma ORM methods, while maintaining the same functionality including password hashing and global user_id storage. The REST calls your application supports should still work the same way, so that your Postman tests don't need to change. +Right now, you are using raw SQL queries with the `pg` library to interact with your PostgreSQL database. For this assignment, you want to replace all raw SQL queries with Prisma ORM methods, while maintaining the same functionality including password hashing and global user_id storage. The REST calls your application supports should still work the same way, so that your Postman tests don't need to change. ## Prerequisites - Completed Assignment 5 with a working PostgreSQL application -- Basic understanding of database concepts and SQL +- Basic understanding of database concepts as well as SQL +- This assignment builds on Assignment 5. Make sure you have a working PostgreSQL application before adding Prisma ORM! --- @@ -99,7 +100,7 @@ model tasks { } ``` -Do you see how the model stanzas map to the SQL you used in part 1? Pay particular attention to the way the relation between tasks and users is specified. Also, notice the `@@unique`, which describes the additional index you need. The models above are ok ... but typically, you make them a little friendlier. By convention, the name of the model is capitalized. and it is singular, not plural. Also, the convention in JavaScript is that variable names are camel case. But if we change the models to match this convention, we have a problem. Prisma will look for tables named User and Task, and for columns like createdAt. We fix this by adding `@map` for columns, and `@@map` for tables. The final product is: +Do you see how the model stanzas map to the SQL you used in `Step 1a` above? Pay particular attention to the way the relation between tasks and users is specified. Also, notice the `@@unique`, which describes the additional index you need. The models above are ok ... but typically, you make them a little friendlier. By convention, the name of the model is capitalized. and it is singular, not plural. Also, the convention in JavaScript is that variable names are camel case. But if we change the models to match this convention, we have a problem. Prisma will look for tables named User and Task, and for columns like createdAt. We fix this by adding `@map` for columns, and `@@map` for tables. The final product is: ``` // This is your Prisma schema file @@ -138,7 +139,7 @@ model Task { #### c. Migration -You can create the schema following the pattern above. You first did the SQL commands to create the tables, then you introspected the schema, then you tweaked the names with mapping as needed. Most people find that this is the hard way. You can instead create the model definitions and use them to create or modify the table schema, using migrate. You do the following: +You can create the schema following the pattern above. You first did the SQL commands to create the tables, then you introspected the schema, then you tweaked the names with mapping as needed. Most people find that this is the hard way. Alternatively, you can instead create the model definitions and use them to create or modify the table schema, using `migrate`. You do the following: ```bash npx prisma migrate reset # answer yes when prompted. This deletes all the data. @@ -159,13 +160,13 @@ As you may make schema changes in the future, you also want Prisma to manage the DATABASE_URL= npx prisma migrate reset ``` -Here for `` you put in the value of that environment variable from your `.env` file. Because you are doing a reset, all the data in the test database is deleted with this command, but that's ok. It brings the test database into sync with the models and with the migration history of the dev database. +For ``, use the value of that environment variable from your `.env` file. Because you are doing a reset, all the data in the test database is deleted with this command, but that's ok. It brings the test database into sync with the models and with the migration history of the dev database. --- **Important:** You must run `npx prisma migrate dev --name ` every time you modify your Prisma schema file. The generated client needs to be updated to reflect any changes to your models, fields, or relationships. Every time you do a migration for the development database, you do it for the test database as well, with the command above. -From this point on, if you make a schema change, you change the model, do an `npx prisma migrate dev`, and then, for the test database, do the corresponding `npx prisma migrate deploy`. You do not change the schema with ordinary SQL. You'll use the `deploy` also with the production database you create for Internet deployment of your app in lesson 10. You never use a schema `reset` with the production database, for the obvious reason that it deletes all the data. +From this point on, if you make a schema change, first update the model, then run `npx prisma migrate dev`, and finally run the corresponding `npx prisma migrate deploy` for the test database. Do not change the schema with ordinary SQL. Use the `deploy` also with the production database you create for Internet deployment of your app in lesson 10. Never use a schema `reset` with the production database, for the obvious reason that it deletes all the data. ### 2. Create Prisma Database Connection @@ -187,7 +188,7 @@ const prisma = new PrismaClient(opts); module.exports = prisma; ``` -It can be a little opaque to figure out what an ORM like Prisma is doing. The code above turns on logging of the queries it issues. You'll actually see the SQL statements appear in the log as they are executed. Obviously this should only happen in development mode. +It can be a little opaque to figure out what an ORM such as Prisma is doing. The code above turns on logging of the queries it issues. You'll actually see the SQL statements appear in the log as they are executed. Obviously this should only happen in development mode. In the log, you'll see each of the table names prefixed with "public". This is the default database schema, which is only important if your database is multi-tenant -- which it isn't. @@ -221,7 +222,7 @@ app.get('/health', async (req, res) => { }); ``` -Also, you want to catch connection errors in your error handler, perhaps adding a statement to the top of your error handler like this: +Also, you should catch connection errors in your error handler, possibly adding a statement at the top like this: ```js if (err.name === "PrismaClientInitializationError") { @@ -229,7 +230,7 @@ if (err.name === "PrismaClientInitializationError") { } ``` -Once you've done this much, test the new health check to make sure it works. +Once you've done this, test the new health check to make sure it works. ### 3. Transform Your Controllers @@ -242,7 +243,7 @@ You need to have a `require()` statement for prisma in the user controller, in a ```js email = email.toLowerCase() // Joi validation always converts the email to lower case // but you don't want logon to fail if the user types mixed case -const user = await prisma.user.findUnique({ where: { email }}); +const user = await prisma.users.findUnique({ where: { email }}); // also Prisma findUnique can't do a case insensitive search ``` That may return null, in which case authentication fails. If not, you still have to do a `comparePassword()`, which may or may not return true. @@ -268,24 +269,24 @@ try { return next(err); // the error handler takes care of other errors } } -// otherwise register succeeded, so set global.user_id with user.id, and do the +// otherwise register succeeded, so set `global.user_id` with `user.id`, and do the // appropriate res.status().json(). ``` #### c. Fix the Task Index Method ```js -const tasks = await prisma.task.findMany({ +const tasks = await prisma.tasks.findMany({ where: { - userId: global.user_id, // only the tasks for this user! + user_id: global.user_id, // only the tasks for this user! }, - select: { title: true, isCompleted: true, id: true } + select: { id: true, title: true, is_completed: true} }); ``` #### d. Fix the Task Create Method -This one's kind of like register. You want to create the task with a userId of global.user_id. +This one is similar to register. You want to create the task with a `userId` of `global.user_id`. #### e. Fix Task Update @@ -293,7 +294,7 @@ This one's kind of like register. You want to create the task with a userId of // assuming that value contains the validated change coming back from Joi, and that // you have a valid req.params.id: try { - const task = await prisma.task.update({ + const task = await prisma.tasks.update({ data: value, where: { id, @@ -310,18 +311,18 @@ try { } ``` -With the pg package, you'd just get an empty array returned, if no matching task was found. But Prisma throws the `P2025` error in this case. You want to catch it at this point -- if you passed it to the global error handler, the caller would not get a useful message. +With the `pg` package, you'd simply get an empty array returned if no matching task was found. But Prisma throws the `P2025` error in this case. You want to catch it at this point -- if you passed it to the global error handler, the caller would not get a useful message. This is where that special unique index for [id, userId] is important! Prisma does not let you do update() or delete() or findUnique() with two attributes in the where clause **unless** a uniqueness index is present for that combination of attributes. #### f. Update the Show Method -You need to use `prisma.task.findUnique()`, but you filter both on the id and the userId, so that there is good access control. You need to catch `P2025` errors in this case also. +You need to use `prisma.tasks.findUnique()`, but you filter both on the id and the `userId`, so that there is good access control. If an object is not found, the method returns `null`. Make sure to address the case when that happens. #### g. Update DeleteTask -This works similar to update(). You need to use the delete() method, and catch `P2025` errors. +This works similarly to `update()`. You need to use the delete() method, and catch `P2025` errors. #### h. Remove All Pool References @@ -343,7 +344,7 @@ Make sure all operations work as before. They are: - logoff - health check -As you did for pg, conduct a test to verify that one user can't read, modify, or delete another's tasks. +As you did for `pg`, conduct a test to verify that one user cannot read, modify, or delete another user's tasks. Then, run `npm run tdd assignment6` and make sure it completes without test failure. @@ -385,8 +386,8 @@ project/ │ ├── prisma.js │ └── pg-pool.js (no longer used) ├── middleware (No changes needed for Prisma) -├── app.js -├── .env +├── app.js +├── .env └── package.json ``` @@ -499,7 +500,4 @@ Record a short video (3–5 minutes) on YouTube, Loom, or similar platform. Shar - Check your Prisma schema and database connection - Use Prisma Studio to visualize your database - Test each endpoint individually -- Ask for help if you get stuck on specific concepts - -**Remember:** This assignment builds on Assignment 5. Make sure you have a working PostgreSQL application before adding Prisma ORM! - +- Ask for help if you get stuck on specific concepts \ No newline at end of file diff --git a/issue96-files/notes.md b/issue96-files/notes.md index ddf59a8..fe10193 100644 --- a/issue96-files/notes.md +++ b/issue96-files/notes.md @@ -24,177 +24,54 @@ Two files are used for the 6th lesson/assignment. Meaning I'll be looking at The lesson file is well written - upon first read I didn't notice anything that should change. It flowed and appeared to be comprehensive. - +## Questions to address -## Proposed text changes +1. [Here](https://github.com/Code-the-Dream-School/node-essentials/blob/efd3026e9b84fa7578d3c74b26d8486444307c04/assignments/06-intro-to-prisma.md?plain=1#L204) it says `Then, change the shutdown so that as well as ending the pg pool, it also does the following:`. -Original -From this point on, if you make a schema change, you change the model, do an npx prisma migrate dev, and then, for the test database, do the corresponding npx prisma migrate deploy. + What exactly is "it also does the following:" referring to? Because immediately after that statement there are two lines of code and no explanation. -Proposed -From this point on, if you make a schema change, first change the model, next do an npx prisma migrate dev, last, do the corresponding npx prisma migrate deploy for the test database. + The code that follows the quoted statement above: -Original + ```javascript + await prisma.$disconnect(); + console.log("Prisma disconnected"); + ``` -You do not change the schema with ordinary SQL. You'll use the deploy also with the production database you create for Internet deployment of your app in lesson 10. You never use a schema reset with the production database, for the obvious reason that it deletes all the data. +## Notes to raise -TODO: make these suggestions in the node-homework repo. +1. I updated the instructions pertaining to "Update the Show Method" -TODO: Use commands rather than "You" all the time. + prisma.tasks.findUnique() does not throw a P2025 error when no record is found. It simply returns null. -``` -..., it also does the following: + The P2025 error only occurs with operations that modify data (update, delete, updateMany, etc.) when no matching record exists. -await prisma.$disconnect(); - console.log("Prisma disconnected"); -``` + Per the Prisma [documentation](https://www.prisma.io/docs/orm/reference/prisma-client-reference#findunique), "By default, both operations return null if the record is not found." -It does what??? These are commands, not an explanation. + It is also already addressed in the curriculum [lesson](https://github.com/Code-the-Dream-School/node-essentials/blob/0f0a113e0d7bd61bc17e96cf912b8ffa4be61358/lessons/06-intro-to-prisma.md?plain=1#L189). ---- +2. Multiple times I had to use `user_id` in place of `userId`. And `is_completed` in place of `isCompleted`. -For the register method in usercontroller: "b. Fix Register" + I THINK this is contrary to the instructions in the [assignment](https://github.com/Code-the-Dream-School/node-essentials/blob/main/assignments/06-intro-to-prisma.md). -Your schema: model users → Prisma client: prisma.users + I was able to successfully use the app via Postman. See my [controllers/taskController.js](https://github.com/JamieBort/node-homework/blob/assignment6/controllers/taskController.js) file. -Current code: prisma.user → undefined → TypeError +3. Every time we're instructed to use `await prisma.task.` in the [assignment](https://github.com/Code-the-Dream-School/node-essentials/blob/main/assignments/06-intro-to-prisma.md), I had to use `await prisma.tasks.` instead. -Fix: replace all prisma.user references with prisma.users + On account of my schema.prisma file had `tasks` rather than `task`: -and + ``` + model tasks { + id Int @id @default(autoincrement()) + title String @db.VarChar(255) + is_completed Boolean @default(false) + user_id Int + created_at DateTime @default(now()) @db.Timestamp(6) + users users @relation(fields: [user_id], references: [id], onDelete: NoAction, onUpdate: NoAction) -replace -res -.status(201) -.json({ name: result.rows[0].name, email: result.rows[0].email }); + @@unique([id, user_id], map: "task_id_user_id_unique") + } + ``` -with -res.status(201).json({ name: user.name, email: user.email, id: user.id }); + Likewise for `const user = await prisma.users.findUnique(` for the same reason. ---- - -for "Fix the Task Index Method" - -`const tasks = await prisma.task.findMany({` should be `const tasks = await prisma.tasks.findMany({` instead - ---- - -for "Fix Task Update" - -rather than - -``` -try { - const task = await prisma.task.update({ - data: value, - where: { - id, - userId: global.user_id, - }, - select: { title: true, isCompleted: true, id: true } - }); -} catch (err) { - if (err.code === "P2025" ) { - return res.status(404).json({ message: "The task was not found."}) - } else { - return next(err); // pass other errors to the global error handler - } -} -``` - ---- - -For "Update the Show Method" - -prisma.task.findUnique() does not throw a P2025 error when no record is found. It simply returns null. The P2025 error only occurs with operations that modify data (update, delete, updateMany, etc.) when no matching record exists. - -Per https://www.prisma.io/docs/orm/reference/prisma-client-reference#findunique, "By default, both operations return null if the record is not found." - - - -### Actions I took, in order - -1. First command - -``` -node-homework % npm install prisma @prisma/client - -added 24 packages, removed 1 package, changed 8 packages, and audited 575 packages in 41s - -106 packages are looking for funding - run `npm fund` for details - -found 0 vulnerabilities -``` - -2. Second command - -``` -node-homework % npx prisma init -Fetching latest updates for this subcommand... - -Initialized Prisma in your project - - prisma/ - schema.prisma - prisma.config.ts - -warn Prisma would have added DATABASE_URL but it already exists in .env -warn You already have a .gitignore file. Don't forget to add .env in it to not commit any private information. - -Next, choose how you want to set up your database: -CONNECT EXISTING DATABASE: - 1. Configure your DATABASE_URL in prisma.config.ts - 2. Run prisma db pull to introspect your database. -CREATE NEW DATABASE: - Local: npx prisma dev (runs Postgres locally in your terminal) - Cloud: npx create-db (creates a free Prisma Postgres database) - -Then, define your models in prisma/schema.prisma and run prisma migrate dev to apply your schema. -Learn more: https://pris.ly/getting-started -``` - -3. Third command `rm prisma.config.ts ` - -4. Fourth command `npx prisma generate` - -5. Fifth command - -``` -node-homework % npx prisma generate -Environment variables loaded from .env -Prisma schema loaded from prisma/schema.prisma - -✔ Generated Prisma Client (v6.19.2) to ./node_modules/@prisma/client in 139ms - -Start by importing your Prisma Client (See: https://pris.ly/d/importing-client) - -Tip: Interested in query caching in just a few lines of code? Try Accelerate today! https://pris.ly/tip-3-accelerate -``` - -6. Sixth command - -`npx prisma db pull` - -``` -node-homework % npx prisma db pull -Environment variables loaded from .env -Prisma schema loaded from prisma/schema.prisma -Datasource "db": PostgreSQL database "tasklist", schema "public" at "localhost" - -✔ Introspected 2 models and wrote them into prisma/schema.prisma in 229ms - -Run prisma generate to generate Prisma Client. -┌─────────────────────────────────────────────────────────┐ -│ Update available 6.19.2 -> 7.3.0 │ -│ │ -│ This is a major update - please follow the guide at │ -│ https://pris.ly/d/major-version-upgrade │ -│ │ -│ Run the following to update │ -│ npm i --save-dev prisma@latest │ -│ npm i @prisma/client@latest │ -└─────────────────────────────────────────────────────────┘ - -zeus@MacBook-Air-de-Jamie node-homework % -``` + For what it is worth, the instructions to create the SQL database is found [here](https://github.com/Code-the-Dream-School/node-essentials/blob/0f0a113e0d7bd61bc17e96cf912b8ffa4be61358/assignments/05-intro-to-sql-and-postgresql.md?plain=1#L158) in the repo (in Assignment 5). There the tables `users` and `tasks`. diff --git a/lessons/06-intro-to-prisma.md b/lessons/06-intro-to-prisma.md index 49b6f44..b93ae23 100644 --- a/lessons/06-intro-to-prisma.md +++ b/lessons/06-intro-to-prisma.md @@ -2,13 +2,13 @@ ## **Lesson Overview** -You have learned to use SQL for CRUD operations in your app. Often, though, that's not how apps are built. This lesson will describe an alternative. You use an SQL database, but you access the database with an Object-Relational Mapper -- an ORM. The lesson explains why this approach can speed development, but also its limitations. The lessons also explain the steps needed to convert your app to the use of the Prisma ORM. You'll do that conversion in the assignment. +You have learned to use SQL for CRUD operations in your app. Often, though, that's not how apps are built. This lesson will describe an alternative. You use an SQL database, but you access the database with an Object-Relational Mapper -- an ORM. The lesson explains why this approach can speed development, but also its limitations. The lesson also explains the steps needed to convert your app to use the Prisma ORM. You'll do that conversion in the assignment. ## **Learning Objectives** You will learn: - What object-relational mappings (ORMs) are -- Why ORMs are used. +- Why ORMs are used - Characteristics of the Prisma ORM - How to set up Prisma in your project - How to use Prisma to manage the schema @@ -25,7 +25,7 @@ You will learn: 6. Prisma methods for database operations 7. Testing and debugging -## **1. What is an ORM, and why are they used?** +## 1. What is an ORM, and why are they used? SQL is a powerful language, but it isn't pretty. In modern languages, you have objects, which may belong to classes. You can create new instances with `new` operations, you can pass the objects as arguments to methods, and you can modify their attributes. With an ORM, you can operate on database entries as if they were objects, which can be more straightforward than writing SQL. Within your programming environment, you get autocomplete support and other programming assistance. @@ -33,7 +33,7 @@ In addition, ORMs have certain inherent advantages: 1. You have learned the `pg` package, but it only talks to PostgreSQL. Suppose you are converting to MySQL, or for that matter, to MongoDB? You'd have to learn an entirely different package, with different syntax. An ORM can handle the differences more or less transparently, so that it is not necessary to make big changes to the code. (Converting from SQL to MongoDB is not transparent, but the ORM you will use supports both.) -2. Database schema management is complicated, especially with team projects. As you add and modify tables, how do you keep track of what has been done to the production database and to the various test and development database instances? You more or less have to write a special program for the SQL operations involved, and then you have to keep track of the steps in a separate table. The ORM can do this for you. +2. Database schema management is complicated, especially with team projects. As you add and modify tables, how do you keep track of what has been done to the production database and to the various test and development database instances? You more or less need to write a special program for the SQL operations involved, and then you have to keep track of the steps in a separate table. The ORM can do this for you. 3. The Prisma ORM brings special advantages to a TypeScript environment. We don't do TypeScript in this class, but with Prisma, one gets strong typing and type safety. @@ -45,7 +45,7 @@ On the other hand: 2. Sometimes the ORM won't do the SQL you want. There's an escape route: You can tell it to emit raw SQL, as if you were using the `pg` package. Sometimes you'll need to do that -- so you still need to know SQL. -## **2. Characteristics of the Prisma ORM** +## 2. Characteristics of the Prisma ORM The Prisma ORM: - has an elegant way of managing schema. @@ -55,9 +55,9 @@ The Prisma ORM: - has significant limitations for GROUP BY and HAVING support. - won't do subqueries. -We could have used Sequelize, another ORM for Node, but it's harder to learn, and schema management with Sequelize requires an additional package. As you'll see, the transition from `pg` to Prisma is pretty easy. +We could have used Sequelize, another ORM for Node, but it's harder to learn, and schema management with Sequelize requires an additional package. As you'll see, the transition from using the `pg` dependency to Prisma is pretty easy. -### **How it Works** +## 3. How it Works Instead of writing: ```js @@ -66,12 +66,12 @@ const results = await pool.query(`SELECT * FROM users WHERE email = 'john@exampl You write: ```javascript -const user = await prisma.user.findUnique({ +const user = await prisma.users.findUnique({ where: { email: 'john@example.com' } }); ``` -Under the covers, Prisma makes the SQL call. In fact, if you are using PostgreSQL, it uses the pg package and a pg pool. +Under the covers, Prisma makes the SQL call. In fact, if you are using PostgreSQL, it uses the `pg` package and a `pg` pool. Prisma consists of three main tools: @@ -79,7 +79,7 @@ Prisma consists of three main tools: 2. **Prisma Client**: An auto-generated, type-safe database client 3. **Prisma Migrate**: Database migration and schema management -## **3. Workflow for adding Prisma support to your app** +## 4. Workflow for adding Prisma support to your app ``` 1. Define Schema → 2. Generate Client → 3. Use in Code → 4. Database Operations @@ -101,7 +101,7 @@ Prisma consists of three main tools: - Prisma translates your method calls to optimized SQL - Handles connections, transactions, and error handling -## **4. Managing the database schema with Prisma** +## 5. Managing the database schema with Prisma ### **Elements of the Prisma Schema** @@ -134,7 +134,7 @@ model User { } ``` -Each model has a name, a collection of fields, perhaps one or several indexes, and perhaps a `@@map` clause. By convention, the model is given a capitalized singular name. As we typically use lowercase table names, the `@@map` clause mapes the model name to the table name. +Each model has a name, a collection of fields, and may include one or more indexes or a `@@map` clause. By convention, the model is given a capitalized singular name. As we typically use lowercase table names, the `@@map` clause maps the model name to the table name. The `@@unique` line declares an index. It is saying that the id and the userId comprise a unique composite key. @@ -172,9 +172,9 @@ The Prisma schema describes the database schema. There are two cases to conside In the assignment, you will do each of these. -Once the Prisma and database schemas have been created by one of the processes above, it may be necessary to modify the schema, perhaps to add tables or to add or remove columns from tables. In this case, the Prisma schema is changed, and the migration step is performed again. Every change to the Prisma schema requires that you run migration again. As the Prisma schema is just a file, it can be shared within a development team via Github, and it can be propagated from Github to the production deployment. +Once the Prisma and database schemas have been created by one of the processes above, it may be necessary to modify the schema, perhaps to add tables or to add or remove columns from tables. In this case, the Prisma schema is changed, and the migration step is performed again. Every change to the Prisma schema requires that you run the migration again. As the Prisma schema is just a file, it can be shared within a development team via Github, and it can be propagated from Github to the production deployment. -## **5. Error Handling with Prisma** +## 6. Error Handling with Prisma ### **Prisma Error Types** @@ -195,33 +195,33 @@ The code below is an example. More frequently, you will only catch a small subs ```javascript try { - const user = await prisma.user.create({ + const user = await prisma.users.create({ data: { email, name, password } // password should be hashed with scrypt }); res.json(user); } catch (error) { if (error.code === 'P2002') { - return res.status(400).json({ - error: "User with this email already exists" + return res.status(400).json({ + error: "User with this email already exists" }); } - - if (error.code === 'P2025') { - return res.status(404).json({ - error: "Record not found" + + if (error.code === 'P2025') { + return res.status(404).json({ + error: "Record not found" }); } - + if (error.code === 'P2003') { // might happen if you tried to create a task with // no corresponding user - return res.status(400).json({ - error: "Invalid reference - related record does not exist" + return res.status(400).json({ + error: "Invalid reference - related record does not exist" }); } - + console.error('Prisma error:', error); - res.status(500).json({ - error: "Internal server error" + res.status(500).json({ + error: "Internal server error" }); } ``` @@ -233,7 +233,7 @@ Prisma throws a `PrismaClientInitializationError` when it cannot connect to the ```javascript app.use((err, req, res, next) => { console.error('Error occurred:', err.message); - + // Handle database connection failures if (err.name === "PrismaClientInitializationError") { console.log("Couldn't connect to the database. Is it running?"); @@ -256,7 +256,7 @@ app.use((err, req, res, next) => { ```javascript let updatedUser = null; try { - updatedUser = await prisma.user.update({ + updatedUser = await prisma.users.update({ where: { id: parseInt(userId) }, data: { name: newName } }); @@ -270,15 +270,13 @@ try { else ... // it succeeded! ``` -As previously mentioned, not all errors should be handled in the context of the controllers. That would be redundant. Some the errors should be handled in context, though. For example, if a user is registering, and the `P2002` error occurs, that is best handled in context, so that good feedback can be returned to the caller. - ---- +As previously mentioned, not all errors should be handled in the context of the controllers. That would be redundant. Some errors should be handled in context, though. For example, if a user is registering, and the `P2002` error occurs, that is best handled in context, so that good feedback can be returned to the caller. -## 6. Performance and Best Practices +## 7. Performance and Best Practices ### Connection Management -All connection management within your app should be centralized, just as it was with the pg package. You create a shared module within your `db` folder to establish the client, and the resulting client is imported by other modules in your app. This ensures that all connections can be ended at server shutdown, and also optimizes connection sharing. +All connection management within your app should be centralized, just as it was with the `pg` package. You create a shared module within your `db` folder to establish the client, and the resulting client is imported by other modules in your app. This ensures that all connections can be ended at server shutdown, and also optimizes connection sharing. ```javascript const prisma = new PrismaClient(); @@ -294,7 +292,7 @@ Specific instructions on the location of these lines will be given during your a **Important:** Always call `await prisma.$disconnect()` when shutting down your application or in tests to close database connections cleanly and prevent connection leaks. -## **7. Prisma Methods for Database Operations** +## 8. Prisma Methods for Database Operations In your assignment, you will substitute Prisma methods for methods from the pg package. The following link shows the syntax of the Prisma methods for [CRUD operations](https://www.prisma.io/docs/orm/prisma-client/queries/crud). You see the following correspondence with SQL statements: @@ -303,27 +301,27 @@ In your assignment, you will substitute Prisma methods for methods from the pg p - UPDATE: `prisma.model.update()`, `prisma.model.updateMany()` - DELETE: `prisma.model.delete()`, `prisma.model.deleteMany()` -This is not an exhaustive list. If the model is User, which is mapped to a users table, you can do `prisma.user.create({data: {name: "Jack"}})` to create an entry. Of course, this example wouldn't be schema compliant. Many of these methods have a `where` attribute to specify which entries in teh database are to be read or modified or deleted. Methods for creating and modifying records have a `data` attribute to specify the attribute names and values. When retrieving data, you can specify the columns you want with a `select` attribute. There are various other choices such as `orderBy` and `groupBy`, which correspond to SQL features you have seen before. +This is not an exhaustive list. If the model is User, which is mapped to a users table, you can do `prisma.users.create({data: {name: "Jack"}})` to create an entry. Of course, this example wouldn't be schema compliant. Many of these methods have a `where` attribute to specify which entries in the database are to be read or modified or deleted. Methods for creating and modifying records have a `data` attribute to specify the attribute names and values. When retrieving data, you can specify the columns you want with a `select` attribute. There are various other choices such as `orderBy` and `groupBy`, which correspond to SQL features you have seen before. -In your assignment, you are given specific guidance and examples to complete the conversion from pg to Prisma. Refer to the link above as needed. +In your assignment, you are given specific guidance and examples to complete the conversion from using the `pg` dependency to Prisma. Refer to the link above as needed. -All of these methods are asynchronous, returning a promise. You must do an `await` to get the return value. +All of these methods are asynchronous and return a promise. You must do an `await` to get the return value. ### **Query Optimization** **Select Only Needed Fields:** ```javascript // Instead of fetching all fields -const user = await prisma.user.findUnique({ where: { id: 1 } }); +const user = await prisma.users.findUnique({ where: { id: 1 } }); // Select only what you need -const user = await prisma.user.findUnique({ +const user = await prisma.users.findUnique({ where: { id: 1 }, select: { id: true, name: true, email: true - // password is excluded. You could also do omit: { hashed_password : true} + // password is excluded. You could also do `omit: { hashed_password : true}` } }); ``` @@ -331,38 +329,36 @@ const user = await prisma.user.findUnique({ **Use Appropriate Methods:** ```javascript // For single records -const user = await prisma.user.findUnique({ where: { email } }); -// This only works if the schema specifies that emails are unique. +const user = await prisma.users.findUnique({ where: { email } }); +// This method only works if the schema specifies that emails are unique. // For multiple records -const users = await prisma.user.findMany({ where: { active: true } }); +const users = await prisma.users.findMany({ where: { active: true } }); // For existence checks -const exists = await prisma.user.findFirst({ where: { email } }); +const exists = await prisma.users.findFirst({ where: { email } }); ``` ### Transaction Support ```javascript // Multiple operations in a single transaction const result = await prisma.$transaction(async (tx) => { - const user = await tx.user.create({ + const user = await tx.users.create({ data: { email, name, password } // password should be hashed with scrypt }); - - const task = await tx.task.create({ + + const task = await tx.tasks.create({ data: { title: "Welcome task", - userId: user.id + userId: users.id } }); - + return { user, task }; }); ``` ---- - -## 7. Testing and Debugging +## 9. Testing and Debugging ### Prisma Studio Prisma provides a visual database browser: From 0ac6b8f771242f8ac0cc408cc9ddb88270d5dfe3 Mon Sep 17 00:00:00 2001 From: Jamie Bort Date: Thu, 12 Feb 2026 17:21:19 -0500 Subject: [PATCH 4/7] Finish comments and updates to lesson/assingment 6. --- issue96-files/{notes.md => issue96-notes.md} | 30 +++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) rename issue96-files/{notes.md => issue96-notes.md} (81%) diff --git a/issue96-files/notes.md b/issue96-files/issue96-notes.md similarity index 81% rename from issue96-files/notes.md rename to issue96-files/issue96-notes.md index fe10193..ea52acf 100644 --- a/issue96-files/notes.md +++ b/issue96-files/issue96-notes.md @@ -11,8 +11,6 @@ This is a file created to make note of things as they pertain to the https://git - If sample answers exist in the mentor guidebook, test them out to confirm everything runs correctly. - Note any issues, confusing sections, or areas that may need improvement, and provide feedback or suggested fixes in the comments. -## Scope of review - ## Resources used Two files are used for the 6th lesson/assignment. Meaning I'll be looking at @@ -20,10 +18,6 @@ Two files are used for the 6th lesson/assignment. Meaning I'll be looking at - The lesson file: https://github.com/Code-the-Dream-School/node-essentials/blob/main/lessons/06-intro-to-prisma.md - The assignment file: https://github.com/Code-the-Dream-School/node-essentials/blob/main/assignments/06-intro-to-prisma.md -## Notes - -The lesson file is well written - upon first read I didn't notice anything that should change. It flowed and appeared to be comprehensive. - ## Questions to address 1. [Here](https://github.com/Code-the-Dream-School/node-essentials/blob/efd3026e9b84fa7578d3c74b26d8486444307c04/assignments/06-intro-to-prisma.md?plain=1#L204) it says `Then, change the shutdown so that as well as ending the pg pool, it also does the following:`. @@ -37,9 +31,25 @@ The lesson file is well written - upon first read I didn't notice anything that console.log("Prisma disconnected"); ``` -## Notes to raise +## Notes about the files I reviewed + +1. The lesson and assignment files are very well written. + + It flowed and appears to be comprehensive. + + For the most part my edits are solely formatting and a few rephrasing changes. + + The changes that were coding in nature are highlighted below. + +2. I did not test the assignment. I believe I didn't create the files in the correct directory. + + So when I ran `npm run tdd assignment6`, the TDD tests did not run. I attempted to modify the command. + + And I attempted to move the files into the `assignment6` directory. But to no avail. + + If someone cares to instruct me on how I should restructure the directories, I'd be happy to run the tests. -1. I updated the instructions pertaining to "Update the Show Method" +3. I updated the instructions pertaining to "Update the Show Method" prisma.tasks.findUnique() does not throw a P2025 error when no record is found. It simply returns null. @@ -49,13 +59,13 @@ The lesson file is well written - upon first read I didn't notice anything that It is also already addressed in the curriculum [lesson](https://github.com/Code-the-Dream-School/node-essentials/blob/0f0a113e0d7bd61bc17e96cf912b8ffa4be61358/lessons/06-intro-to-prisma.md?plain=1#L189). -2. Multiple times I had to use `user_id` in place of `userId`. And `is_completed` in place of `isCompleted`. +4. Multiple times I had to use `user_id` in place of `userId`. And `is_completed` in place of `isCompleted`. I THINK this is contrary to the instructions in the [assignment](https://github.com/Code-the-Dream-School/node-essentials/blob/main/assignments/06-intro-to-prisma.md). I was able to successfully use the app via Postman. See my [controllers/taskController.js](https://github.com/JamieBort/node-homework/blob/assignment6/controllers/taskController.js) file. -3. Every time we're instructed to use `await prisma.task.` in the [assignment](https://github.com/Code-the-Dream-School/node-essentials/blob/main/assignments/06-intro-to-prisma.md), I had to use `await prisma.tasks.` instead. +5. Every time we're instructed to use `await prisma.task.` in the [assignment](https://github.com/Code-the-Dream-School/node-essentials/blob/main/assignments/06-intro-to-prisma.md), I had to use `await prisma.tasks.` instead. On account of my schema.prisma file had `tasks` rather than `task`: From f1c865883ebbbb65e4a07e5a980e2ea11c6d0fed Mon Sep 17 00:00:00 2001 From: Jamie Bort Date: Fri, 13 Feb 2026 08:15:59 -0500 Subject: [PATCH 5/7] Remove personal notes from PR and ignore locally --- issue96-files/README.md | 23 -- issue96-files/issue96-notes.md | 87 ----- issue96-files/semi-complete-output.txt | 473 ------------------------- 3 files changed, 583 deletions(-) delete mode 100644 issue96-files/README.md delete mode 100644 issue96-files/issue96-notes.md delete mode 100644 issue96-files/semi-complete-output.txt diff --git a/issue96-files/README.md b/issue96-files/README.md deleted file mode 100644 index 5f30ab3..0000000 --- a/issue96-files/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# issue96-files - -## Purpose of this directory - -This directory is strictly for organizing my notes and thoughts; which will be used for the [Review, test and evaluate Week 6](https://github.com/Code-the-Dream-School/node-essentials/issues/96) GitHub Issue. I created this directory - -1. ~~to keep track of where I had left off for the day~~ and - -2. to make any notes relevant to my completing the assignment and - -3. to make any notes to help me understand the content better. - -~~All that to say, this directory and its contents can be discarded.~~ - -## Explanation of files - - - -./issue96-files/semi-complete-output.txt - the Terminal output from using Git and from using the commands in the assignment. This was documented for my own sake in case I needed to revisit it. It can be discarded and/or ignored. - -./issue96-files/notes.md - The file I kept to document my thoughts as I worked on the Issue. Again, this file can be discarded and/or ignored. - -./issue96-files/README.md - Created to explain the reason for this issue96-files/ directory. This file can be discarded and/or ignored. diff --git a/issue96-files/issue96-notes.md b/issue96-files/issue96-notes.md deleted file mode 100644 index ea52acf..0000000 --- a/issue96-files/issue96-notes.md +++ /dev/null @@ -1,87 +0,0 @@ -# Notes for Lesson/Assignment 6 - -## About this file - -This is a file created to make note of things as they pertain to the https://github.com/Code-the-Dream-School/node-essentials/issues/96 Issue, which was created for the 6th lesson. More specifically it was created to "review, test, and evaluate Lesson/Assignment 6 for accuracy and clarity." - -## Specific instructions - -- Make sure all examples and instructions work as expected. -- If sample answers are not available, please create and submit them. -- If sample answers exist in the mentor guidebook, test them out to confirm everything runs correctly. -- Note any issues, confusing sections, or areas that may need improvement, and provide feedback or suggested fixes in the comments. - -## Resources used - -Two files are used for the 6th lesson/assignment. Meaning I'll be looking at - -- The lesson file: https://github.com/Code-the-Dream-School/node-essentials/blob/main/lessons/06-intro-to-prisma.md -- The assignment file: https://github.com/Code-the-Dream-School/node-essentials/blob/main/assignments/06-intro-to-prisma.md - -## Questions to address - -1. [Here](https://github.com/Code-the-Dream-School/node-essentials/blob/efd3026e9b84fa7578d3c74b26d8486444307c04/assignments/06-intro-to-prisma.md?plain=1#L204) it says `Then, change the shutdown so that as well as ending the pg pool, it also does the following:`. - - What exactly is "it also does the following:" referring to? Because immediately after that statement there are two lines of code and no explanation. - - The code that follows the quoted statement above: - - ```javascript - await prisma.$disconnect(); - console.log("Prisma disconnected"); - ``` - -## Notes about the files I reviewed - -1. The lesson and assignment files are very well written. - - It flowed and appears to be comprehensive. - - For the most part my edits are solely formatting and a few rephrasing changes. - - The changes that were coding in nature are highlighted below. - -2. I did not test the assignment. I believe I didn't create the files in the correct directory. - - So when I ran `npm run tdd assignment6`, the TDD tests did not run. I attempted to modify the command. - - And I attempted to move the files into the `assignment6` directory. But to no avail. - - If someone cares to instruct me on how I should restructure the directories, I'd be happy to run the tests. - -3. I updated the instructions pertaining to "Update the Show Method" - - prisma.tasks.findUnique() does not throw a P2025 error when no record is found. It simply returns null. - - The P2025 error only occurs with operations that modify data (update, delete, updateMany, etc.) when no matching record exists. - - Per the Prisma [documentation](https://www.prisma.io/docs/orm/reference/prisma-client-reference#findunique), "By default, both operations return null if the record is not found." - - It is also already addressed in the curriculum [lesson](https://github.com/Code-the-Dream-School/node-essentials/blob/0f0a113e0d7bd61bc17e96cf912b8ffa4be61358/lessons/06-intro-to-prisma.md?plain=1#L189). - -4. Multiple times I had to use `user_id` in place of `userId`. And `is_completed` in place of `isCompleted`. - - I THINK this is contrary to the instructions in the [assignment](https://github.com/Code-the-Dream-School/node-essentials/blob/main/assignments/06-intro-to-prisma.md). - - I was able to successfully use the app via Postman. See my [controllers/taskController.js](https://github.com/JamieBort/node-homework/blob/assignment6/controllers/taskController.js) file. - -5. Every time we're instructed to use `await prisma.task.` in the [assignment](https://github.com/Code-the-Dream-School/node-essentials/blob/main/assignments/06-intro-to-prisma.md), I had to use `await prisma.tasks.` instead. - - On account of my schema.prisma file had `tasks` rather than `task`: - - ``` - model tasks { - id Int @id @default(autoincrement()) - title String @db.VarChar(255) - is_completed Boolean @default(false) - user_id Int - created_at DateTime @default(now()) @db.Timestamp(6) - users users @relation(fields: [user_id], references: [id], onDelete: NoAction, onUpdate: NoAction) - - @@unique([id, user_id], map: "task_id_user_id_unique") - } - ``` - - Likewise for `const user = await prisma.users.findUnique(` for the same reason. - - For what it is worth, the instructions to create the SQL database is found [here](https://github.com/Code-the-Dream-School/node-essentials/blob/0f0a113e0d7bd61bc17e96cf912b8ffa4be61358/assignments/05-intro-to-sql-and-postgresql.md?plain=1#L158) in the repo (in Assignment 5). There the tables `users` and `tasks`. diff --git a/issue96-files/semi-complete-output.txt b/issue96-files/semi-complete-output.txt deleted file mode 100644 index dbcb676..0000000 --- a/issue96-files/semi-complete-output.txt +++ /dev/null @@ -1,473 +0,0 @@ -TODO: delete this file. - -zeus@MacBook-Air-de-Jamie node-homework % git status -On branch assignment5 -nothing to commit, working tree clean -zeus@MacBook-Air-de-Jamie node-homework % npm install pg dotenv - -added 34 packages, removed 2 packages, changed 6 packages, and audited 551 packages in 3s - -102 packages are looking for funding - run `npm fund` for details - -1 high severity vulnerability - -To address all issues, run: - npm audit fix - -Run `npm audit` for details. -zeus@MacBook-Air-de-Jamie node-homework % npm audit -# npm audit report - -qs <6.14.1 -Severity: high -qs's arrayLimit bypass in its bracket notation allows DoS via memory exhaustion - https://github.com/advisories/GHSA-6rw7-vpxm-498p -fix available via `npm audit fix` -node_modules/qs - -1 high severity vulnerability - -To address all issues, run: - npm audit fix -zeus@MacBook-Air-de-Jamie node-homework % npm audit fix - -changed 1 package, and audited 551 packages in 2s - -102 packages are looking for funding - run `npm fund` for details - -found 0 vulnerabilities -zeus@MacBook-Air-de-Jamie node-homework % git status -On branch assignment5 -Changes not staged for commit: - (use "git add ..." to update what will be committed) - (use "git restore ..." to discard changes in working directory) - modified: package-lock.json - modified: package.json - -no changes added to commit (use "git add" and/or "git commit -a") -zeus@MacBook-Air-de-Jamie node-homework % psql --version -psql (PostgreSQL) 14.20 (Homebrew) -zeus@MacBook-Air-de-Jamie node-homework % brew services list -✔︎ JSON API cask_tap_migrations.jws.json [Downloaded 2.4KB/ 2.4KB] -✔︎ JSON API cask.jws.json [Downloaded 15.3MB/ 15.3MB] -✔︎ JSON API formula.jws.json [Downloaded 32.0MB/ 32.0MB] -✔︎ JSON API formula_tap_migrations.jws.json [Downloaded 1.9KB/ 1.9KB] -Name Status User File -postgresql@14 started zeus ~/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist -zeus@MacBook-Air-de-Jamie node-homework % brew services start postgresql@14 -Service `postgresql@14` already started, use `brew services restart postgresql@14` to restart. -zeus@MacBook-Air-de-Jamie node-homework % brew services list -Name Status User File -postgresql@14 started zeus ~/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist -zeus@MacBook-Air-de-Jamie node-homework % ls -l -total 440 --rw-r--r-- 1 zeus staff 1071 Dec 15 11:51 LICENSE --rw-r--r--@ 1 zeus staff 14186 Dec 29 17:47 README.md --rw-r--r--@ 1 zeus staff 2037 Jan 29 17:13 app.js -drwxr-xr-x 10 zeus staff 320 Dec 15 11:51 assignment1 -drwxr-xr-x 3 zeus staff 96 Dec 15 11:51 assignment2 -drwxr-xr-x 4 zeus staff 128 Jan 29 17:13 assignment5 -drwxr-xr-x 3 zeus staff 96 Dec 15 11:51 class-utils -drwxr-xr-x@ 4 zeus staff 128 Jan 29 17:13 controllers -drwxr-xr-x 7 zeus staff 224 Dec 15 11:51 csv -drwxr-xr-x@ 3 zeus staff 96 Jan 29 17:13 db --rw-r--r-- 1 zeus staff 421 Dec 15 11:51 eslint.config.js -drwxr-xr-x 4 zeus staff 128 Dec 15 11:51 lesson9TDD --rw-r--r-- 1 zeus staff 5015 Dec 15 11:51 load-db.js -drwxr-xr-x@ 5 zeus staff 160 Jan 29 17:13 middleware --rw-r--r--@ 1 zeus staff 60 Jan 29 17:13 node-homework.code-workspace -drwxr-xr-x 393 zeus staff 12576 Jan 30 11:33 node_modules --rw-r--r--@ 1 zeus staff 162994 Jan 30 11:33 package-lock.json --rw-r--r--@ 1 zeus staff 1293 Jan 30 11:25 package.json --rw-r--r-- 1 zeus staff 1 Dec 15 11:51 project-links.txt -drwxr-xr-x@ 4 zeus staff 128 Jan 29 17:13 routes --rw-r--r--@ 1 zeus staff 682 Jan 29 17:13 schema.sql --rw-r--r-- 1 zeus staff 2884 Dec 15 11:51 sqlcommand.js -drwxr-xr-x 14 zeus staff 448 Jan 29 17:13 tdd --rwxr-xr-x@ 1 zeus staff 184 Jan 29 17:13 tdd.sh -drwxr-xr-x@ 11 zeus staff 352 Jan 29 17:13 validation -drwxr-xr-x 6 zeus staff 192 Dec 15 11:51 week-3-middleware -zeus@MacBook-Air-de-Jamie node-homework % psql "postgresql://node_homework_owner@localhost/tasklist?host=/tmp" -f schema.sql -psql:schema.sql:9: NOTICE: relation "users" already exists, skipping -CREATE TABLE -psql:schema.sql:19: NOTICE: relation "tasks" already exists, skipping -CREATE TABLE -zeus@MacBook-Air-de-Jamie node-homework % postgresql://node_homework_owner@localhost/testtasklist?host=/tmp -zeus@MacBook-Air-de-Jamie node-homework % psql "postgresql://node_homework_owner@localhost/testtasklist?host=/tmp" -f schema.sql -psql:schema.sql:9: NOTICE: relation "users" already exists, skipping -CREATE TABLE -psql:schema.sql:19: NOTICE: relation "tasks" already exists, skipping -CREATE TABLE -zeus@MacBook-Air-de-Jamie node-homework % git status -On branch assignment5 -Changes not staged for commit: - (use "git add ..." to update what will be committed) - (use "git restore ..." to discard changes in working directory) - modified: package-lock.json - modified: package.json - -no changes added to commit (use "git add" and/or "git commit -a") -zeus@MacBook-Air-de-Jamie node-homework % - * History restored - -zeus@MacBook-Air-de-Jamie node-homework % npm dev -Unknown command: "dev" - - -Did you mean this? - npm run dev # run the "dev" package script -To see a list of supported npm commands, run: - npm help -zeus@MacBook-Air-de-Jamie node-homework % npm run dev - -> node-homework@1.0.0 dev -> nodemon app.js - -[nodemon] 3.1.10 -[nodemon] to restart at any time, enter `rs` -[nodemon] watching path(s): *.* -[nodemon] watching extensions: js,mjs,cjs,json -[nodemon] starting `node app.js` -Server is listening on port 3000... -Internal server error: DatabaseError {"name":"error","message":"null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint","stack":"error: null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint\n at /Users/zeus/Documents/development/node-homework/node_modules/pg-pool/index.js:45:11\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async exports.create (/Users/zeus/Documents/development/node-homework/controllers/taskController.js:43:15)"} -Internal server error: DatabaseError {"name":"error","message":"null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint","stack":"error: null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint\n at /Users/zeus/Documents/development/node-homework/node_modules/pg-pool/index.js:45:11\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async exports.create (/Users/zeus/Documents/development/node-homework/controllers/taskController.js:43:15)"} -Internal server error: DatabaseError {"name":"error","message":"null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint","stack":"error: null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint\n at /Users/zeus/Documents/development/node-homework/node_modules/pg-pool/index.js:45:11\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async exports.create (/Users/zeus/Documents/development/node-homework/controllers/taskController.js:43:15)"} -[nodemon] restarting due to changes... -[nodemon] starting `node app.js` -Server is listening on port 3000... -[nodemon] restarting due to changes... -[nodemon] starting `node app.js` -Server is listening on port 3000... -Internal server error: DatabaseError {"name":"error","message":"null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint","stack":"error: null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint\n at /Users/zeus/Documents/development/node-homework/node_modules/pg-pool/index.js:45:11\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async exports.create (/Users/zeus/Documents/development/node-homework/controllers/taskController.js:45:15)"} -[nodemon] restarting due to changes... -[nodemon] starting `node app.js` -Server is listening on port 3000... -global.user_id = 1 -Internal server error: DatabaseError {"name":"error","message":"null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint","stack":"error: null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint\n at /Users/zeus/Documents/development/node-homework/node_modules/pg-pool/index.js:45:11\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async exports.create (/Users/zeus/Documents/development/node-homework/controllers/taskController.js:45:15)"} -[nodemon] restarting due to changes... -[nodemon] starting `node app.js` -Server is listening on port 3000... -[nodemon] restarting due to changes... -[nodemon] starting `node app.js` -Server is listening on port 3000... -[nodemon] restarting due to changes... -[nodemon] starting `node app.js` -Server is listening on port 3000... -auth middleware, global.user_id = undefined -auth middleware, global.user_id = 1 -auth middleware, global.user_id = 1 -global.user_id = 1 -auth middleware, global.user_id = 1 -global.user_id = 1 -Internal server error: DatabaseError {"name":"error","message":"null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint","stack":"error: null value in column \"is_completed\" of relation \"tasks\" violates not-null constraint\n at /Users/zeus/Documents/development/node-homework/node_modules/pg-pool/index.js:45:11\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async exports.create (/Users/zeus/Documents/development/node-homework/controllers/taskController.js:45:15)"} -[nodemon] restarting due to changes... -[nodemon] starting `node app.js` -Server is listening on port 3000... -auth middleware, global.user_id = undefined -[nodemon] restarting due to changes... -[nodemon] starting `node app.js` -Server is listening on port 3000... -[nodemon] restarting due to changes... -[nodemon] starting `node app.js` -Server is listening on port 3000... -auth middleware, global.user_id = 1 -auth middleware, global.user_id = 1 -global.user_id = 1 -auth middleware, global.user_id = 1 -global.user_id = 1 -auth middleware, global.user_id = 1 -[nodemon] restarting due to changes... -[nodemon] starting `node app.js` -Server is listening on port 3000... -auth middleware, global.user_id = undefined -auth middleware, global.user_id = undefined -auth middleware, global.user_id = 1 -auth middleware, global.user_id = 1 -auth middleware, global.user_id = 1 -auth middleware, global.user_id = 1 -^CShutting down gracefully... -HTTP server closed. -Exiting process... - -zeus@MacBook-Air-de-Jamie node-homework % npm run tdd assignment5 - -> node-homework@1.0.0 tdd -> ./tdd.sh assignment5 - -[napi-postinstall@0.3.0] Trying to install package "@unrs/resolver-binding-darwin-arm64" using npm -● Validation Error: - - Module /Users/zeus/Documents/development/node-homework/node_modules/jest-circus/build/runner.js in the testRunner option was not found. - is: /Users/zeus/Documents/development/node-homework - - Configuration Documentation: - https://jestjs.io/docs/configuration - -zeus@MacBook-Air-de-Jamie node-homework % npm run tdd assignment5b - -> node-homework@1.0.0 tdd -> ./tdd.sh assignment5b - - console.log - global.user_id = 4 - - at log (controllers/taskController.js:33:10) - - PASS tdd/assignment5b.test.js - ✓ finds the user and task schemas (1 ms) - test that database and tables exist - ✓ connects to database (54 ms) - ✓ clears the tasks table (1 ms) - ✓ clears the users table (1 ms) - testing logon, register, and logoff - ✓ You can register a user. (68 ms) - ✓ The user can be logged on (51 ms) - ✓ returns the expected name. (1 ms) - ✓ A logon attempt with a bad password returns a 401 (54 ms) - ✓ You can't register again with the same email. (54 ms) - ✓ You can register an additional user. (54 ms) - ✓ You can logon as that new user. (51 ms) - ✓ You can now logoff. (1 ms) - testing task creation - ✓ Logon before testing tasks (51 ms) - ✓ If you have a valid user id, create() succeeds (res.statusCode should be 201). (19 ms) - ✓ The object returned from the create() call has the expected title. (1 ms) - ✓ The object has the right value for isCompleted. - getting created tasks - ✓ If you use user1's id, index returns a 200 statusCode. (3 ms) - ✓ The returned JSON array has length 1. - ✓ The title in the first array object is as expected. (1 ms) - ✓ If get the list of tasks using the userId from user2, you get a 404. (1 ms) - ✓ You can retrieve the first array object using the `show()` method of the controller. (2 ms) - testing the update and delete of tasks. - ✓ User1 can set the task to isCompleted: true. (2 ms) - ✓ User2 can't do this. (1 ms) - ✓ User2 can't delete this task. (1 ms) - ✓ User1 can delete this task. (2 ms) - ✓ Retrieving user1's tasks now returns a 404. (1 ms) - user object validation tests - ✓ doesn't permit a trivial password (1 ms) - ✓ The user schema requires that an email be specified. (1 ms) - ✓ The user schema does not accept an invalid email. (1 ms) - ✓ The user schema requires a password. (1 ms) - ✓ The user schema requires name. (1 ms) - ✓ The name must be valid (3 to 30 characters). (1 ms) - ✓ If validation is performed on a valid user object, error comes back falsy. - task object validation test - ✓ The task schema requires a title. - ✓ If an isCompleted value is specified, it must be valid. (1 ms) - ✓ If an isCompleted value is not specified but the rest of the object is valid, a default of false is provided by validation - ✓ If `isCompleted` in the provided object has the value `true`, it remains `true` after validation. (1 ms) - patchTask object validation test - ✓ Test that the title is not required in this case. - ✓ Test that if no value is provided for `isCompleted`, that this remains undefined in the returned value. (1 ms) - -Test Suites: 1 passed, 1 total -Tests: 39 passed, 39 total -Snapshots: 0 total -Time: 1.005 s -Ran all test suites matching ^tdd/.*assignment5b.*\.test\.js. -zeus@MacBook-Air-de-Jamie node-homework % git status -On branch assignment5 -Changes to be committed: - (use "git restore --staged ..." to unstage) - modified: controllers/taskController.js - modified: package-lock.json - modified: package.json - -zeus@MacBook-Air-de-Jamie node-homework % git add . && git commit -m "Prepare for assignment6 by completing assignment 5." -[assignment5 f46ca64] Prepare for assignment6 by completing assignment 5. - 3 files changed, 114 insertions(+), 100 deletions(-) -zeus@MacBook-Air-de-Jamie node-homework % git status -On branch assignment5 -nothing to commit, working tree clean -zeus@MacBook-Air-de-Jamie node-homework % git push -fatal: The current branch assignment5 has no upstream branch. -To push the current branch and set the remote as upstream, use - - git push --set-upstream origin assignment5 - -To have this happen automatically for branches without a tracking -upstream, see 'push.autoSetupRemote' in 'git help config'. - -zeus@MacBook-Air-de-Jamie node-homework % git push --set-upstream origin assignment5 -Enumerating objects: 22, done. -Counting objects: 100% (21/21), done. -Delta compression using up to 8 threads -Compressing objects: 100% (11/11), done. -Writing objects: 100% (11/11), 2.93 KiB | 2.93 MiB/s, done. -Total 11 (delta 7), reused 0 (delta 0), pack-reused 0 (from 0) -remote: Resolving deltas: 100% (7/7), completed with 4 local objects. -remote: -remote: Create a pull request for 'assignment5' on GitHub by visiting: -remote: https://github.com/JamieBort/node-homework/pull/new/assignment5 -remote: -remote: GitHub found 1 vulnerability on JamieBort/node-homework's default branch (1 high). To find out more, visit: -remote: https://github.com/JamieBort/node-homework/security/dependabot/7 -remote: -To github.com:JamieBort/node-homework.git - * [new branch] assignment5 -> assignment5 -branch 'assignment5' set up to track 'origin/assignment5'. -zeus@MacBook-Air-de-Jamie node-homework % git status -On branch assignment5 -Your branch is up to date with 'origin/assignment5'. - -nothing to commit, working tree clean -zeus@MacBook-Air-de-Jamie node-homework % git switch assignment6 -fatal: invalid reference: assignment6 -zeus@MacBook-Air-de-Jamie node-homework % git switch -c assignment6 -Switched to a new branch 'assignment6' -zeus@MacBook-Air-de-Jamie node-homework % git status -On branch assignment6 -nothing to commit, working tree clean -zeus@MacBook-Air-de-Jamie node-homework % npm install prisma @prisma/client - -added 24 packages, removed 1 package, changed 8 packages, and audited 575 packages in 41s - -106 packages are looking for funding - run `npm fund` for details - -found 0 vulnerabilities -zeus@MacBook-Air-de-Jamie node-homework % npx prisma init -Fetching latest updates for this subcommand... - -Initialized Prisma in your project - - prisma/ - schema.prisma - prisma.config.ts - -warn Prisma would have added DATABASE_URL but it already exists in .env -warn You already have a .gitignore file. Don't forget to add .env in it to not commit any private information. - -Next, choose how you want to set up your database: -CONNECT EXISTING DATABASE: - 1. Configure your DATABASE_URL in prisma.config.ts - 2. Run prisma db pull to introspect your database. -CREATE NEW DATABASE: - Local: npx prisma dev (runs Postgres locally in your terminal) - Cloud: npx create-db (creates a free Prisma Postgres database) - -Then, define your models in prisma/schema.prisma and run prisma migrate dev to apply your schema. -Learn more: https://pris.ly/getting-started - - -zeus@MacBook-Air-de-Jamie node-homework % rm prisma.config.ts -zeus@MacBook-Air-de-Jamie node-homework % npx prisma generate -Environment variables loaded from .env -Prisma schema loaded from prisma/schema.prisma - -✔ Generated Prisma Client (v6.19.2) to ./node_modules/@prisma/client in 139ms - -Start by importing your Prisma Client (See: https://pris.ly/d/importing-client) - -Tip: Interested in query caching in just a few lines of code? Try Accelerate today! https://pris.ly/tip-3-accelerate - -zeus@MacBook-Air-de-Jamie node-homework % npx prisma db pull -Environment variables loaded from .env -Prisma schema loaded from prisma/schema.prisma -Datasource "db": PostgreSQL database "tasklist", schema "public" at "localhost" - -✔ Introspected 2 models and wrote them into prisma/schema.prisma in 229ms - -Run prisma generate to generate Prisma Client. -┌─────────────────────────────────────────────────────────┐ -│ Update available 6.19.2 -> 7.3.0 │ -│ │ -│ This is a major update - please follow the guide at │ -│ https://pris.ly/d/major-version-upgrade │ -│ │ -│ Run the following to update │ -│ npm i --save-dev prisma@latest │ -│ npm i @prisma/client@latest │ -└─────────────────────────────────────────────────────────┘ - -node-homework % git status -On branch assignment6 -Changes not staged for commit: - (use "git add ..." to update what will be committed) - (use "git restore ..." to discard changes in working directory) - modified: .gitignore - modified: package-lock.json - modified: package.json - -Untracked files: - (use "git add ..." to include in what will be committed) - database-status.txt - prisma/ - -no changes added to commit (use "git add" and/or "git commit -a") -zeus@MacBook-Air-de-Jamie node-homework % mv lesson6-notes.txt lesson6-notes.md -zeus@MacBook-Air-de-Jamie node-homework % brew services list -✔︎ JSON API formula_tap_migrations.jws.json [Downloaded 1.9KB/ 1.9KB] -✔︎ JSON API cask_tap_migrations.jws.json [Downloaded 2.4KB/ 2.4KB] -✔︎ JSON API cask.jws.json [Downloaded 15.3MB/ 15.3MB] -✔︎ JSON API formula.jws.json [Downloaded 32.0MB/ 32.0MB] -Name Status User File -postgresql@14 started zeus ~/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist -zeus@MacBook-Air-de-Jamie node-homework % npx prisma migrate reset -Environment variables loaded from .env -Prisma schema loaded from prisma/schema.prisma -Datasource "db": PostgreSQL database "tasklist", schema "public" at "localhost" - -✔ Are you sure you want to reset your database? All data will be lost. … yes - -Database reset successful - - -✔ Generated Prisma Client (v6.19.2) to ./node_modules/@prisma/client in 88ms - -npm notice -npm notice New major version of npm available! 10.8.2 -> 11.9.0 -npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.9.0 -npm notice To update run: npm install -g npm@11.9.0 -npm notice -zeus@MacBook-Air-de-Jamie node-homework % npx prisma migrate dev --name firstMigration -Environment variables loaded from .env -Prisma schema loaded from prisma/schema.prisma -Datasource "db": PostgreSQL database "tasklist", schema "public" at "localhost" - -Applying migration `20260206214630_first_migration` - -The following migration(s) have been created and applied from new schema changes: - -prisma/migrations/ - └─ 20260206214630_first_migration/ - └─ migration.sql - -Your database is now in sync with your schema. - -✔ Generated Prisma Client (v6.19.2) to ./node_modules/@prisma/client in 90ms - -┌─────────────────────────────────────────────────────────┐ -│ Update available 6.19.2 -> 7.3.0 │ -│ │ -│ This is a major update - please follow the guide at │ -│ https://pris.ly/d/major-version-upgrade │ -│ │ -│ Run the following to update │ -│ npm i --save-dev prisma@latest │ -│ npm i @prisma/client@latest │ -└─────────────────────────────────────────────────────────┘ - -zeus@MacBook-Air-de-Jamie node-homework % DATABASE_URL=postgresql://node_homework_owner@localhost/testtasklist?host=/tmp npx prisma migrate reset -Environment variables loaded from .env -Prisma schema loaded from prisma/schema.prisma -Datasource "db": PostgreSQL database "testtasklist", schema "public" at "localhost" - -✔ Are you sure you want to reset your database? All data will be lost. … yes - -Applying migration `20260206214630_first_migration` - -Database reset successful - -The following migration(s) have been applied: - -migrations/ - └─ 20260206214630_first_migration/ - └─ migration.sql - -✔ Generated Prisma Client (v6.19.2) to ./node_modules/@prisma/client in 80ms - -zeus@MacBook-Air-de-Jamie node-homework % \ No newline at end of file From 52918239f45ce1fc66c9b80dc8bb8c217344c6a9 Mon Sep 17 00:00:00 2001 From: Jamie Bort Date: Fri, 13 Feb 2026 08:19:00 -0500 Subject: [PATCH 6/7] Remove personal files from PR. --- .prettierignore | 3 --- node-essentials.code-workspace | 8 -------- 2 files changed, 11 deletions(-) delete mode 100644 .prettierignore delete mode 100644 node-essentials.code-workspace diff --git a/.prettierignore b/.prettierignore deleted file mode 100644 index 5aa5997..0000000 --- a/.prettierignore +++ /dev/null @@ -1,3 +0,0 @@ -* -!issue96-files/ -!issue96-files/** \ No newline at end of file diff --git a/node-essentials.code-workspace b/node-essentials.code-workspace deleted file mode 100644 index 876a149..0000000 --- a/node-essentials.code-workspace +++ /dev/null @@ -1,8 +0,0 @@ -{ - "folders": [ - { - "path": "." - } - ], - "settings": {} -} \ No newline at end of file From 069830943836a0d5366d3a4c6ad4e790186414e2 Mon Sep 17 00:00:00 2001 From: Jamie Bort Date: Thu, 19 Feb 2026 14:36:03 -0500 Subject: [PATCH 7/7] Update prisma assignment. --- .gitignore | 5 +++++ assignments/06-intro-to-prisma.md | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0f7b419..ca28528 100644 --- a/.gitignore +++ b/.gitignore @@ -70,3 +70,8 @@ jspm_packages/ .Trashes ehthumbs.db Thumbs.db + +# My Personal Files and Directories +issue96-files/ +.prettierignore +node-essentials.code-workspace \ No newline at end of file diff --git a/assignments/06-intro-to-prisma.md b/assignments/06-intro-to-prisma.md index 29383a4..de9fddd 100644 --- a/assignments/06-intro-to-prisma.md +++ b/assignments/06-intro-to-prisma.md @@ -34,7 +34,11 @@ npm install prisma @prisma/client npx prisma init ``` -The prisma init command above creates the prisma folder, and within it the shell of a `schema.prisma` file. It also creates a `.env` file if you don't have one. You need to fix `schema.prisma`. The init generates: +The prisma init command above creates the prisma folder, and within it the shell of a `schema.prisma` file. It also creates a `.env` file if you don't have one. Two things need to be addressed at this point. + +First, `.env` file should never be pushed to the remote repo. If it was created when the `npx prisma init` command was run, make sure to add it to the `.gitignore` file BEFORE pushing any changes to the remove repo. + +Second, you need to fix `schema.prisma`. The init generates: ``` generator client { @@ -137,6 +141,8 @@ model Task { } ``` +Note, any time the schema changes, you must regenerate it using the `npx prisma generate` command. + #### c. Migration You can create the schema following the pattern above. You first did the SQL commands to create the tables, then you introspected the schema, then you tweaked the names with mapping as needed. Most people find that this is the hard way. Alternatively, you can instead create the model definitions and use them to create or modify the table schema, using `migrate`. You do the following: