-
Notifications
You must be signed in to change notification settings - Fork 8
Update database lesson material (Backend) #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
72 commits
Select commit
Hold shift + click to select a range
d7b0e00
Scaffolding of backend - db - week 2/3
marcorichetta b4a1ae2
Merge branch 'main' into 6-database-backend-content-update
marcorichetta 92cb4c5
Merge branch 'main' into 6-database-backend-content-update
marcorichetta 9924de3
Rename weeks modules and format them to match the template
marcorichetta c3c811b
update week 1 session goals
marcorichetta 0886edb
match template format
marcorichetta eaaf34b
add todo for session content
marcorichetta 667b8d6
update week 2 learning goals and main topics
marcorichetta 9d8ef42
format according to template + fixing links
marcorichetta 0ec4714
update preparation.md with video for an example on SQL Injection and …
marcorichetta 1ba77bc
include comment on using a tool other than dbeaver
marcorichetta c8c810d
add session plan for DB week1
marcorichetta c675b08
Merge branch 'main' into 6-database-backend-content-update
marcorichetta c9dc685
update preparation requirements and material
marcorichetta f85018b
small fixes to learning goals
marcorichetta 6f7c648
refactor assignment: modified the legacy content + adapted it to work…
marcorichetta d0c9616
lint:fix
marcorichetta f16bfec
use mariadb.com resources for reading list - much cleaner and stick t…
marcorichetta a8666a6
add mariadb resources for preparation
marcorichetta 9dbcc07
make the session goals more practical
marcorichetta 4db3a43
create session plan based on learning goals, focusing on using the sa…
marcorichetta 4c2980d
add sample api to work through the session-plan
marcorichetta bb66937
assignment todo
marcorichetta 0d4eeca
`./lint --fix`
marcorichetta e8293a6
refine module learning goals + add prerequisites
marcorichetta 33d31fd
correct some more content based on Adam's feedback
marcorichetta e304340
move example-api to correct directory
marcorichetta de008a9
update database filename and directory
marcorichetta ea5c0f6
rename tasks/db to tasks.sqlite3 for consistency
marcorichetta 13ffef1
set package type to avoid warning when running `npm run dev`
marcorichetta 5d29b51
improve setup notes
marcorichetta 111d763
improve aggregate functions wording
marcorichetta 16d7347
reorganize transactions content
marcorichetta c99af40
refine database types section + add summary
marcorichetta 941967e
add exercise for sql injection
marcorichetta 178d620
change ORM queries to parameterized ones
marcorichetta 6a97fc8
add interactivity to the ERD demo
marcorichetta 6f34dca
fix: clarify difference between CRUD goal on week 1
marcorichetta ed23a89
refactor: clarify session structure and add more incremental exercises
marcorichetta d75d4ed
refactor: improve the join explanation to be more incremental
marcorichetta 41542d3
refactor: small fixes
marcorichetta 0e0b12b
fix: remove ids to avoid duplicate id constraint and use autoincrement
marcorichetta ff6deb2
feat: add sample db with complete data from class. Also useful for as…
marcorichetta fb1c363
refactor: minimal fixes to the session plan
marcorichetta 0157bec
refactor: improve description, add tips and replace mysql for sqlite …
marcorichetta 5b90cfa
feat: add aggregate fns and more transaction resources
marcorichetta 19ba9fd
refactor: remove transactions from session plan
marcorichetta 25ec446
./lint --fix
marcorichetta 1718c02
Merge branch 'main' into 6-database-backend-content-update
marcorichetta 3202c98
./lint --fix
marcorichetta 203e207
fix: move course from Backend -> backend
marcorichetta 110d1a9
feat: add html elements to use collapsible sections
marcorichetta 9481d9a
./lint --fix
marcorichetta 116a453
fix: add clearer setup instructions for mentor and trainees
marcorichetta b3d11c1
feat: add section on database deployments: concepts, the why and setup
marcorichetta 18a65a0
fix: move example-api to the assignment repo and update instructions
marcorichetta 6e89b4c
small clarification
marcorichetta 8c3e734
Merge branch 'main' into 6-database-backend-content-update
marcorichetta defbc3b
remove example api
marcorichetta 198198e
fix lint errors
marcorichetta c9b5c5f
fix invalid links
marcorichetta 3c9cb05
Added directory structure for gitbook
adamblanchard b0187b0
updated language from school like terms
adamblanchard 886b4dc
another student replacement
adamblanchard bad5606
Improved wording of the cloud header
adamblanchard cb86a64
Removed sqlite3 file but give clear insturctions to mentor to recreat…
adamblanchard 658aaa2
add clearer instructions where the trainee should create the database…
adamblanchard 15be2c5
clarify that the assignment is built ontop of the working solution fr…
adamblanchard 806e02d
tidy up session plan week 2
adamblanchard b915463
Fixed broken reference to sample data
adamblanchard 01b0df0
fixed broken link on gitbook
adamblanchard 62fcbce
actually fixed gitbook link
adamblanchard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,28 @@ | ||
| # Databases | ||
|
|
||
| TODO | ||
| This module is part of the Backend specialism course and goes deep on databases, including SQL topics like CRUD, relationships and other advanced concepts. It should also covers security and NoSQL on a theoretical level # TODO | ||
|
|
||
| Lesson1 is already been covered in foundation. These is the remaining content: | ||
| ## Contents | ||
|
|
||
| Week 1: [legacy lesson2](../../../legacy/databases/lesson2/) | ||
| Week 2: [legacy lesson3](../../../legacy/databases/lesson3/) | ||
| | Week | Topic | Preparation | Lesson Plan | Assignment | | ||
| | ---- | -------------------------------------------------------------- | ------------------------------------- | ----------------------------------------------------- | ----------------------------------- | | ||
| | 1. | [Data Modeling and Relational Fundamentals](./week1/README.md) | [Preparation](./week1/preparation.md) | [Session Plan](./week1/session-plan.md) (for mentors) | [Assignment](./week1/assignment.md) | | ||
| | 2. | [Database Security and Transactions](./week2/README.md) | [Preparation](./week2/preparation.md) | [Session Plan](./week2/session-plan.md) (for mentors) | [Assignment](./week2/assignment.md) | | ||
|
|
||
| ## Module Learning Goals | ||
|
|
||
| By the end of this module, you will be able to: | ||
|
|
||
| - [ ] Explain the purpose of databases in web applications | ||
| - [ ] Perform basic CRUD operations using SQL | ||
| - [ ] Understand and implement relationships between tables in SQL | ||
| - [ ] Write SQL queries involving joins and aggregations | ||
| - [ ] Describe the differences between SQL and NoSQL databases | ||
| - [ ] Performance? | ||
| - [ ] Security? | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| You should have completed or understand the learning goals in the following modules before proceeding: | ||
|
|
||
| - [ ] ? | ||
marcorichetta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # Data Modeling and Relational Fundamentals | ||
|
|
||
| This session is about understanding the entity relationship model, being able to use that knowledge and implement it building a database schema. With the database schema created, you should be able to create a database and test it using SQL statements. | ||
|
|
||
| ## Contents | ||
|
|
||
| - [Preparation](./preparation.md) | ||
| - [Session Plan](./session-plan.md) (for mentors) | ||
| - [Assignment](./assignment.md) | ||
|
|
||
| ## Session Learning Goals | ||
|
|
||
| By the end of this session, you will be able to: | ||
|
|
||
| - [ ] Create an entity relationship diagram from a description of data requirements | ||
| - [ ] Translate a simple entity relationship diagram into a database schema | ||
| - [ ] Use SQL statements for data manipulation (INSERT INTO, UPDATE, DELETE) | ||
marcorichetta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - [ ] Use foreign keys to establish relationships between tables | ||
| - [ ] Write SQL queries to retrieve related data using JOIN operations | ||
|
|
||
| ## Main Topics | ||
|
|
||
| - Entity-Relationship Diagrams (ERDs): | ||
| - Introduction to ERDs | ||
| - Components: Entities, Attributes, Relationships (1:1, 1:M, M:M) | ||
| - Translating ERDs to Database Schema: | ||
| - Mapping rules for tables, columns, primary keys (PKs), and foreign keys (FKs) | ||
| - Working with Related Data: | ||
| - Foreign Key Constraints (ON DELETE, ON UPDATE actions) | ||
| - SQL JOIN Operations (INNER JOIN, LEFT JOIN) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| # Week 1 Assignment: Working with Databases | ||
|
|
||
| In this assignment, you'll practice working with a task management database. You'll learn how to create tables, insert data, write queries, and modify the database structure. | ||
|
|
||
| ## Getting Started | ||
|
|
||
| [tasks.sql](./session-materials/tasks.sql) contains SQL statements to create a database. | ||
|
|
||
| To create a database called `tasks.db` executing the SQL statements in `tasks.sql`, run the following command in your terminal: | ||
|
|
||
| ```shell | ||
| sqlite3 tasks.db < session-materials/tasks.sql | ||
| ``` | ||
|
|
||
| > [!NOTE] | ||
| > Remember you can delete the `tasks.db` file and run the command again to recreate it from scratch. | ||
| The script will also insert some sample data for you to work with, including users, tasks, and statuses. | ||
|
|
||
| ```mermaid | ||
| erDiagram | ||
| USER { | ||
| int id PK | ||
| string name | ||
| string email | ||
| string phone | ||
| } | ||
| STATUS { | ||
| int id PK | ||
| string name | ||
| } | ||
| TASK { | ||
| int id PK | ||
| string title | ||
| string description | ||
| datetime created | ||
| datetime updated | ||
| date due_date | ||
| int status_id FK | ||
| } | ||
| USER_TASK { | ||
| int user_id FK | ||
| int task_id FK | ||
| } | ||
| USER ||--o{ USER_TASK : assigns | ||
| TASK ||--o{ USER_TASK : is_assigned | ||
| STATUS ||--o{ TASK : has | ||
| ``` | ||
|
|
||
| ## Part 1: Basic CRUD Operations | ||
|
|
||
| Write SQL queries to perform the following operations: | ||
|
|
||
| 1. Insert a new user with your own name and email | ||
| 2. Insert a new task assigned to yourself with the following attributes: | ||
| - Title: "Learn SQL" | ||
| - Description: "Practice database queries" | ||
| - Status: "In Progress" | ||
| - Due date: One week from today | ||
| 3. Update the title of the task you just created to "Master SQL Basics" | ||
| 4. Change the due date of your task to two weeks from today | ||
| 5. Change the status of your task to "Done" | ||
| 6. Delete one of the tasks in the database (choose any task) | ||
|
|
||
| For each operation, save your SQL query in a text file. | ||
|
|
||
| ## Part 2: Working with Relationships | ||
|
|
||
| Write SQL queries to answer the following questions: | ||
|
|
||
| 1. Get all tasks assigned to a specific user (choose a username from the database) | ||
| 2. Find how many tasks each user is responsible for (show username and count) | ||
| 3. List all users who don't have any tasks assigned | ||
| 4. Find all tasks with a status of "Done" | ||
| 5. Find all overdue tasks (due_date is earlier than today) | ||
|
|
||
| ## Part 3: Modifying the Database Schema | ||
|
|
||
| Now let's modify our database structure to add more functionality: | ||
|
|
||
| 1. Add a new column called `priority` to the `task` table with possible values: 'Low', 'Medium', 'High' | ||
| 2. Update some existing tasks to have different priority values | ||
| 3. Create a new table called `category` with columns: | ||
| - id (PRIMARY KEY) | ||
| - name (e.g., "Work", "Personal", "Study") | ||
| - color (e.g., "red", "blue", "green") | ||
| 4. Create a linking table called `task_category` to establish a many-to-many relationship between tasks and categories: | ||
| - task_id (FOREIGN KEY to task.id) | ||
| - category_id (FOREIGN KEY to category.id) | ||
| 5. Insert at least 3 categories | ||
| 6. Assign categories to at least 5 different tasks | ||
marcorichetta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Part 4: Advanced Queries | ||
|
|
||
| Now that you've enhanced the database, write queries to: | ||
|
|
||
| 1. Find all tasks in a specific category (e.g., "Work") | ||
| 2. List tasks ordered by priority (High to Low) and then by due date (earliest first) | ||
| 3. Find which category has the most tasks | ||
| 4. Get all high priority tasks that are either "In Progress" or "To Do" | ||
| 5. Find users who have tasks in more than one category | ||
|
|
||
| ## Submission | ||
|
|
||
| Submit your assignment as a single .sql file containing all your queries, clearly labeled with comments indicating which part and question each query addresses. | ||
|
|
||
| Example: | ||
|
|
||
| ```sql | ||
| -- Part 1, Question 1: Insert a new user | ||
| INSERT INTO user (name, email, phone) VALUES ('My Name', '[email protected]', '123-456-7890'); | ||
|
|
||
| -- Part 1, Question 2: Insert a new task | ||
| INSERT INTO task (title, description, created, updated, due_date, status_id) | ||
| VALUES ('Learn SQL', 'Practice database queries', NOW(), NOW(), DATE_ADD(NOW(), INTERVAL 7 DAY), 2); | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Preparation | ||
|
|
||
| ## Software | ||
|
|
||
| - Install [DBeaver](https://dbeaver.io/download/) or any other SQL client of your choice. | ||
marcorichetta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - (Optional) Install [SQLite](https://www.sqlite.org/download.html) if you want to practice using the command line. | ||
marcorichetta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Reading List | ||
|
|
||
| Read/watch through this list of content before you come to the session: | ||
|
|
||
| - [Databases resources from Foundation](../../../Foundation/databases/week1/preparation.md) | ||
| - [What is an ER diagram?](https://www.figma.com/resource-library/what-is-an-er-diagram/) | ||
| - [What is a foreign key?](https://www.cockroachlabs.com/blog/what-is-a-foreign-key/) | ||
50 changes: 50 additions & 0 deletions
50
courses/Backend/databases/week1/session-materials/articles_example.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| [ | ||
| { | ||
| "id": 1, | ||
| "authors": [ | ||
| { | ||
| "id": 1, | ||
| "name": "James Smith" | ||
| }, | ||
| { | ||
| "id": 2, | ||
| "name": "Jane Jones" | ||
| } | ||
| ], | ||
| "title": "BREAKING NEWS: Water is wet!", | ||
| "content": "Scientists have discovered that water is wet, it's amazing what.... ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.", | ||
| "tags": ["science", "breaking"] | ||
| }, | ||
| { | ||
| "id": 2, | ||
| "authors": [ | ||
| { | ||
| "id": 3, | ||
| "name": "Aliya Awad" | ||
| }, | ||
| { | ||
| "id": 4, | ||
| "name": "Igor Vladimir" | ||
| } | ||
| ], | ||
| "title": "Heavy Snowfall Expected this Weekend", | ||
| "content": "Lots of snow is expected... Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", | ||
| "tags": ["weather", "winter"] | ||
| }, | ||
| { | ||
| "id": 3, | ||
| "authors": [ | ||
| { | ||
| "id": 2, | ||
| "name": "Jane Jones" | ||
| }, | ||
| { | ||
| "id": 5, | ||
| "name": "Kim Jensen" | ||
| } | ||
| ], | ||
| "title": "BREAKING NEWS: These 10 Clickbait Titles Are Bad for Your Health, Number 7 Will SHOCK You!", | ||
| "content": "Haha, you clicked! Minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat ", | ||
| "tags": ["clickbait", "breaking"] | ||
| } | ||
| ] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.