DD.WellWorkover.Cloud/AsbCloudDb
2022-12-26 21:50:33 +05:00
..
Migrations edit column migration 2022-12-26 21:50:33 +05:00
Model edit column migration 2022-12-26 21:50:33 +05:00
UsefulQueries nit add useful sql script. 2022-12-16 16:09:11 +05:00
AsbCloudDb.csproj Update nuget packs 2022-09-09 15:29:46 +05:00
EFExtentionOrderBy.cs Recreate migration Add_mw_telemetry_datas_saub_stat. 2022-05-06 10:58:52 +05:00
EFExtentions.cs Fix WitsRecordRepository.SaveDataAsync(). Add some milliseconds to duplicated records. 2022-10-25 17:23:01 +05:00
install pg timescale.md BIG. Add timescaleDB into DB. 2021-11-13 18:47:11 +05:00
Readme.md #7912198 Tests ok 2022-11-25 09:34:20 +05:00

Миграции

EF tools

https://docs.microsoft.com/ru-ru/ef/core/cli/dotnet

Установка:

dotnet tool install --global dotnet-ef

Обновление:

dotnet tool update --global dotnet-ef

Создать миграцию

dotnet ef migrations add <MigrationName> --project AsbCloudDb

Откатить миграцию

dotnet ef migrations remove <MigrationName> --project AsbCloudDb

<MigrationName> - Name of migration class. После создания миграции обязательно прочитать генерированный код.

Применить миграции

При старте проекта применяются автоматически

 dotnet ef database update --project .\AsbCloudDb

Backup and restore

Backup

Terminal:

sudo -u postgres pg_dump -Fc -U postgres postgres -W > dump_2022-03-09.bak

Restore backup

Step 1. (Re)Create DB and schema IF needed.

psql:

--drop schema public cascade;
CREATE DATABASE postgres;
\c postgres
create schema public;

Step 2. Init timescaledb and prepare DB to restore

CREATE EXTENSION IF NOT EXISTS timescaledb;
SELECT timescaledb_pre_restore();

Step 3. Restore DB, then [Longest operation]

Terminal:

sudo -u postgres pg_restore -Fc -d postgres dump_2021-11-26.bak

OR psql:

\! pg_restore -Fc -d postgres dump_2021-11-26.bak

win: pg_restore -Fc -d postgres -U postgres -W dump_2022-01-11.bak Then 'exit restore mode' psql:

SELECT timescaledb_post_restore();