DK2/database/create/auth.sql

29 lines
798 B
MySQL
Raw Normal View History

2024-10-16 22:55:47 -05:00
DROP TABLE IF EXISTS users;
CREATE TABLE users (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`username` TEXT NOT NULL UNIQUE,
`email` TEXT NOT NULL UNIQUE,
`password` TEXT NOT NULL,
`auth` INT NOT NULL DEFAULT 0,
`char_id` INTEGER NOT NULL DEFAULT 0,
`char_slots` INTEGER NOT NULL DEFAULT 2,
`created` DATETIME DEFAULT CURRENT_TIMESTAMP,
`last_login` DATETIME DEFAULT CURRENT_TIMESTAMP
);
DROP TABLE IF EXISTS sessions;
CREATE TABLE sessions (
`user_id` INTEGER NOT NULL,
`token` TEXT NOT NULL UNIQUE,
`expires` INTEGER NOT NULL
);
CREATE INDEX idx_sessions_user_id ON sessions (`user_id`);
DROP TABLE IF EXISTS tokens;
CREATE TABLE tokens (
`user_id` INTEGER NOT NULL,
`token` TEXT NOT NULL UNIQUE,
`created` INTEGER NOT NULL
);
CREATE INDEX idx_tokens_user_id ON tokens (`user_id`);