Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
d7b0e00
Scaffolding of backend - db - week 2/3
marcorichetta May 27, 2025
b4a1ae2
Merge branch 'main' into 6-database-backend-content-update
marcorichetta May 27, 2025
92cb4c5
Merge branch 'main' into 6-database-backend-content-update
marcorichetta Jul 5, 2025
9924de3
Rename weeks modules and format them to match the template
marcorichetta Jul 5, 2025
c3c811b
update week 1 session goals
marcorichetta Jul 8, 2025
0886edb
match template format
marcorichetta Jul 8, 2025
eaaf34b
add todo for session content
marcorichetta Jul 8, 2025
667b8d6
update week 2 learning goals and main topics
marcorichetta Jul 8, 2025
9d8ef42
format according to template + fixing links
marcorichetta Jul 8, 2025
0ec4714
update preparation.md with video for an example on SQL Injection and …
marcorichetta Jul 9, 2025
1ba77bc
include comment on using a tool other than dbeaver
marcorichetta Jul 23, 2025
c8c810d
add session plan for DB week1
marcorichetta Jul 24, 2025
c675b08
Merge branch 'main' into 6-database-backend-content-update
marcorichetta Jul 24, 2025
c9dc685
update preparation requirements and material
marcorichetta Jul 25, 2025
f85018b
small fixes to learning goals
marcorichetta Jul 25, 2025
6f7c648
refactor assignment: modified the legacy content + adapted it to work…
marcorichetta Jul 25, 2025
d0c9616
lint:fix
marcorichetta Jul 25, 2025
f16bfec
use mariadb.com resources for reading list - much cleaner and stick t…
marcorichetta Jul 25, 2025
a8666a6
add mariadb resources for preparation
marcorichetta Jul 28, 2025
9dbcc07
make the session goals more practical
marcorichetta Jul 28, 2025
4db3a43
create session plan based on learning goals, focusing on using the sa…
marcorichetta Jul 28, 2025
4c2980d
add sample api to work through the session-plan
marcorichetta Jul 28, 2025
bb66937
assignment todo
marcorichetta Jul 28, 2025
0d4eeca
`./lint --fix`
marcorichetta Jul 28, 2025
e8293a6
refine module learning goals + add prerequisites
marcorichetta Jul 30, 2025
33d31fd
correct some more content based on Adam's feedback
marcorichetta Jul 30, 2025
e304340
move example-api to correct directory
marcorichetta Jul 30, 2025
de008a9
update database filename and directory
marcorichetta Jul 30, 2025
ea5c0f6
rename tasks/db to tasks.sqlite3 for consistency
marcorichetta Aug 4, 2025
13ffef1
set package type to avoid warning when running `npm run dev`
marcorichetta Aug 4, 2025
5d29b51
improve setup notes
marcorichetta Aug 4, 2025
111d763
improve aggregate functions wording
marcorichetta Aug 4, 2025
16d7347
reorganize transactions content
marcorichetta Aug 4, 2025
c99af40
refine database types section + add summary
marcorichetta Aug 4, 2025
941967e
add exercise for sql injection
marcorichetta Aug 4, 2025
178d620
change ORM queries to parameterized ones
marcorichetta Aug 4, 2025
6a97fc8
add interactivity to the ERD demo
marcorichetta Aug 4, 2025
6f34dca
fix: clarify difference between CRUD goal on week 1
marcorichetta Aug 20, 2025
ed23a89
refactor: clarify session structure and add more incremental exercises
marcorichetta Aug 21, 2025
d75d4ed
refactor: improve the join explanation to be more incremental
marcorichetta Aug 21, 2025
41542d3
refactor: small fixes
marcorichetta Aug 21, 2025
0e0b12b
fix: remove ids to avoid duplicate id constraint and use autoincrement
marcorichetta Aug 21, 2025
ff6deb2
feat: add sample db with complete data from class. Also useful for as…
marcorichetta Aug 21, 2025
fb1c363
refactor: minimal fixes to the session plan
marcorichetta Aug 21, 2025
0157bec
refactor: improve description, add tips and replace mysql for sqlite …
marcorichetta Aug 21, 2025
5b90cfa
feat: add aggregate fns and more transaction resources
marcorichetta Aug 21, 2025
19ba9fd
refactor: remove transactions from session plan
marcorichetta Aug 21, 2025
25ec446
./lint --fix
marcorichetta Aug 21, 2025
1718c02
Merge branch 'main' into 6-database-backend-content-update
marcorichetta Aug 21, 2025
3202c98
./lint --fix
marcorichetta Aug 21, 2025
203e207
fix: move course from Backend -> backend
marcorichetta Aug 21, 2025
110d1a9
feat: add html elements to use collapsible sections
marcorichetta Aug 22, 2025
9481d9a
./lint --fix
marcorichetta Aug 22, 2025
116a453
fix: add clearer setup instructions for mentor and trainees
marcorichetta Oct 7, 2025
b3d11c1
feat: add section on database deployments: concepts, the why and setup
marcorichetta Oct 14, 2025
18a65a0
fix: move example-api to the assignment repo and update instructions
marcorichetta Oct 14, 2025
6e89b4c
small clarification
marcorichetta Oct 14, 2025
8c3e734
Merge branch 'main' into 6-database-backend-content-update
marcorichetta Oct 14, 2025
defbc3b
remove example api
marcorichetta Oct 14, 2025
198198e
fix lint errors
marcorichetta Oct 14, 2025
c9b5c5f
fix invalid links
marcorichetta Oct 14, 2025
3c9cb05
Added directory structure for gitbook
adamblanchard Oct 14, 2025
b0187b0
updated language from school like terms
adamblanchard Oct 14, 2025
886b4dc
another student replacement
adamblanchard Oct 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ MD026:
MD033:
allowed_elements:
- nobr
- summary
- details
MD046:
style: fenced
"search-replace":
Expand Down
8 changes: 8 additions & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@
- [Backend](courses/backend/README.md)
- [Advanced JavaScript](courses/backend/advanced-javascript/README.md)
- [Databases](courses/backend/databases/README.md)
- [Week 1](courses/backend/databases/week1/README.md)
- [Preparation](courses/backend/databases/week1/preparation.md)
- [Session Plan](courses/backend/databases/week1/session-plan.md)
- [Assignment](courses/backend/databases/week1/assignment.md)
- [Week 2](courses/backend/databases/week2/README.md)
- [Preparation](courses/backend/databases/week2/preparation.md)
- [Session Plan](courses/backend/databases/week2/session-plan.md)
- [Assignment](courses/backend/databases/week2/assignment.md)
- [Node](courses/backend/node/README.md)
- [Final Backend Project](courses/backend/final-project/README.md)

