DD.WellWorkover.Cloud/AsbCloudDb/Readme.md

66 lines
1.5 KiB
Markdown
Raw Normal View History

2021-12-03 17:34:24 +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
```
2021-12-07 11:34:06 +05:00
## Создать миграцию
```
dotnet ef migrations add <MigrationName> --project AsbCloudDb
```
2021-12-07 11:34:06 +05:00
## Откатить миграцию
```
dotnet ef migrations remvoe <MigrationName> --project AsbCloudDb
```
2021-12-07 11:34:06 +05:00
\<MigrationName> - Name of migration class.
После создания миграции обязательно прочитать сгенерированый код.
2021-12-03 17:34:24 +05:00
## Применить миграции
При старте проекта применяются автоматически
2021-09-10 11:28:57 +05:00
```
dotnet ef database update --project .\AsbCloudDb
2021-12-03 17:34:24 +05:00
```
2021-09-29 10:09:40 +05:00
2021-12-07 11:34:06 +05:00
# Backup and restore
## Backup
2021-12-03 17:34:24 +05:00
Terminal:
```
sudo -u postgres pg_dump -Fc -U postgres postgres -W > dump_2021-11-26.bak
```
2021-11-17 13:06:48 +05:00
2021-12-07 11:34:06 +05:00
## Restore backup
### Step 1. (Re)Create DB and schema IF needed.
2021-12-03 17:34:24 +05:00
psql:
```
--drop schema public cascade;
CREATE DATABASE postgres;
\c postgres
create schema public;
```
2021-12-07 11:34:06 +05:00
### Step 2. Innit timescaledb and prepare DB to restore
2021-12-03 17:34:24 +05:00
```
CREATE EXTENSION IF NOT EXISTS timescaledb;
SELECT timescaledb_pre_restore();
```
2021-12-07 11:34:06 +05:00
### Step 3. Restore DB, then [Longest operation]
2021-12-03 17:34:24 +05:00
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
```
2021-12-07 11:34:06 +05:00
Then 'exit resore mode' psql:
2021-12-03 17:34:24 +05:00
```
SELECT timescaledb_post_restore();
```