# 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: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
