Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/postgres local stage 2 #72

Merged
merged 8 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ DJANGO_SUPERUSER_ROLE=admin
DJANGO_SUPERUSER_USERNAME=admin
DJANGO_SUPERUSER_EMAIL=admin@admin.ru
DJANGO_SUPERUSER_PASSWORD=admin

# Postgres settings

DB_ENGINE='django.db.backends.postgresql'
POSTGRES_PASSWORD='1qw2#ER$'
POSTGRES_USER='django'
POSTGRES_DB='django'
DB_HOST='localhost'
DB_PORT='5432'
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ MANAGE_DIR := $(PROJECT_DIR)/adaptive_hockey_federation/manage.py
DJANGO_DIR := $(PROJECT_DIR)/adaptive_hockey_federation
POETRY_RUN := poetry run python
DJANGO_RUN := $(POETRY_RUN) $(MANAGE_DIR)
DEV_DOCK_FILE := $(PROJECT_DIR)/infra/dev/docker-compose.dev.yaml
SHELL_GREEN = \033[32m
SHELL_YELLOW = \033[33m
SHELL_NC := \e[0m
Expand All @@ -21,6 +22,9 @@ help:
@echo " collectstatic - $(SHELL_GREEN)Команда для сбора статики.$(SHELL_NC)"
@echo " migrate - $(SHELL_GREEN)Команда для применения к базе данных готовых миграций.$(SHELL_NC)"
@echo " createsuperuser - $(SHELL_GREEN)Команда для создания супер-юзера.$(SHELL_NC)"
@echo " start-db - $(SHELL_GREEN)Команда для запуска локального контейнера postgres.$(SHELL_NC)"
@echo " stop-db - $(SHELL_GREEN)Команда для остановки локального контейнера postgres.$(SHELL_NC)"
@echo " clear-db - $(SHELL_GREEN)Команда для очистки volume локального контейнера postgres.$(SHELL_NC)"
@echo " run - $(SHELL_GREEN)Команда для локального запуска проекта.$(SHELL_NC)"
@echo " fill-db - $(SHELL_GREEN)Команда для заполнения базы данных с помощью парсера.$(SHELL_NC)"
@echo " pytest - $(SHELL_GREEN)Команда для прогона юнит тестов pytest.$(SHELL_NC)"
Expand Down Expand Up @@ -55,6 +59,31 @@ createsuperuser:
cd $(PROJECT_DIR) && $(DJANGO_RUN) createsuperuser --no-input


# Запуск локальногоконтейнера Postgres
start-db:
docker-compose -f $(DEV_DOCK_FILE) up -d; \
if [ $$? -ne 0 ]; \
then \
docker compose -f $(DEV_DOCK_FILE) up -d; \
fi

# Остановка контейнера Postgres
stop-db:
docker-compose -f $(DEV_DOCK_FILE) down; \
if [ $$? -ne 0 ]; \
then \
docker compose -f $(DEV_DOCK_FILE) down; \
fi

# Очистка БД Postgres
clear-db:
docker-compose -f $(DEV_DOCK_FILE) down --volumes; \
if [ $$? -ne 0 ]; \
then \
docker compose -f $(DEV_DOCK_FILE) down --volumes; \
fi


# Локальный запуск сервера разработки.
run:
cd $(PROJECT_DIR) && $(DJANGO_RUN) runserver
Expand Down
10 changes: 6 additions & 4 deletions adaptive_hockey_federation/core/config/dev_settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

from .base_settings import *

ROOT_DIR = BASE_DIR.parent
Expand All @@ -15,8 +13,12 @@

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'ENGINE': env('DB_ENGINE', default='django.db.backends.postgresql'),
'NAME': env('POSTGRES_DB', default='postgres_db'),
'USER': env('POSTGRES_USER', default='postgres_user'),
'PASSWORD': env('POSTGRES_PASSWORD', default='postgres_password'),
'HOST': env('DB_HOST', default='localhost'),
'PORT': env('DB_PORT', default='5432')
}
}

Expand Down
8 changes: 8 additions & 0 deletions adaptive_hockey_federation/core/config/test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .base_settings import *

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
8 changes: 6 additions & 2 deletions infra/dev/docker-compose.dev.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#filename: docker-compose.dev.yaml
#full path: ./infra/dev/docker-compose.dev.yaml
#description: docker-compose file for development environment

version: '3.8'
name: ahf_dev

Expand All @@ -7,11 +11,11 @@ services:
image: postgres:13.0-alpine
restart: always
volumes:
- postgres_data:/var/lib/postgresql/data/
- postgres_db_data:/var/lib/postgresql/data/
env_file:
- ../../.env
ports:
- 5432:5432

volumes:
postgres_data:
postgres_db_data:
83 changes: 82 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ click = "^8.1.7"
wrapt = "^1.16.0"
django-phonenumber-field = {extras = ["phonenumbers"], version = "^7.2.0"}
pytest-django = "^4.7.0"
psycopg2-binary = "^2.9.9"
django-environ = "^0.11.2"

[tool.poetry.group.dev.dependencies]
Expand Down
1 change: 1 addition & 0 deletions requirements/develop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ phonenumbers==8.13.26 ; python_version >= "3.11" and python_version < "4.0"
platformdirs==4.1.0 ; python_version >= "3.11" and python_version < "4.0"
pluggy==1.3.0 ; python_version >= "3.11" and python_version < "4.0"
pre-commit==3.5.0 ; python_version >= "3.11" and python_version < "4.0"
psycopg2-binary==2.9.9 ; python_version >= "3.11" and python_version < "4.0"
pytest-django==4.7.0 ; python_version >= "3.11" and python_version < "4.0"
pytest==7.4.3 ; python_version >= "3.11" and python_version < "4.0"
pyyaml==6.0.1 ; python_version >= "3.11" and python_version < "4.0"
Expand Down
1 change: 1 addition & 0 deletions requirements/production.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ openpyxl==3.1.2 ; python_version >= "3.11" and python_version < "4.0"
packaging==23.2 ; python_version >= "3.11" and python_version < "4.0"
phonenumbers==8.13.26 ; python_version >= "3.11" and python_version < "4.0"
pluggy==1.3.0 ; python_version >= "3.11" and python_version < "4.0"
psycopg2-binary==2.9.9 ; python_version >= "3.11" and python_version < "4.0"
pytest-django==4.7.0 ; python_version >= "3.11" and python_version < "4.0"
pytest==7.4.3 ; python_version >= "3.11" and python_version < "4.0"
sqlparse==0.4.4 ; python_version >= "3.11" and python_version < "4.0"
Expand Down
Loading