learn-go/snippetbox/db/initdb.d/init.sql
tamsin johnson 4f2dc018da lets-go:11.0 user signup without peeking
deliberately skipping salting and encrypting passwords at this point. intending
to approach this in tandem with authenication.

also starting to want db migrations, but trying not to get distracted.
2024-02-07 11:07:29 -08:00

31 lines
725 B
SQL

USE snippetbox;
CREATE TABLE snippets (
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(100) NOT NULL,
content TEXT NOT NULL,
created DATETIME NOT NULL,
expires DATETIME NOT NULL
);
CREATE USER 'web';
GRANT SELECT, INSERT, UPDATE, DELETE ON snippetbox.* TO 'web' IDENTIFIED BY 'dbpass';
CREATE INDEX idx_snippets_created ON snippets(created);
CREATE TABLE sessions (
token CHAR(43) PRIMARY KEY,
data BLOB NOT NULL,
expiry TIMESTAMP(6) NOT NULL
);
CREATE INDEX sessions_expiry_idx on sessions(expiry);
CREATE TABLE users (
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(20) NOT NULL,
password VARCHAR(20) NOT NULL,
created DATETIME NOT NULL,
UNIQUE (username)
)