> For the complete documentation index, see [llms.txt](https://program.hackyourfuture.dk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://program.hackyourfuture.dk/course-content/backend/node/week1/session-materials/02-schema.md).

# 2. Schema

This week we will work with 2 tables:

* A `users` table.
* A `snippets` table containing (code) snippets that belong to a user.

Create a new Sqlite database/schema `hyf_node_week1` containing the following tables:

```sql
CREATE TABLE users (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  created_at DATETIME NOT NULL DEFAULT (CURRENT_TIMESTAMP),
  confirmed_at DATETIME DEFAULT NULL,
  first_name TEXT NOT NULL,
  last_name TEXT NOT NULL,
  email TEXT NOT NULL UNIQUE,
  token TEXT UNIQUE
);

CREATE TABLE snippets (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  created_at DATETIME NOT NULL DEFAULT (CURRENT_TIMESTAMP),
  user_id INTEGER NOT NULL,
  title TEXT NOT NULL,
  contents TEXT NOT NULL,
  is_private INTEGER NOT NULL DEFAULT 1,
  FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE RESTRICT
);

```

Insert sample data to have something to play with:

```sql
INSERT INTO users (first_name, last_name, email, token, confirmed_at)
VALUES
('Aiko', 'Tanaka', 'aiko.tanaka@example.com', 'tok123', '2025-01-12 10:30:00'),
('Mateo', 'García', 'mateo.garcia@example.com', 'mad456', '2025-02-18 14:22:00'),
('Liam', "O'Connor", 'liam.oconnor@example.com', 'dub789', '2025-03-09 09:45:00'),
('Fatima', 'Al-Sayed', 'fatima.alsayed@example.com', 'cai321', '2025-04-01 16:15:00'),
('Zanele', 'Khumalo', 'zanele.khumalo@example.com', 'jhb654', NULL); -- Not yet confirmed


INSERT INTO snippets (user_id, title, contents, is_private)
VALUES
(1, 'Async in Python', 'A quick guide to using asyncio for concurrent tasks.', 0),
(1, 'SQL Basics', 'An introduction to SELECT, WHERE, and JOIN in SQL.', 1),

(2, 'React Hooks', 'Explaining useState and useEffect with examples.', 0),
(2, 'Docker 101', 'Setting up containers for web apps.', 1),
(2, 'Node.js Tips', 'Best practices for writing clean async code.', 0),

(3, 'Rust Ownership', 'A simple explanation of the ownership model.', 0),
(3, 'Linux Commands', 'Common shell commands for beginners.', 1),

(4, 'CSS Grid Layout', 'How to build responsive layouts with CSS Grid.', 0),
(4, 'Tailwind Shortcuts', 'Useful utility classes for quick design.', 1),
(4, 'Flask REST API', 'Creating a small REST API in Flask.', 0);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://program.hackyourfuture.dk/course-content/backend/node/week1/session-materials/02-schema.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
