D
D
DarkUser13372020-03-22 19:01:18
MySQL
DarkUser1337, 2020-03-22 19:01:18

Does MySQL's table structure look correct?

Hello! Are these tables properly configured in terms of proper data storage and optimization? What errors and shortcomings can occur? What to fix?

I use TINYINT instead of bool, the value will always be 1/0
DATETIME naturally for date and time. Maybe it's better to use UNIX time with integers? restore

table for password recovery

`id` int(11) NOT NULL,   
 `user_id` int(11) NOT NULL DEFAULT 0,  
 `email` varchar(100) COLLATE utf8_unicode_ci NOT NULL,   
 `restore_key` varchar(191) COLLATE utf8_unicode_ci NOT NULL, -- ключ, который отправится на email   
 `changed` tinyint(1) NOT NULL DEFAULT 0, -- при следующем переходе по той же ссылке, проверяется это значение, менялся ли уже пароль
 `created_at` datetime NOT NULL


users table
`user_id` int(11) UNSIGNED NOT NULL,
  `username` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
  `email` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  `password` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
  `password_salt` varchar(64) COLLATE utf8_unicode_ci NOT NULL,   -- динамическая соль
  `token` varchar(191) COLLATE utf8_unicode_ci NOT NULL,          -- ключ для доступа к API
  `hwid` varchar(128) COLLATE utf8_unicode_ci NOT NULL,           -- хеш
  `activation_key` varchar(191) COLLATE utf8_unicode_ci NOT NULL, -- ключ для подтверждения email'a
  `status` tinyint(1) NOT NULL DEFAULT 0,                         -- подтвержден ли email
  `password_changed_date` datetime NOT NULL DEFAULT current_timestamp(),
  `join_date` datetime NOT NULL


user_privileges table user privileges (admin, moderator, etc.)
`id` int(11) NOT NULL,
  `user_id` int(11) UNSIGNED NOT NULL,
  `level` int(11) NOT NULL DEFAULT 1


Indices

restore tables , user_privileges
ADD PRIMARY KEY (`id`);

table users
ADD PRIMARY KEY (`user_id`),
  ADD KEY `username` (`username`),
  ADD KEY `email` (`email`),
  ADD KEY `hwid` (`hwid`),
  ADD KEY `token` (`token`);


AUTO_INCREMENT attribute

restore tables , user_privileges
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

table users
MODIFY `user_id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT;

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question