DD.WellWorkover.Cloud/AsbCloudDb/Readme.md

67 lines
1.4 KiB
Markdown
Raw Normal View History

# Миграции
## 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
```
2023-03-29 01:23:41 +05:00
## Откатить миграцию
```
2023-03-29 01:21:14 +05:00
dotnet ef migrations remove --project AsbCloudDb
```
2023-03-29 01:23:41 +05:00
Удаляется последняя созданная миграция.
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:
```
2022-03-10 17:18:30 +05:00
sudo -u postgres pg_dump -Fc -U postgres postgres -W > dump_2022-03-09.bak
2021-12-03 17:34:24 +05:00
```
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;
```
### Step 2. Init 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 pg_restore -Fc -d postgres dump_2021-11-26.bak
2021-12-03 17:34:24 +05:00
```
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:
2021-12-03 17:34:24 +05:00
```
SELECT timescaledb_post_restore();
```