2. Schema
This week we will work with 2 tables:
A
userstable.A
snippetstable containing (code) snippets that belong to a user.
Create a new Sqlite database/schema hyf_node_week1 containing the following tables:
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:
Last updated