feat: роли customer/admin, админ-панель, admin@site.com

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
shop
2026-05-17 11:19:01 +03:00
parent 58c789d5f8
commit f24f35d0fc
18 changed files with 497 additions and 9 deletions
+4
View File
@@ -5,9 +5,13 @@ CREATE TABLE IF NOT EXISTS users (
email TEXT NOT NULL UNIQUE,
password_hash TEXT NOT NULL,
name TEXT NOT NULL,
role TEXT NOT NULL DEFAULT 'customer'
CHECK (role IN ('customer', 'admin')),
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_users_role ON users(role);
CREATE TABLE IF NOT EXISTS categories (
id SERIAL PRIMARY KEY,
slug TEXT NOT NULL UNIQUE,
+14
View File
@@ -0,0 +1,14 @@
-- Роли пользователей (миграция для существующих БД)
ALTER TABLE users ADD COLUMN IF NOT EXISTS role TEXT NOT NULL DEFAULT 'customer';
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM pg_constraint WHERE conname = 'users_role_check'
) THEN
ALTER TABLE users ADD CONSTRAINT users_role_check
CHECK (role IN ('customer', 'admin'));
END IF;
END $$;
CREATE INDEX IF NOT EXISTS idx_users_role ON users(role);