From b1e7a78032366723df7d5ce0b5a0f83cb089281e Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Mon, 21 Sep 2026 18:54:32 +0700 Subject: [PATCH] add dev user script --- Makefile | 16 ++++++++++++++++ README.md | 12 ++++++++++++ scripts/dev-user.sql | 18 ++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 scripts/dev-user.sql diff --git a/Makefile b/Makefile index f9ddcef..eb1e14f 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,19 @@ +# Local development user. Override DATABASE_URL/DEV_USER_* when needed. +DATABASE_URL ?= postgresql://postgres:postgres@localhost:5432/evening_detective_server?sslmode=disable +DEV_USER_USERNAME ?= dev +DEV_USER_EMAIL ?= dev@example.com +DEV_USER_PASSWORD ?= dev123456 + +.PHONY: dev-user + +dev-user: + psql "$(DATABASE_URL)" \ + -v ON_ERROR_STOP=1 \ + -v dev_username="$(DEV_USER_USERNAME)" \ + -v dev_email="$(DEV_USER_EMAIL)" \ + -v dev_password="$(DEV_USER_PASSWORD)" \ + -f scripts/dev-user.sql + # Protobuf generation (tool versions are documented in README.md). # Install the pinned plugins before running: make install-generate-tools. generate: diff --git a/README.md b/README.md index ff307e7..6fc6f58 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,18 @@ mkdir migrations make run ``` +Создание локального пользователя с полными ролями: + +```shell +make dev-user +``` + +По умолчанию: `dev@example.com` / `dev123456`. Значения можно изменить: + +```shell +make dev-user DEV_USER_EMAIL=test@example.com DEV_USER_PASSWORD=test123456 +``` + Сборка ```shell diff --git a/scripts/dev-user.sql b/scripts/dev-user.sql new file mode 100644 index 0000000..d0c2875 --- /dev/null +++ b/scripts/dev-user.sql @@ -0,0 +1,18 @@ +CREATE EXTENSION IF NOT EXISTS pgcrypto; + +INSERT INTO users (username, email, password_hash, roles, is_active) +VALUES ( + :'dev_username', + :'dev_email', + crypt(:'dev_password', gen_salt('bf')), + '["admin", "author", "organizer", "user"]'::jsonb, + TRUE +) +ON CONFLICT (email) DO UPDATE +SET username = EXCLUDED.username, + password_hash = EXCLUDED.password_hash, + roles = EXCLUDED.roles, + is_active = TRUE; + +\echo 'Development user is ready.' +\echo 'Login with the DEV_USER_EMAIL and DEV_USER_PASSWORD values passed to make.'