forked from ddrilling/AsbCloudServer
551c60c4ff
Rename some fields in DB.permission.
66 lines
1.5 KiB
Markdown
66 lines
1.5 KiB
Markdown
# Миграции
|
|
## 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 remvoe <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_2021-11-26.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. Innit 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 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 'exit resore mode' psql:
|
|
```
|
|
SELECT timescaledb_post_restore();
|
|
``` |