Expand Down
25 changes: 24 additions & 1 deletion courses/backend/databases/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
# Databases

Coming soon
This module is part of the Backend specialism course and goes deep on databases, including SQL topics like CRUD, relationships and other advanced concepts like transactions, security, and deployment. It also covers different types of databases and their use cases.

| 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) |

## 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 more complex SQL queries involving joins and aggregations
- [ ] Understand the use cases for different types of databases (SQL, NoSQL, Key-Value, Graph)
- [ ] Communicate the importance of database security
- [ ] Understand the most common security threats and how to mitigate them with best practices

## Prerequisites

You should have completed or understand the learning goals in the following modules before proceeding:

- [ ] [Foundation - Databases](../../foundation/databases/README.md)
30 changes: 30 additions & 0 deletions courses/backend/databases/week1/README.md
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)

## 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 CRUD operations for more complex scenarios (INSERT with Foreign keys, DELETE with filters)
- [ ] 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 Keys and Constraints (ON DELETE, ON UPDATE actions)
- SQL JOIN Operations (INNER JOIN, LEFT JOIN)
121 changes: 121 additions & 0 deletions courses/backend/databases/week1/assignment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Assignment

In this assignment, you'll practice working with the task management database we worked in the session.
The idea is for you to create a database from scratch, insert and update data writing queries, practice querying relationships, and finally modify the database schema to add new functionality.

## Getting Started

> [!TIP]
> If problems arise, remember you can ask on Slack for help.
> We encourage you to create the DB from scratch, but you can also use the provided database, [tasks.sqlite3](./session-materials/tasks.sqlite3) which has the same content as the one created in the session.

[tasks.sql](./session-materials/tasks.sql) contains SQL statements to create a database.

To create a database called `tasks.sqlite3` executing the SQL statements in `tasks.sql`, run the following command in your terminal:

```shell
sqlite3 tasks.sqlite3 < session-materials/tasks.sql
```

> [!NOTE]
> Remember you can delete the `tasks.sqlite3` 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.
And the database schema will look like this:

```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. List all users who don't have any tasks assigned
1. Find all tasks with a status of "Done"
1. 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'. 💡 Remember to provide default values.
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

## 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 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', datetime('now'), datetime('now'), date('now', '+7 days'), 2);
```
18 changes: 18 additions & 0 deletions courses/backend/databases/week1/preparation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Preparation

## Tools Setup

If you haven't already, install the following tools:

- [DBeaver](https://dbeaver.io/download/), [SQlite Viewer - VSCode Extension](https://marketplace.visualstudio.com/items?itemName=qwtel.sqlite-viewer) or any other SQL client of your choice.
- (Optional) [SQLite](https://www.sqlite.org/download.html) if you want to practice using the command line.

## Reading List

Read/watch through this list of content before you come to the session:

- [Database Design - Phase 1 - Analysis](https://mariadb.com/docs/general-resources/database-theory/database-design/database-design-example-phase-1-analysis)
- [Database Design - Phase 2 - Design](https://mariadb.com/docs/general-resources/database-theory/database-design/database-design-example-phase-2-design)
- [Database Design - Phase 3 - Implementation](https://mariadb.com/docs/general-resources/database-theory/database-design/database-design-example-phase-3-implementation) - Don't implement the database, just read through the example.
- [What is a foreign key?](https://mariadb.com/docs/general-resources/database-theory/relational-databases-foreign-keys)
- [Databases resources from Foundation](../../../foundation/databases/week1/preparation.md)
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"]
}
]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading