learn-go/snippetbox/db/initdb.d/init.sql

33 lines
806 B
MySQL
Raw Normal View History

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
);
2024-01-25 20:41:08 +00:00
CREATE USER 'web';
GRANT SELECT, INSERT, UPDATE, DELETE ON snippetbox.* TO 'web' IDENTIFIED BY 'dbpass';
CREATE INDEX idx_snippets_created ON snippets(created);
2024-02-07 05:06:48 +00:00
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,
2024-02-07 23:15:54 +00:00
username VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
hashed_password CHAR(60) NOT NULL,
2024-02-07 23:54:12 +00:00
created DATETIME NOT NULL
2024-02-07 23:15:54 +00:00
);
ALTER TABLE users ADD CONSTRAINT users_uc_email UNIQUE (email);