diff --git a/AsbCloudDb/Readme.md b/AsbCloudDb/Readme.md index d3621a5a..1ec8eea1 100644 --- a/AsbCloudDb/Readme.md +++ b/AsbCloudDb/Readme.md @@ -1,28 +1,53 @@ -создать миграцию +# Миграции +## создать миграцию ``` dotnet ef migrations add --project AsbCloudDb ``` -создать миграцию +## откатить миграцию ``` dotnet ef migrations remvoe --project AsbCloudDb ``` + - Name of migration class После создания миграции обязательно прочитать сгенерированый код. -Применить миграции +## Применить миграции +При старте проекта применяются автоматически ``` dotnet ef database update --project .\AsbCloudDb - ``` +``` - #backup - ``` -sudo -u postgres pg_dump -Fc -U postgres postgres -W | gzip > 2021-09-27_dump.sql.gz -sudo -u postgres pg_dump -Fc -U postgres postgres -W > 2021-11-26_dump.sql - ``` +# Backup +Terminal: +``` +sudo -u postgres pg_dump -Fc -U postgres postgres -W > dump_2021-11-26.bak +``` - #restore - ``` - psql postgres < dump_file_name - ``` - -sudo -u postgres psql -p 5499 -U postgres postgres -W < 2021-11-16_dump.sql.gz \ No newline at end of file +# Restore backup +## Step 1. (Re)Create DB and schema IF needeed. +psql: +``` +--drop schema public cascade; +CREATE DATABASE postgres; +\c postgres +create schema public; +``` + +## Step 2. Innit timescaledb and prepare DB to restore +``` +CREATE EXTENSION IF NOT EXISTS timescaledb; +SELECT timescaledb_pre_restore(); +``` +## Step 3. Restore DB, then 'exit resore mode'. [Longest operation] +Terminal: +``` +sudo -u postgres psql -p 5499 -U postgres postgres -W < dump_2021-11-26.bak +``` +OR psql: +``` +\! pg_restore -Fc -d postgres dump_2021-11-26.bak +``` +Then psql: +``` +SELECT timescaledb_post_restore(); + ``` \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/TelemetryDataBaseService.cs b/AsbCloudInfrastructure/Services/TelemetryDataBaseService.cs index 42e86342..f7b11e3b 100644 --- a/AsbCloudInfrastructure/Services/TelemetryDataBaseService.cs +++ b/AsbCloudInfrastructure/Services/TelemetryDataBaseService.cs @@ -89,6 +89,7 @@ namespace AsbCloudInfrastructure.Services var idTelemetry = well?.IdTelemetry ?? default; + var filterByDateEnd = dateBegin != default; if (dateBegin == default) { dateBegin = telemetryService.GetLastTelemetryDate(idTelemetry); @@ -113,8 +114,10 @@ namespace AsbCloudInfrastructure.Services var query = dbSet .Where(d => d.IdTelemetry == idTelemetry - && d.Date >= dateBegin - && d.Date < dateEnd); + && d.Date >= dateBegin); + + if (filterByDateEnd) + query = query.Where(d => d.Date < dateEnd); var fullDataCount = await query.CountAsync(token) .ConfigureAwait(false); diff --git a/AsbCloudWebApi/Controllers/AdminUserRoleController.cs b/AsbCloudWebApi/Controllers/AdminUserRoleController.cs index 5876ece4..34bca745 100644 --- a/AsbCloudWebApi/Controllers/AdminUserRoleController.cs +++ b/AsbCloudWebApi/Controllers/AdminUserRoleController.cs @@ -8,7 +8,7 @@ namespace AsbCloudWebApi.Controllers [Route("api/admin/role")] [ApiController] [Authorize] - public class AdminUserRoleController : CrudController> + public class AdminUserRoleController : CrudController { public AdminUserRoleController(IUserRoleService service) :base(service)