generated from VLADIMIR/template
add dev user script
This commit is contained in:
@@ -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).
|
# Protobuf generation (tool versions are documented in README.md).
|
||||||
# Install the pinned plugins before running: make install-generate-tools.
|
# Install the pinned plugins before running: make install-generate-tools.
|
||||||
generate:
|
generate:
|
||||||
|
|||||||
@@ -28,6 +28,18 @@ mkdir migrations
|
|||||||
make run
|
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
|
```shell
|
||||||
|
|||||||
@@ -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.'
|
||||||
Reference in New Issue
Block a user