81 lines
2.0 KiB
Markdown
81 lines
2.0 KiB
Markdown
# Backend
|
|
|
|
Технологии:
|
|
|
|
* ASP.NET
|
|
* Aspire
|
|
* PostgreSQL
|
|
* Docker + Compose
|
|
* Nginx
|
|
* Github CI/CD
|
|
|
|
# ApiService
|
|
|
|
## Docker
|
|
|
|
```bash
|
|
docker run -d -p 8080:8080 \
|
|
--name Backend \
|
|
--restart=always \
|
|
-e DATABASE='Host=192.168.111.0;Port=5432;Database=prod;Username=prod;Password=' \
|
|
-e TZ=Europe/Moscow \
|
|
git.zetcraft.ru/hackathonpreparing/backend:main
|
|
```
|
|
|
|
## Docker compose
|
|
|
|
```yaml
|
|
version: '3.3'
|
|
services:
|
|
backend:
|
|
ports:
|
|
- 8080:8080
|
|
container_name: Backend
|
|
restart: always
|
|
environment:
|
|
- DATABASE=Host=192.168.111.0;Port=5432;Database=prod;Username=prod;Password=
|
|
- TZ=Europe/Moscow
|
|
image: git.zetcraft.ru/hackathonpreparing/backend:main
|
|
```
|
|
|
|
Строка подключения в appsettings.json:
|
|
username:postgres
|
|
password:postgres
|
|
host:localhost
|
|
port:5432
|
|
database:prod
|
|
|
|
|
|
|
|
Если нет миграций в проекте то в папке HackathonPreparing.ApiService нужно писать:
|
|
|
|
```sh
|
|
dotnet ef migrations add UserContextMigration --context UserContext
|
|
dotnet ef database update --context UserContext
|
|
|
|
dotnet ef migrations add WeatherForecastContextMigration --context WeatherForecastContext
|
|
dotnet ef database update --context WeatherForecastContext
|
|
```
|
|
|
|
```ps
|
|
dotnet-ef.exe migrations add UserContextMigration --context UserContext
|
|
dotnet-ef.exe database update --context UserContext
|
|
|
|
dotnet-ef.exe migrations add WeatherForecastContextMigration --context WeatherForecastContext
|
|
dotnet-ef.exe database update --context WeatherForecastContext
|
|
```
|
|
|
|
И так для каждого DbContext в проекте
|
|
|
|
Если в папке HackathonPreparing.ApiService есть папка Migrations и там есть миграции то можно просто сделать запрос post: /api/db/migrate.
|
|
Все запросы к маршрутам /api/db/... доступны только в dev моде
|
|
|
|
|
|
|
|
/api/swagger - путь к свагеру
|
|
|
|
из свагера в dev моде можно запустить миграции в /api/db/migrate
|
|
|
|
|
|
|